# principal component analysis on non stationary data

I read that since stock prices are non-stationary it does not make sense to take their covariance. So I took the log returns of stocks, computed covariance matrix, took the top few eigen vectors that explain maximum variance and instead of projecting the returns I projected the log prices on these vectors. Is there anything wrong with this approach? python code below:

logprices = numpy.log(prices)

logreturns = numpy.diff(logprices, axis=0)

cov = EmpiricalCovariance().fit(logreturns).covariance_

eigenvalues, eigenvectors = numpy.linalg.eigh(cov)

components = eigenvectors[:, :5] # top 5 eigen vectors

sources = numpy.dot(logprices, components)

• Clarify what you precisely mean by, "...instead of projecting the returns I projected the log prices on these vectors?" – Matthew Gunn Aug 6 '17 at 2:20
• I meant I take the matrix dot product of log prices and eigen vectors. – pavybez Aug 6 '17 at 2:27
• Here on Cross Validated is a somewhat related discussion (but perhaps too far from what you are interested in). – Richard Hardy Aug 6 '17 at 11:37

You may know that they are two definitions of stationary (see for instance Series of Irregular Observations: Forecasting and Model Building; this book probably contains all you need to model timeseries, and it is now new):

• strongly stationary means each time you have an observation (for you an observation is a vector of returns of dimension you number of stocks) it is drawn from the same distribution;
• weakly stationary means each time how have an observation, it is drawn from a distribution that has the same expectation (i.e. mean) and variance (i.e. here covariance matrix).

If you believe mixing your observation to obtain a covariance matrix and make his PCA, what would you need ?

• a first answer is you need your observations to be weakly stationary to be able to even speak about their covariance matrix, no?
• but you can relax it and say you only need the eigenvectors and eigenvalues you will keep to be strongly stationary. You will need the betas of the stocks with respects to these components to be "stable", say constant.

The second option is another model, it is in fact a factor model. It states the returns $R_k$ of the $k$th stock is equal to

$$R_k = \beta_k F_k + \epsilon_k,$$

where $\epsilon_k$ is no more stationary... You will for sure need its variance to be far lower than the one of $\beta_k F_k$ to be able to identify the factors.

As usual in statistics, all is matter of model choice. You need to be aware of your choices, use estimators that are compatible with them (imagine for instance your random vector of $\epsilon_k$ is somehow "synchronized" to drive $R_k$ towards highly negative values during months, and then switches them to positive values... you will need an ad hoc estimator). And at the end of the process, you will need to check all the parameters you obtain are compatible with your initial hypothesis.