Friday, December 11, 2009

Beta

corr(A, B) = Cov(A,B)/Vol(A)Vol(B)
var(A) = Vol(A) sqrt
Beta(A,B) = Cov(A,B)/var(B)

Monday, December 7, 2009

sed in Linux

1- say for example, in Shell programming, you want to append some variable at the string end, this wont work - sed 's/$/$temp/'

what we can do is use two sed's - sed -e 's/$/dummy/' | sed "/dummy/$temp/".

Friday, December 4, 2009

Revolutionary Road

A sad story...

Kate and Leo are just the best pair! They made it so much more perfect!

Everyone wants out.
Everyone wants in.
Everyone wants to want.

To want nothing is to have everything!

This movie made my honey and me cry, especially we watched it together when we're suffering bad things! There's a moment in the life of any human be that we stop and ask ourself if we're in the right road, with right person. Insatisfaction???!!! We got it from this one - Revolutionary Road.

Thursday, December 3, 2009

FIX Learning Notes (3)

1. interesting to know that we don't support msg with OrdStatus = New (we only care about executions, not orders)... Apparently this only applies to us, not part of FIX protocol.

2. OrdStatus, ExecType, ExecTransType

Perl Points

1- single quotes & double quotes:
single quotation doesn't interpret, while double quotation does.

Friday, November 27, 2009

一些宏观层面上的经济学原理

1、各大中央银行已经说得清清楚楚:他们就是要尽可能增加货币供应,促成纸币贬值,帮助负债者。
-- for this point, there's no need to talk about China (we have plenty of Chinese newspapers on it). Just look at today's Bloomberg post on Japan - BOJ to Provide 10 Trillion Yen in Emergency Credit. The Bank of Japan said it’s ready to pump more money into the financial system after unveiling a 10 trillion yen ($115 billion) program to help an economy battered by falling prices and the yen’s surge to a 14-year high. Yen is gaining against USD in the past six months, once peaked at almost 84...

Thursday, November 26, 2009

FIX Learning Notes (2)

1. Symbol - Tag 55
ticker symbol

2. SecurityType - Tag 167
sample values: CS, FUT, OPT, WAR etc

3. IDSource - Tag 22 (symbol type)
sample values: 1-cusip, 2-sedol, 3-quik, 4-isin, 5-RIC, 8-exchange symbol etc

4. some other config's

Wednesday, November 25, 2009

RIC Futures & Options Name Convention

1. Reuters monthly codes for futures

my %futureCode = (
"01" => "F",
"02" => "G",
"03" => "H",
"04" => "J",
"05" => "K",
"06" => "M",
"07" => "N",
"08" => "Q",
"09" => "U",
"10" => "V",
"11" => "X",
"12" => "Z",
);

2. Reuters monthly codes for options

my %optionCode = (
P => { # codes for put option
"01" => "M",
"02" => "N",
"03" => "O",
"04" => "P",
"05" => "Q",
"06" => "R",
"07" => "S",
"08" => "T",
"09" => "U",
"10" => "V",
"11" => "W",
"12" => "X",
},
C => { # call option
"01" => "A",
"02" => "B",
"03" => "C",
"04" => "D",
"05" => "E",
"06" => "F",
"07" => "G",
"08" => "H",
"09" => "I",
"10" => "J",
"11" => "K",
"12" => "L",
},
);

3. for Options -- market symbol = security root + strike + option code shown above + expiry year (only one digit)

4. for futures -- market symbol = security root + future code shown above + expiry year (only one digit)

5. examples,

RIO2300X9.L - RIO.L O 20091218 2300.00 AP (RIO.L 2300 Put 20091218)
CBRY800L9.L - CBRY.L O 20091218 800.00 AC

Thursday, November 19, 2009

awk & nawk

1. nawk -F'\t' '$4==1 {print $5"\t"$1"\t"$2"\t"$3"\tYes"}; $4==0 {print $5"\t"$1"\t"$2"\t"$3"\tNO"}' xxxxx

2. grep xxxx XXXX | awk '$2 == 1 { ++total }; END {print "total = ", total} '

Wednesday, November 18, 2009

Trouble shooting commands

1. sp__who & sp_who

2. sp_lock

3. sp__whodo

4. uptime; who -b

Working on a FX trades upload project

1.

Monday, November 16, 2009

Concepts in FIX practice

1. the most important concept here is, FIX talks to IMR, and IMR talks to DBL. There're mappings between each layer.
(a) from FIX to IMR, we're basically talking about Group/Customer/Trader/Account/Broker etc

2. the FIX connectivity issues - see my other posts related to FIX

3. security search -> dup trades detection -> trades filter (trader/customer/broker/group/account mapping) -> price convert -> add trades -> calc charge based on broker -> ensureNotify_sp(?) -> update last processed trade ID

4. security search - based on what rules?
(a) securityType - tag 167

