tag:blogger.com,1999:blog-1346045313195961352.post3118462346302662355..comments2023-03-13T07:47:46.102-07:00Comments on MatlabTrading: Pca - how it really worksIgorhttp://www.blogger.com/profile/10662229147968940872noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-1346045313195961352.post-19483374053673941002013-01-29T01:26:47.416-08:002013-01-29T01:26:47.416-08:00What 2 number sets you are talking about? The resu...What 2 number sets you are talking about? The result has to be different if you transform the data one way or another. Any formula you can point to?SLnoreply@blogger.comtag:blogger.com,1999:blog-1346045313195961352.post-11815785628557325512013-01-08T01:37:15.231-08:002013-01-08T01:37:15.231-08:00Thanks. That indeed produces the same result as yo...Thanks. That indeed produces the same result as yours, however is it correct? PCA finds the core orthogonal components of a signal. When I fed it with the IWM and SPY prices - these prices are the signal, not the price changes.<br /><br />And if you run IWM and SPY via the two number sets - the one that you get from calculating on daily changes like you did, and the one you get from calculating for the actual price signal, the later seems to produce a much smoother output that is more "market neutral", IMHO.<br /><br />I tested for 2012 (signal from 1/3/2012 to 12/31/2012). With PCA factors of (-0.78, 0.62) you get a signal that deviates from the zero for months, and does the year with stdev of 1.43%. With factors of (-0.8883, 0.4593) you get a smaller amplitude that is always near zero. Same average but the stdev of this signal is much smaller, only 0.6%. It looks more market neutral.<br /><br />So which is right?<br />Best... Zvi<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1346045313195961352.post-86100980192335148622013-01-02T23:29:51.588-08:002013-01-02T23:29:51.588-08:00Try applying pca on daily returns instead of raw p...Try applying pca on daily returns instead of raw prices.sjevhttps://www.blogger.com/profile/17452562180989360928noreply@blogger.comtag:blogger.com,1999:blog-1346045313195961352.post-34431836212117267722013-01-02T20:28:22.890-08:002013-01-02T20:28:22.890-08:00Hi Jev, thanks for the interesting blog. I am tryi...Hi Jev, thanks for the interesting blog. I am trying to repeat your calc on SPY and IWM for data from 1/1/2012 through 12/31/2012. However the Coeff that princomp produces for me are different. In my runs Mathlab returns:<br />Coeff = <br />0.8883 -0.4593<br />0.4593 0.8883<br /><br />Any idea why the difference from your result?<br />My mathlab code is pretty simple:<br /><br />smbl='SPY';<br />smb2='IWM';<br /><br />% d1 and d2 were set to the beginning and end of 2012<br />[date, close, open, low, high, volume, closeadj] ... <br /> = StockQuoteQuery(smbl,d1,d2,freq) ;<br /> <br />% adjusted price data from yahoo <br />% I checked and the data is correct<br />SPY = closeadj;<br /><br />[date, close, open, low, high, volume, closeadj] ... <br /> = StockQuoteQuery(smb2,d1,d2,freq) ;<br /> <br />IWM = closeadj;<br /><br />comb1 = [SPY,IWM];<br />comb2 = [SPY-mean(SPY),IWM2-mean(IWM)];<br /><br />[COEFF2,SCORE2] = princomp(comb2);<br />[COEFF1,SCORE1] = princomp(comb1);<br /><br />% with or without the use of mean <br />% which is requested by the PCA <br />% article you referred to) the <br />% result comes out the same<br />%<br /><br />Thanks for your help,<br />ZviAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-1346045313195961352.post-41960972705817689012012-12-31T02:09:40.282-08:002012-12-31T02:09:40.282-08:00exactly. The weights are in capital, $78 short SPY...exactly. The weights are in capital, $78 short SPY & 62$ long iwm. Note that 78/62=1.26 is pretty close to beta of IWM, which is 1.2 according to google.sjevhttps://www.blogger.com/profile/17452562180989360928noreply@blogger.comtag:blogger.com,1999:blog-1346045313195961352.post-45174088395791820082012-12-31T01:02:11.069-08:002012-12-31T01:02:11.069-08:00Thanks for trying again. I understand PCA, just wo...Thanks for trying again. I understand PCA, just wondering how this would resolve to a portfolio. Should i short spy for .78 weight and go long on iwm for .62 weight to create a neutral spread?Anonymousnoreply@blogger.com