Matlab | extracting string from in a cell array

A(1,1) is still a cell array — 1×1. It's not a string and many functions won't accept it.

myStr = sprintf('%s',A(1,1));

Advertisements

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).

non-intrusive test – if current process has admin privilege

Just run qq(openfiles) command.

See https://groups.google.com/forum/#!topic/alt.msdos.batch.nt/1dnlamNqZ7U

==============================

Information in this message is confidential. It is intended solely for the person or the entity to whom it is addressed. If you are not the intended recipient, you are not to disseminate, distribute or copy this communication. Please notify the sender and delete the message and any other record of it from your system immediately.

==============================

c++ bad_alloc handling — briefly

Q: What can you do when you get an std::bad_alloc exception?
A: Scott Meyers suggested overloading operator new and new-handler. I guess in financial apps it’s rarely needed. But we should really read the [[safe c++]] book written by a hedge fund coder.

A: I used to keep 60MB files in my C: drive, to be deleted when I run out of disk — same idea expressed in Item 7 in [[effC++]]

A: if it’s stack, it’s often due to deep recursion. You can set stack size —

gcc -Wl,–stack=xxxxx -Wl,–heap=yyyyy …

Fwd: negative skew intuitively #mean < median

Update: now I know the lognormal squashed bell curve has Positive

skew. This post is about Neg skew. Better remember a clear picture of

the Neg skew distribution.

Neg skew is commonly observed on daily returns — lots of large neg

returns than large positive returns. Level return or log return

doesn't matter.



I knew the definition of median and the interpretation of the median on the

histogram/pdf curve. But The mean is harder to visualize. The way I

see it, the x-axis is a flat plank. The histogram depicts chunks of

“probability mass” to be balanced on the plank. The exact pivot point

(on the x-axis) to balance the plank is the mean value.

In our case of negative skew, the prob mass left to the mean value

(pivot point) is… say 40.6%. This small mass could hold the other

59.4% prob mass in balance. Why? Because part of the 40.6% prob mass

is far out to the left.

Therefore, as we both mentioned earlier, the neg skew seems to reflect

(or relate to) the occurrence of large negative returns.

—- Mark earlier wrote —

Negative skewness means that the mean is to the left of the median.

(Recall that the median is the point at which half the mass is to the

left and half is to the right.) Thus, negative skewness implies a bit

of the probability mass hangs out to the left. In finance, this means

that there are more “very large” negative returns than “very large”

positive returns.

MSExcel | special LEDs

These special LEDs “radiate” useful information, but many users don’t recognize them.
–Formula ribbon -> showFormulas
Affects entire workSheet, but not entire workBook
–status bar quick stats, showing sum, average by default. customizable by right-click
–in function wizard, bold args are mandatory
— single $ vs 2 separate $s in a formula
$K33 means FIX column K when we copy the formula;
K$33 means FIX row 33

[[all about HFT]]

Author is an option specialists (currently teaching derivatives at a university). Many mentions of HFT on options.
 
chapters (80p) on technology. Author believes the 3 legs are {strategy, math, tech}
chapter (50p) on strategy
**first part seems to be uninteresting, math-light but might be important in practice
**chapter (12p) on arbitrage strategies
1 page on native API vs FIX.
a few pages on cpu offloading, including running Monte Carlo on GPGPU
compares c++ vs c#java in a HFT context
compares buy vs build in a HFT context

MSExcel | time-savers

–select a row of cell populated with formulas -> double click on the right-bottom handle ==> will auto drag downward

 

–rename a tab, quickly — double click the tab

–to see (long) list of sheets Vertically, right click on the tab-navigator buttons

–to clear format on a cell — Home ribbon -> clear button

— sort quickly — click any cell in the key column -> Data ribbon -> ascendingSort button ==> will sort the entire “natural table”

–VIEW ribbon -> arrangeAll -> TILE ==> 2 workbooks side by side …. easiest way to move tabs between workbooks

–to copy formatting from source cell to target cell

