# Forecasting next day return of a stock using PCA of index constituents

I am trying to predict the return of BN4.SI ( a singapore stock ) and part of Strait Times 30 component index using principal component Analysis. I have written my code in python.

My Question is i have got factors loading how can i predict the next day return of BN4.SI based on this PCA Factors.

The steps i have taken are

1. Get the matrix of standardised returns of all stocks. Standardised log returns are [(x - mean)/std for x in array]
2. Generate covariance matrix of the return matrix and that should give me a square matrix ( m X m)
3. I am using numpy linear algebra eig function to calculate eigen values and eigen vectors. Since my returns are standardised then sum of eigen values should be equalled to number of components.
4. Then sort the eigen values in decending order to get first 3 eigen values which explains almost 80% of the variance. This is shown in scree plot in the picture added below.
5. Next step is to get top 3 PCA vector which is acheived by getting the dot product of eigen vector and the original return matrix data. pca1 = ti.np.dot(newDF,eVector1.reshape(-1,1)).reshape(1,-1) pca2 = ti.np.dot(newDF,eVector2.reshape(-1,1)).reshape(1,-1) pca3 = ti.np.dot(newDF,eVector3.reshape(-1,1)).reshape(1,-1)
6. To perform linear regression with BN4.SI standarised return data. I need to get the matrix of the transpose of PCA vectors. np.column_stack([pca1.T,pca2.T,pca3.T])
7. I am using sklearn to do linear regression.

from sklearn import linear_model model = linear_model.LinearRegression() model.fit(ti.np.column_stack([pca1.T,pca2.T,pca3.T]),newDF["BN4.SI"]) model.score(ti.np.column_stack([pca1.T,pca2.T,pca3.T]),newDF["BN4.SI"]) print(model.coef_) print(model.intercept_)

[ 0.2802088 0.37944899 0.13462393] -1.15582251414e-18

• Please remove this long screenshot. PCA describes what has happend it does not forecast the future. – Richard Jun 2 '17 at 12:15
• @Richard - I never quite got this argument. Most data people use describes what has happened - somehow this doesn't stop anyone from trying to forecast the future. – LazyCat Jun 12 '17 at 14:18
• @LazyCat the key question is whether the factors identified by PCA are persistent or not. It needs to be checked, not just assumed. – noob2 Jun 12 '17 at 14:34
• @noob2 with that I fully agree. My point was that you can't brush off attempts at using PCA for forecasting simply because it "describes what has happened". – LazyCat Jun 12 '17 at 14:40
• @LazyCat please see my answer – Richard Jun 12 '17 at 14:56

I decided to write an answer in order not to write too many comments.

What do we get by PCA? Let us assume we have $n$ random variables. We get a representation of the data of the form $$X_i = e_{1,i} P_1 + \cdots + e_{n,i} P_n$$ where the PCAs $P_1,\ldots,P_n$ are uncorrelated (not necessarily independent) and ordered (descending) by variance.

The above relation is estimated from past data.

In the world of interest rates $X_i$ could be the change (rather not the level) of vertex $i$ and it turns out that the change of the i-th rate can be decomposed into a parallel shift ($P_1$) and a steppening ($P_2$) and so on. This conditional on the future realization of $P_1$ we can estimate the change of vertex $i$ as it is estimated to be proportional by a factor $e_{1,i}$ to the parallel shift. The relation above does not tell us whether $P_{1,t+1}$ the future pf $P_1$ will be positive or negative.

In the case of stocks we usually take $X_i$ to be the return of asset $i$. And the principle components are a market factor and several long/short portfolios. If we can predict the market then we can plug this into the above equation.

Note that as far as I remember $e_{1,i}$ is not the beta of the stock in the stock setting. Thus we would get a forecast cheaper by looking a betas and forecasting the broad market.

• Thank you for expanding your comment. While all you've wrote is fine, I don't see how this implies, that one cannot try to use PCA for forecasting. – LazyCat Jun 12 '17 at 15:44
• You can try :) ... So you have a reference where a PCA itself is forecast? – Richard Jun 12 '17 at 15:45
• Well, say, you pick a group of stocks (e.g. an industry), and use the returns of the first PC to forecast all the returns of all the stocks in the group. If the group is large enough, the noise for the returns of PC1 will be much less, that that of individual stocks. This is pretty much what "Statistical Arbitrage in the U.S. Equities Market" by Avellaneda/Lee is doing. – LazyCat Jun 12 '17 at 15:48
• So you trade on the residuals and assume that the asset's future return reverts to where the present (truncated) PCA indicates, right? have to read that in detail. – Richard Jun 12 '17 at 16:04
• @Richard - yes, if I understand correctly where your residual comes from. Heuristically, you'd go long the stocks whose return is below that projected by PC1 and short the stocks that outperformed PC1. – LazyCat Jun 12 '17 at 16:17