Back to Community
Help with Linear Regression as Factor

Hi All,

I'm looking to use the attached linear regression envelope with alphalens across multiple assets. In other words, I want to build the values of the envelope in as factors to my pipeline. I have all the alphalens logic figured out, however, I can't seem to get the correct values of the linear regression envelope into my pipeline object. All this factor would do is compute the predicted value at that time based on a linear regression model for the past 100 days, which could be expressed as price.iloc[-1]['linreg'] in my current notebook. This needs to be rolling and be calculated for each day and each asset in the pipeline.

Note: My 'Y' values for the linear regression are currently the values of a custom moving average I created, but for now, I'm fine with just using the closing price of each asset as my 'Y' value.

Any and all help would be appreciated! Thank you.

Loading notebook preview...