In a previous post, we introduced three built-in factors which could be used to compute correlations and regressions between the returns of stocks. Now, three new methods have been added to Factors to allow for more flexible computations:
linear_regression. In principle these methods work the same as the built-in factors, but they allow for things like correlations between two different factors or between a factor and a dataset. For example, you could compute the correlation between each column of a
Returns factor and VIX (VIX is now treated as a single column of values).
One important distinction between these methods and the built-in factors is that they no longer accept an Asset object as their target parameter, but instead accept a
Slice object. A
Slice can simply be thought of as a single column of a Factor corresponding to a particular stock. Slices can be created by indexing into a Factor, keyed by Asset:
# Create a Returns factor and extract just AAPL's returns. returns = Returns(window_length=30) aapl_returns_slice = returns[sid(24)]
There are various restrictions as to how these methods and Slices can be used, so check out the attached notebook for detailed examples and explanations. For an overview of the new methods, check out the docs here.