Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
record_vars or log.info to record risk factors exposures for sector and style

I want to record my algorithm's exposure to risk factors each day, like exposure to momentum risk factor as the backtest runs. Right now, my record_vars function looks like this...but it doesn't work. Says risk_exposures is undefined.

def record_vars(context, data):  
    rolling_mean_risk_exposures = risk_exposures.rolling(63, axis=0).mean()[62:].fillna(0)  
    absolute_mean_style_exposure = rolling_mean_risk_exposures[style].abs()  
    algo.record(num_positions=len(context.portfolio.positions))  
    algo.record(style_exposure=context.absolute_mean_style_exposure)