range-check in c++ vector^raw array

[[safe c++]] points out that static array or dynamic array are both (unfortunately) silent about access beyond their limits. Vector has operator[] and at() —

[[]] says c++ new array type supports .size()…


#include <iostream>
#include <vector>
using namespace std;

int main(){
    vector<int> v;
    v.push_back(15);
    size_t sz = v.size();
    try{
        cout<<v[0]<<" "<<v[sz]<<" <- operator[]: out-of-range treated as non-error!"<<endl;
        cout<<v.at(sz)<<" <- at(): throws:)"<<endl;
    }catch(exception & ex){
        cerr<<"Must catch by ref (what() virtual) " << ex.what()<<endl;
    }
}

matlab [] vs ()

paren and brackets are by far the most versatile constructs in matlab. Each has rich contextual meanings. Here is an incomplete sketch.

–Matlab doc on “special characters” —

Brackets are used to form vectors and matrices.

Parentheses are used to enclose subscripts of vectors

http://stackoverflow.com/questions/5966817/difference-between-square-brackets-and-curly-brackets-in-matlab

A right angle (square) bracket creates a vector or matrix, whereas curly brackets creates a cell array.

When working with numbers, I'd say that 99% of the time, you will use square brackets. Cell arrays allow you to store different types of data at each location, e.g. a 10×5 matrix at (1,1), a string array at (1,2).

selling an existing IR swap@@

I guess technically we can’t sell an IRS as it’s not a product like an orange (or a house, or an option) with an owner. A IRS is a long-term bilateral agreement. Analog? I can’t “sell” my insurance policy to someone else.

A liquid swap market lets us offset our Libor exposure —

Suppose I’m a Payer in Deal 1 with Citi, to receive Libor and pay fixed 4.5%. Five hours (or 5 days or 5 months) later, I could become a Receiver in a JPM deal (Deal 2) to pay Libor and receive fixed 4.6%. Therefore I get rid of my Libor exposure, as long as the reset dates are identical between Deal 1 and Deal 2. But strictly speaking I haven’t Sold an existing swap. Both are long-term commitments that could in theory be unwound (painful) but never “sold” IMO.

By market convention, the counterparty paying the fixed rate is called the “payer” (while receiving the floating rate), and the counterparty receiving the fixed rate is called the “receiver” (while paying the floating rate).