Sunday, September 13, 2009

Some realtime issues ...

I need some speed.
Below is the code needed to calulate any equity index in realtime. The only pre-requisite is to have a curve defined with the constituents and a vector of shares in the index as well. (And also the divisor of course).

out number calc_index(curve_name cn, date d, string num_share_tag, quote_side q){

curve idx_c = curve(cn, d, q);
number index_divisor = get_tag_num('index_divisor', cn, d);
vector(string) i = idx_c.instruments().name();
vector(number) w = get_tag_num(num_share_tag, i, d);

return w*instrument(i,d,q).quote()/index_divisor;
}

Any time a new price quote comes in the code will excecute and calculate the index value again. The code can still be optimized further though. I will do that later.

No comments:

Post a Comment