Sammit, Yes I have, but it would be quicker to do it again than to find the old code.
There is function in qmao called makeTestData that splits the data for you. zoo:::rollapplyr or quantmod:::period.apply are beneficial for this type of analyis as well. On Tue, Nov 29, 2011 at 1:42 PM, Samit Jain <[email protected]> wrote: > Sorry I meant to address the email to Garrett :) > > > On Tue, Nov 29, 2011 at 2:41 PM, Samit Jain <[email protected]>wrote: > >> Hi Paul, >> Interesting findings. I was wondering if you tested the different ratios >> (OLS, btcdHedge and TLS) on a new data set to see which performs better? >> Something we could do is split the data since 2011-01-01 in two, train the >> parameters using the three approaches on the first, and test them for daily >> returns on second set. We could then look at average returns and variance. >> >> cheers, >> Samit >> >> >> On Tue, Nov 29, 2011 at 2:20 PM, G See <[email protected]> wrote: >> >>> Paul, >>> >>> Thank you very much for sending this; I've seen the lightning talk >>> slides, and spent some time playing with it. I do have a couple >>> observations. >>> >>> First, often it seems like if I use the inverse of your code I get >>> better results. >>> >>> i.e. I find that r$loadings[1,1] / r$loadings[2,1] is closer to what I >>> get using other hedge ratio calculation methods. >>> >>> I attached a hedge ratio calculating function called "btcdHedge" to use >>> as a comparison. I took the code for this function from >>> http://quantivity.wordpress.com/2011/10/02/proxy-cross-hedging/ >>> >>> If I use btcdHedge to calculate the ratio between SPY and DIA since >>> 2011-01-01, it tells me to sell 1.070554 DIA for each share of SPY that I >>> am long. >>> >>> That is very close to the 1.070894 I would get if I used OLS with a >>> zero intercept >>> >>> If I use OLS with a floating intercept, I get 1.206745. >>> >>> If I use your TLS code, I get 0.777546 >>> >>> So, your TLS code is the only one that gives a ratio of less than 1. >>> >>> However, if I use the inverse of your code I get something close to OLS >>> with floating intercept >>> r$loadings[1,1] / r$loadings[2,1] >>> [1] 1.286098 >>> >>> >>> Second, >>> You say >>> "Forcing a zero intercept requires an additional step: recentering the >>> data around >>> their means prior to the PCA." >>> >>> However, I get the same values regardless of whether I center around the >>> means. >>> >>> Thanks, >>> Garrett >>> >>> On Tue, Nov 29, 2011 at 12:08 PM, Paul Teetor <[email protected]>wrote: >>> >>>> R-SIG-Finance community: >>>> >>>> I recently posted a short paper entitled Better Hedge Ratios for Spread >>>> Trading: >>>> >>>> http://www.quanttrader.info/public/betterHedgeRatios.pdf >>>> >>>> The topic is pretty arcane but important to spread traders. A surprizing >>>> number of textbooks and practitioners simply use ordinary least squares >>>> (OLS) to calculate their hedge ratios, but OLS can give misleading >>>> results. >>>> The paper shows how to use total least squares (TLS) to obtain a better >>>> balanced spread. The needed R code is simple and included in the paper. >>>> >>>> The paper is based on a lightning talk I gave at the R/Finance >>>> Conference >>>> back in April. >>>> >>>> I welcome all comments. I can't guarantee I will quickly incorporate >>>> your >>>> feedback into the paper, unfortunately. Heck, it took me seven months >>>> just >>>> to get out this first version. >>>> >>>> Paul Teetor >>>> Elgin, IL USA >>>> http://www.linkedin.com/in/paulteetor >>>> >>>> "For quant traders, there are no bad days in the market. It's just more >>>> data." >>>> >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> _______________________________________________ >>>> [email protected] mailing list >>>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance >>>> -- Subscriber-posting only. If you want to post, subscribe first. >>>> -- Also note that this is not the r-help list where general R questions >>>> should go. >>>> >>> >>> >>> _______________________________________________ >>> [email protected] mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance >>> -- Subscriber-posting only. If you want to post, subscribe first. >>> -- Also note that this is not the r-help list where general R questions >>> should go. >>> >> >> > [[alternative HTML version deleted]] _______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
