Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to use a Variable to Retrieve an Asset for use as a Target

For instance how do I do this?

aapl_regressions = RollingLinearRegressionOfReturns(
target=sid(24), returns_length=10, regression_length=30,
)

With a variable as the target? For some odd reason, the sid function doesn't allow variables and there seems to be no way I can find to go from sid to asset.

Thanks for any assistance.

This is also a continuation of my problem here, https://www.quantopian.com/posts/how-to-get-a-list-of-assets-into-a-customfactor-to-be-used-as-targets

2 responses

If you have a problem with the sid () function, use the symbol () function instead.
It is more natural and works.

from quantopian.pipeline import Pipeline, CustomFactor, factors, filters, classifiers  
from quantopian.pipeline.factors import SimpleBeta, RollingLinearRegressionOfReturns  
from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline.filters import QTradableStocksUS  
# --------------------------------------------------------------------------------------  
STK_SET = QTradableStocksUS(); STOCK = symbol('MSFT'); BENCH = symbol('AAPL'); REGR = 21  
# --------------------------------------------------------------------------------------  
def initialize(context):  
    beta = SimpleBeta(target = BENCH, regression_length = REGR)  
    attach_pipeline(Pipeline(columns={'beta': beta}, screen = STK_SET), 'pipeline')  

def before_trading_start(context, data):  
    output = pipeline_output('pipeline')  
    b = output.beta[STOCK]  

    record(b = b, ZERO = 0)  

Thanks for responding Vladimir, but as I understand it, neither the sid() function nor the symbol() function will accept a variable, only a constant.

I'm trying to find an equivalent to sid() basically, but one that will actually accept a variable.