MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayTo resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Asked by Andrew Kreitzman on 25 Jun 2013

I am trying to use the mvregress function to regress stock returns over various style factor weights (8 to be exact) and also a binary variable representing the industry (essentially, we have a 34-column matrix of zeros with one 1 in every row to indicate the industry the equity belongs to. I have grouped the stocks by country, so all of my data (returns, industry factor, and style factors) exist in 1x68 cells, with each matrix representing a different country. I want to use a for loop to iterate over every country when the regression is run. Here is what I tried. I understand how the multivariate regression works in real life, but I am having trouble implementing in MATLAB:

for i = 1:(numel(code_list)-1) factor_regressor_cell{1,i} = horzcat(industry_cell{1,i},style_factors_cell{1,i}); end

for i = 1:(numel(code_list)-1) [beta1,~,E,covB,~] = mvregress(factor_regressor_cell{1,i},returns_cell{1,i}); end

I am also getting warnings from MATLAB to preallocate for speed before my for loops, especially those involving cells. Does anyone have a relevant example of how to do this....I was having trouble finding a good exmaple that applied to my code. Thanks!

*No products are associated with this question.*

Answer by the cyclist on 2 Jul 2013

See my answer to this question

for a simple, commented example of using mvregress. Using the design matrices is admittedly tricky.

There are also examples on the Mathworks site:

## 0 Comments