Serving the Quantitative Finance Community

 
User avatar
CanDo
Topic Author
Posts: 0
Joined: June 20th, 2013, 5:27 pm

How to implement arithmetic of 'returns'

July 19th, 2013, 7:00 am

Hello expert programmers,I am trying my hand at writing a code to implement a trading formula. But I am not sure about how the returns and their arithmetic is implemented. The formula I am trying to implement is something like Z = Return (stock) - beta1*Return (market) - beta2 * Return (sector). Assuming stock is APPL, market is SPY and sector is IYT and beta values are known constants, if I need to calculate the value of Z intraday based on the close price on T-1, can you please suggest me how to go about the calculations.Would it be simply: Z (at any given instant) = log( real time price of AAPL at that time/ Prev. close price of AAPL) - beta1 * log(real time price of SPY/Prev close price of SPY) - beta2*(real time price of IYT/ prev close price of IYT)I doubt that this is the way it is implemented by professional quant. programmers, but if it is right it will be very noisy and a resource hog, given how this calc will change with every tick and how active these (AAPL, SPY, IYT) equities are. I woutd appreciate any suggestions on implementing it in the right way and to get a stable and meaningful signal (Z).THANK YOU.
 
User avatar
Samsaveel
Posts: 34
Joined: April 20th, 2008, 5:47 am

How to implement arithmetic of 'returns'

July 22nd, 2013, 5:48 am

are you doing this in Assembly ??
 
User avatar
lexington
Posts: 0
Joined: November 16th, 2008, 5:04 am

How to implement arithmetic of 'returns'

July 24th, 2013, 5:05 am

which language you are using? How do you know it is a resource hog?you can also check this book.
 
User avatar
tags
Posts: 3625
Joined: February 21st, 2010, 12:58 pm

How to implement arithmetic of 'returns'

July 24th, 2013, 6:35 pm

I must be dumb, I don't get well what CanDo is asking.
Last edited by tags on July 23rd, 2013, 10:00 pm, edited 1 time in total.
 
User avatar
Jim
Posts: 1
Joined: February 1st, 2002, 5:20 pm

How to implement arithmetic of 'returns'

July 25th, 2013, 12:45 pm

You are correct that your signal will be noisy. But that is due to the model you have chosen.Here are two things you can do to speed calculations:1) Use a Taylor expansion of ln(1+x)=x - x^2/2 + x^3/3 - x^4/4 +.... and truncate after a few terms. Use Horner's method to avoid exponentiation.2) Cache the contributions of the three components and only update that component and the total, Z, when there is a new price to one or more of the underlying stock/index.
 
User avatar
lexington
Posts: 0
Joined: November 16th, 2008, 5:04 am

How to implement arithmetic of 'returns'

July 25th, 2013, 12:57 pm

QuoteOriginally posted by: Jim 2) Cache the contributions of the three components and only update that component and the total, Z, when there is a new price to one or more of the underlying stock/index.for stocks like AAPL which he mentioned, there is a new price every millisecond
 
User avatar
Jim
Posts: 1
Joined: February 1st, 2002, 5:20 pm

How to implement arithmetic of 'returns'

July 25th, 2013, 1:13 pm

> for stocks like AAPL which he mentioned, there is a new price every millisecondYes, I know. My point was he wouldn't necessarily need to do the log calculation on the other two components each time AAPL changes.He always had the choice to throttle his updates to limit how often his signal value would change. I proposed ways to make the calculation more computational efficient.
 
User avatar
lexington
Posts: 0
Joined: November 16th, 2008, 5:04 am

How to implement arithmetic of 'returns'

July 25th, 2013, 1:52 pm

QuoteOriginally posted by: Jim> for stocks like AAPL which he mentioned, there is a new price every millisecondYes, I know. My point was he wouldn't necessarily need to do the log calculation on the other two components each time AAPL changes.other two components change each time AAPL changes
 
User avatar
Jim
Posts: 1
Joined: February 1st, 2002, 5:20 pm

How to implement arithmetic of 'returns'

July 25th, 2013, 5:33 pm

> other two components change each time AAPL changesTheoretically, yes. Practically, no. SPY and IYT are separately traded ETFs with their own bid/ask and own last trade prints.
 
User avatar
CanDo
Topic Author
Posts: 0
Joined: June 20th, 2013, 5:27 pm

How to implement arithmetic of 'returns'

July 30th, 2013, 7:56 am

Thanks, Jim. I think a combination of caching the values and using some sort of throttling (updating threshold) will probably do the trick. I am new to trading and have a limited exposure to programming and wanted to confirm if there was a more elegant and/or obscure way the pros. would do it.
Last edited by CanDo on July 29th, 2013, 10:00 pm, edited 1 time in total.