## Results

After having designated our X and y data for the regression modeling, it ‘s time to apply our Lasso model regression.

1 |
fitmodel = cv_optimize_lasso(df_xtrain[feature_names], df_ytrain, n_folds=4) |

1 |
fitmodel.best_estimator_, fitmodel.best_params_, fitmodel.best_score_, fitmodel.grid_scores_ |

(Lasso(alpha=0.01, copy_X=True, fit_intercept=True, max_iter=1000,

normalize=False, positive=False, precompute=False, random_state=None,

selection=’cyclic’, tol=0.0001, warm_start=False),

{‘alpha’: 0.01},

-0.70821656192264104,

[mean: -0.71097, std: 0.02741, params: {‘alpha’: 1e-08},

mean: -0.71097, std: 0.02741, params: {‘alpha’: 1e-06},

mean: -0.71096, std: 0.02742, params: {‘alpha’: 1e-05},

mean: -0.71094, std: 0.02745, params: {‘alpha’: 5e-05},

mean: -0.71091, std: 0.02749, params: {‘alpha’: 0.0001},

mean: -0.71068, std: 0.02781, params: {‘alpha’: 0.0005},

mean: -0.71041, std: 0.02821, params: {‘alpha’: 0.001},

mean: -0.70822, std: 0.03515, params: {‘alpha’: 0.01},

mean: -0.71203, std: 0.05003, params: {‘alpha’: 0.1}

1 2 |
alphawechoose = fitmodel.best_params_['alpha'] clf = Lasso(alpha=alphawechoose).fit(df_xtrain[feature_names],df_ytrain) |

1 2 3 4 |
from sklearn.metrics import mean_absolute_error err=mean_absolute_error(clf.predict(df_xtest[feature_names]), df_ytest) errtr=mean_absolute_error(clf.predict(df_xtrain[feature_names]), df_ytrain) print 'train MAE', errtr, 'test MAE', err |

train MAE 0.695980532838 test MAE 0.7297133845

### Lasso Model Coefficients

This is showing the strength of each feature in the Lasso model to describe price returns.

Momentum, as expected from the initial scatterplot data visualizations, is the strongest feature.

Note that zero coefficient values signify the feature has been eliminated during the shrinkage process.

1 2 3 4 5 6 7 8 9 10 11 12 |
lasso_coef = [] for f_idx in range(len(clf.coef_)): lasso_coef.append((feature_names[f_idx], clf.coef_[f_idx])) lasso_coef.sort(key=lambda coef:-np.abs(coef[1])) coef_names = [] coef_values = [] for f_tuple in lasso_coef: coef_names.append(f_tuple[0]) coef_values.append(f_tuple[1]) df_coefs = pd.DataFrame({'feature':coef_names,'coef_value':coef_values}) df_coefs |

1 2 |
df_coefs = df_coefs.set_index('feature') df_coefs.plot(kind='barh',legend=None, title="Lasso Coefficients"); |

### Intercept

An effectively zero intercept is not unexpected given we have centered and normalized the data.

1 |
clf.intercept_ |

4.5468220990517026e-16

### Prediction Errors

The prediction errors are somewhat bell-shaped, which at least does not disagree with regression model assumptions.

1 2 3 4 |
plt.hist(df_ytrain - clf.predict(df_xtrain[feature_names]),bins=25,label='train prediction error',normed=1,alpha=0.75); plt.hist(df_ytest - clf.predict(df_xtest[feature_names]),bins=25,label='test prediction error',normed=1,alpha=0.75); plt.title('Sample Errors') plt.legend(); |

### Other Diagnostics – Pearson Correlation

We now examine how each feature is correlated to the response price returns.

The correlation should relatively align with our Lasso Coefficient strength ordering – to some degree.

1 2 3 4 5 6 7 8 9 |
from scipy.stats.stats import pearsonr correlations=[] for f in feature_names: r=pearsonr(df_xtrain[f], df_train['P_PRICE_RETURNS'])[0] correlations.append(dict(feature=f,corr=r, abscorr=np.abs(r))) sortedFeatures=pd.DataFrame(correlations).sort('abscorr', ascending=False) sortedFeatures.set_index(['feature'], inplace=True) sortedFeatures.head(25) |

### Summary

Above we have a Lasso based price returns model that has indeed achieved some dimensionality reduction.

Are there any surprises?

We would need to study further in the financial literature each feature’s theoretical expected effect on price change, however, we consider some interesting notes below.

Momentum (i.e., P_PRICE_RETURNS_PR: trailing 6 month returns) was anticipated to be a strong predictor from the initial data visual exploration and Pearson Correlation, and this was proven out in the Lasso model. Intuitively, this makes sense though, as it is seems likely that price returns of a sample period’s month would be in the same direction as the price returns aggreagated over that sample period’s previous 6 months.

It was interesting, if not surprising, to see some difference in the relative ordering of Lasso Coefficients and Pearson Correlation of features. We should not ignore this, as it may warrant further analysis which may reveal some new understanding of the data set. One notable difference is for FF_PBK (Price to Book Value), where the Lasso has it with relatively high coefficient strength, the Pearson Correlation revealed a weaker relative connection to price returns, although both indicated a positive direction.

Price to Earnings (FF_PE) was relatively weak in both Lasso Coefficient and Pearson Correlation, but this may not be unexpected given our data set consisted of stock issued by already well established DJIA companies.

### Next Steps

An even more parsimonious model, desirable for its ability to generalize new data, could be pursued next starting with the top N, say 4, features as sorted above based on coefficient strength.

We also need to evaluate how “good” the model is. This requires a benchmark or other model to compare to. We want to avoid data mining specifically for this historical feature data set, though, as this may encourage overfitting in our model, so if it is clear these features are not working well enough we may need to consider other features, as there are many, and even possibly indicator variables to encode stock issuer industry or sector, for example. It could also be that we need to include overall market trends in the model in the form of market index based features, or adjusted returns, or some other mechanism.

Finally we would want to next attempt to model future month price returns, as opposed to, current period returns. This could be based on our current model, at least to begin with.