5. dup trades detection - we first check if there's an orderID (broker assigned one, unique for a single trading session) in the database already; if yes, we then go ahead, and check if there's an execID there in the database. If yes, that's great - we caught a dup trade!

6. cancel order?

7. name service - mapping name to IOR?

8. what's IOS?

Sunday, November 15, 2009

少室山之战

金庸笔下的少室山之战,无与伦比!
金庸笔下的萧峰,豪气干云!

有机会,一定去少室山看一看!

Thursday, November 12, 2009

Commands by Example in Perl

1. perl -c xxx.pl

Tuesday, November 10, 2009

Commands by Example in T-SQL

1. T-SQL - declare/select/if...else/exec

declare @user varchar(32)
select @user = '${userLogin}'

declare @groupName varchar(32)
select @groupName = 'xxx'

declare @fullName varchar(64)
select @fullName = xxx from xxx

declare @found int
select @found = 0
select @found = 1 from xxx

if(@found=0)
begin
print "--adding user %1! = %2! --", @user, @fullName
declare @id xxx
exec xxx @table_name='xxx', @nr=1, @next_id=@id output
insert xxx values (@id, @fullName, @groupName)
end

2. while/if/else etc
declare @hldQuantity int
select @hldQuantity = 0
declare @buysell int
declare @execQuantity int
declare @execId int
declare @nextId int
select @nextId = min(exec_id) from exec,order,port where order_id = id and hold_id = id and hold_id = 00001
while ( @nextId is not NULL)
begin
print '---working on %1!', @nextId
select @execQuantity = quantity, @buysell = buysell from exec,order where id = @nextId and id = order_id
if (@buysell = 0)
begin
print '---its a buy---'
select @hldQuantity = @hldQuantity + @execQuantity
end
else
if (@buysell = 2)
begin
print '---its a sell---'
select @hldQuantity = @hldQuantity - @execQuantity
end
select @execId = @nextId
select @nextId = min(id) from exec,order,holding where id = order_id and _id = holding_id and port_id= 00001 and exec_id > @execId
end
print "--the hold quantity %1! --", @hldQuantity

Monday, November 9, 2009

近期总结

1、学而不思则罔,思而不学则殆

比较喜欢目前工作的一个重要原因就是每天都能遇到新的挑战,而不是机械的重复同样的事情;每天都能接触到新的知识。但是,也有一个令人沮丧的地方,就是每天都疲于理解和实践新的东西,而没有时间和精力去好好弄懂并记住这些新的东西。随着时间的流逝,很多工作中接触的东西慢慢会忘掉。

现在重温孔子的这句话,真的获益匪浅。今后,尽量每天都抽出一点时间来温习和巩固工作中遇到和学到的知识!

2、拿得起放得下

我很讨厌自己性格的一个方面,就是做不到拿得起放得下。每次遇到一些事情和人,当触到自己心灵的时候,往往变得非常敏感和冲动,有时候甚至不能控制自己的情绪和感情。说得难听一点就是非常幼稚。真希望自己能够坚强一点,成熟一点。

3、Public Enemies

这是我近期看得一部电影。John Dillinger,一个传奇人物。Byebye Blackbird,最后听到这句话的时候,我眼眶湿润了。

some reading notes - Essential C++

1. this is doable - overload based on the constness

class T
{
public:
const tClass& val() const { return _val; }
tClass & val() const { return _val; }
}

2. a good practice - make sure two class objects are not the same when copying

T& T::copy(const T& rhs)
{
if (this != &rhs)
{
_var1 = rhs._var1;
_var2 = rhs._var2;
}
return *this;
}

3. static class members - the single, shared instance that is accessible to all the objects of that class (static members); don't access any non-static class members (static member functions)

---T.h
class T
{
public:
static bool is_elem(int);
private:
static vector _elements; // we need to put its explicit definition within a .cpp file
static const int _var1 = 1024; // no need to do that
}

---T.cpp
vector T::_elements;
bool T::is_elem(int val) { ... _elements ...} // only access static members

---Main.cpp
if (T::is_elem()) {}

4. constructor, copy constructor, copy assignment operator ...

copy assignment -

M& M::operator= (const M& rhs)
{
if (this != &rhs)
{
delete [] _elem;
_elem = new double [cnt];
for(int ix=0;ix != cnt; ++ix)
_elem[ix] = rhs._elem[ix];
}
return *this;
}

5. function object - an object of a class that has an instance of the function call operator

class LessThan
{
public:
LessThan(int val):_val(val) {}
int comp_val() const {return _val;}
void comp_val(int nval) {_val = nva;}
bool operator() (int value) const;
private:
int _val;
}

inline bool LessThan::operator() (int value) const
{ return value "<" _val; }

