# Non-negative matrix factorization for factor analysis of stocks

I stumbled over the term Non-negative matrix factorization in presentations such as Application of Machine Learning to Finance and this Big Data in Asset Management.

The basic idea is to decompose a positive (!) matrix $A$ in $$A = BC.$$

Then one can interpret $B$ as factor loadings and $C$ as factors. I assume that $A$ is not a correlation matrix (which is not necessarily positive) neither a return matrix for the same reason. The authors of the first presentation use the logarithm of stock prices shifted to the right as input. I tried this myself and did not find any useful decomposition.

I have used stock prices and also shifted returns (just adding $1$) to have the whole matrix positive. Then I applied the R function nnmf of the package NMFN which uses the Multiplicative Update Algorithm. I get some "factors" but the interpretation is by far not clear. In the presentation they say that one can (probably) recognize a bear and a bull market factor.

Did you ever try such a decomposition? Which input do you use? Which algorithm and which factors do you analyze? Thanks!

PS:I am aware of PCA but I wanted to try an alternative.

EDIT: For NMF I am having a look at this as a first start.

EDIT: Apparently there are is another stream of research of cardinality constraint and non-negative exposures in PCA. Christian Sigg provides an R-package and Matlab code for doing this here.

• Did you look at lee & Seung (2001) ? May 8, 2014 at 12:27
• Yes, I quickly browsed it but I didn't see anything related to stocks or finance ... May 8, 2014 at 13:08

In the chapter that deals with NMF of the book "Programming collective intelligence" , the author did NMF on several stock trading volumes and found some comovement.

I googled a little. This did NMF on 40 chinese stock close prices. This developed A variant of nonnegative matrix factorization for Stock Trend Extraction. Another google found this also did NMF on stock close prices. This develops a method of Automatic Relevance Determination with demonstration on stock prediction task.

In my opinion, for these unsupervised learning methods such as NMF, you may need to seek hard to find the interpretation of latent factors. They might perform very well on some data, while totally meaningless in some other. They are good tools to help you explore the probable factors that affecting the outcome.

• Thanks for pointing to the book. Do you have any free reference from the web too? thanks! Jul 1, 2014 at 11:53
• Added some references, don' t know if it' s free for you, though. Jul 1, 2014 at 12:48

I am not sure if I have correctly understood your problem. But, as you want to detect the market sentiment (bear/bull), you imply that there is extra information in the market that is not included in the stock prices yet. You should then rather use a collective factorization on (on-line) news monitoring, in order to detect previously unknown topics, as you assume that the market (returns) are not aware of the change/do not include the information.

By defining topics based on words related to stocks/economic sectors of interest to you, they will show on as bursts (natural calamities) or periodically (weekly broadcasted TV shows) and the goal is to map the topics discovered at time t+1 with those discovered at time t. Monitoring the textual Yahoo news stream, with the goal of predicting the word distribution for each topic at time t, would be a good starting point, in my opinion.

A good paper on this would be "Detect and Track Latent Factors with Online Nonnegative Matrix Factorization" by Bin Cao & all.

• Thanks for your answer but my question is about the concept nnmf as described and not about factor models in general. Jun 29, 2014 at 8:47