click source cell -> home ribbon -> formatPainter -> click target cell

 

 

window procedure in microsoft windows app, briefly

http://msdn.microsoft.com/en-us/library/ms644927(v=vs.85).aspx explains that Every (visual) window is an instance of a window class. “Every window class has a window procedure, and every {{visual}} window created with that class uses that same window procedure to respond to messages.”

Therefore every visual window has a window procedure – a function that processes all messages sent or posted to All window instances of the class. The window procedure (i.e. callback) has the business logic.

N(d2), GBM, binary call valuation – intuitive

It’s possible to get an intuitive feel for the binary call valuation formula.
For a vanilla European call, C = … – K exp(-Rdisc T)*N(d2)
N(d2) = Risk-Neutral Pr(S_T > K). Therefore,
N(d2) = RN-expected payoff of a binary call
N(d2) exp(-Rdisc T) — If we discount that RN-expected payoff to Present Value, we get the current price of the binary call. Note all prices are measure-independent.
Based on GBM assumption, we can *easily* prove Pr(S_T > K) = N(d2) .
First, notice Pr(S_T > K) = Pr (log S_T > log K).
Now, given S_T is GBM, the random variable (N@T) 
   log S_T ~ N ( mean = log S + T(Rgrow – σ^2)  ,   std = T σ^2 ). 
Let’s standardize it to get
   Z := (log S_T  – mean)/std    ~  N(0,1)
Pr = Pr (Z > (log K  – mean)/std ) = Pr (Z < (mean – log k)/std) = N( (mean – log k)/std)  = N(d2)

MSExcel | cursor-jump by ctrl-arrow

Very useful when we have large blocks of data.
 –ctrl-anyArrow ==> jump to boundary… always lands on {next populated cell or the physical limit of the “universe”}
This is the basic technique.
–ctrl-shift-anyArrow ==> range-select
–to select current “block”
click on the top left “starting point” -> ctrl-shift-right -> ctrl-shift-down
Alternatively, click anywhere in a block -> ctrl-*
–Range.End() pitfalls

Rule – End(xxx) under VBA automation == Ctrl+Arrow
Rule – it always transports you i.e. jumps to a populated cell, never an unpopulated cell.

Jargon – An “Edge” cell is a populated cell with at least one unpopulated neighbour.

Happy path – If you are in the middle not edge of a populated region, then End() would jump to the Edge

If you are on an unpopulated cell, then you jump to the next edge cell.

If you are already on the right-edge, end(right) would first (implicitly) jump to the RHS neighbour (unpopulated), then do the actual jump.

MSExcel | find/replace

–can change all red cells to blue background
–can limit the replacement to within a (disjoint) selection
–look-In “values”
needed if the search “needle” appears in a formula’s evaluated output but not in the formula’s “source code”

PCP with dividend – intuitively

See also posts on PCP.
See also post on replicating fwd contract.

I feel PCP is the most intuitive, fundamental and useful “rule of thumb” in option pricing. Dividend makes things a tiny bit less straightforward.

C, P := call and put prices today
F := forward contract price today, on the same strike. Note this is NOT the fwd price of the stock.

We assume bid/ask spread is 0.

    C = P + F

The above formula isn’t affected by dividend — see the very first question of our final exam. It depends only on replication and arbitrage. Replication is based on portfolio of traded securities. (Temperature – non-tradable.) But a dividend-paying stock is technically non-tradable!

* One strategy – replicate with European call, European put and fwd contract. All tradable.

* One strategy – replicate with European call, European put, bond and dividend-paying stock, but no fwd contract. Using reinvestment and adjusting the initial number of shares, replication can still work. No need to worry about the notion that the stock is “non-tradable”.

Hockey stick, i.e. range-of-possibility graphs of expiration scenarios? Not very simple.

What if I must express F in terms of S and K*exp(-rT)? (where S := stock price any time before maturity.)

  F = S – D – K*exp(-rT) … where D := present value of the dividend stream.