int count_less_than(const vector& vec, int comp)
{
LessThan lt(comp);
int count = 0;
for (int ix=0;ix!=vec.size();++ix)
{
if(lt(vec[ix])) ++count;
}
return count;
}

Pieces of knowledge in ITS

1. light crude oil - CLc1, gold - GCc1, USD Index - .DXY

Concepts in ITS

For holding level,

1. Delta



For security level,

1. option volatility - strick, expiry, style (A, E), put/call

Sunday, November 8, 2009

Commands by Example in Sybase

1. drop procedure XXX; grant execute on XXX to public

2. exec disableTriggers_sp & exec enableTriggers_sp

3. bcp xxx..xxx in symbs.e98 -U xxx -P ${xxx} -S xxx -c -e bcp.err

4. bcp xxx..xxx out xxx -S xxx -U xxx -P xxx -c

5. set rowcount 10

Saturday, November 7, 2009

Commands by Example in Unix

1. split -l 5000 -a 3 (-d) theFile newFile

2. egrep -v -f subFile orgFile

3. echo xxx | tee -a /home/test.log

4. Shell example - it works with bourne shell (ie, sh), but not tcsh

PHILLY$for s in `ls -1 /home/hosts/`; do
> echo $s
> ssh $s "ls /opt/lib/defaults/license.6.0"
> done

5. grep xxx XXX | awk '$2 == 1 { ++total }; END {print "total = ", total} '

6. setenv LOG_FILE /bbb/ccc

Monday, November 2, 2009

FIX Learning Notes (1)

1. unique identifiers for executions

(a) Tag - 17; Name - ExecID
assigned by broker; it's unique within a single trading day or the life of a multi-day order (we can embed a date there).

2. unique identifiers for orders, not for executions

(a) Tag - 37; Name - OrderID

3. some other fields

(a) Tag - 60; Name - TransactTime
the time of order/execution creation, expressed in UTC (aka GMT); it's UTCTimestamp, YYYYMMDD-HH:MM:SS or YYYYMMDD-HH:MM:SS.sss

(b) Tag - 32; Name - LastShares
the qty of this fill; we only process trades with LastShares not equal to zero

(c) Tag - 6; Name - AvgPx
(d) Tag - 44; Name - Price
(e) Tag - 31; Name - LastPx

Thursday, October 29, 2009

some quotes from "The Godfather I&II"

The greatest movie I ever watched. My most favorite one, very touching.

1. A man who doesn't spend time with his family can never be a real man.
2. Women and children can afford to be careless, but not men.
3. It's not personal. It's strictly business.
4. Because it insults my intelligence. It makes me very angry.
5. Get out of my sight.
6. I'll handle it. I told you I'll handle it, I'll handle it.

Wednesday, October 28, 2009

All Of A Sudden

All of a sudden, I'm totally lost, again :(

This is not what I wanted. You should remember all those bad things you have gone through. Learn your lessons, man.

Come on. It's a nice day anyway.

Wednesday, October 21, 2009

The Present - Author Unkown

Imagine there is a bank that credits your account each morning with $86,400.
It carries over no balance from day to day.
Every evening it deletes whatever part of the balance you failed to use during the day.
What would you do?
Draw out every cent, of course!
Each of us has such a bank.
Its name is TIME.

Every morning, it credits you with 86,400 seconds.
Every night it writes off, as loss whatever of this you have failed to invest to good purpose.
It carries over no balance.
It allows no overdraft.
Each day it opens a new account for you.
Each night it burns the day's deposits; the loss is yours.

There is no going back.
There is no drawing against the "tomorrow."
You must live in the present on today's deposits.
Invest it so as to get from it the utmost in health, happiness, and success!
The clock is running.
Make the most of today.

To realize the value of ONE YEAR, ask a student who failed a grade.
To realize the value of ONE MONTH, ask a mother who gave birth to a pre-mature baby.
To realize the value of ONE WEEK, ask the editor of a weekly newspaper.
To realize the the value of ONE DAY, ask a daily wage laborer with kids to feed.
To realize the value of ONE HOUR, ask the lovers who are waiting to meet.
To realize the value of ONE MINUTE, ask the man who missed his train.
To realize the value of ONE SECOND, ask the person who just avoid an accident.
To realize the value of ONE MILLISECOND, ask the person who won a silver medal in the Olympics.

Treasure every moment that you have!
And treasure it more because you've shared it with someone special---special enough to share your time.
And remember that time waits for no one.

Yesterday is history.
Tomorrow is a mystery.
Today is a gift.
That's why it's called, "the present."

Friday, October 16, 2009

how to remove ^M from a Unix file

^M is DOS line break charater which shows up in unix files when uploaded from a windows file system in ascii format.

Under vi, and enter :s/(ctrl-v)(ctrl-m)//g

Note, we need to press (Ctrl+v) and (Ctrl+m) to get ^M, instead of directly input these two characters. Seems we can also try dos2unix command.