I am reading some volatility stategies as it's popular on the site such as
https://www.quantopian.com/posts/trading-vix-quandl-data-now-in-pipeline-for-backtesting-and-live-trading
def initialize(context):
"""
Called once at the start of the algorithm.
"""
# Rebalance every day, 1 hour after market open.
schedule_function(my_rebalance, date_rules.every_day(), time_rules.market_open(hours=1))
# Record tracking variables at the end of each day.
schedule_function(my_record_vars, date_rules.every_day(), time_rules.market_close())
# Create our dynamic stock selector.
# Create, register and name a pipeline in initialize.
pipe = Pipeline()
attach_pipeline(pipe, 'example')
# Add the TermStrucutreImpact factor to the Pipeline
ts_impact = TermStructureImpact()
pipe.add(ts_impact, 'ts_impact')
# Define our securities, global variables, and schedule when to trade.
context.vxx = sid(38054)
context.xiv = sid(40516)
context.impact = 0
def before_trading_start(context, data):
"""
Called every day before market open.
"""
output = pipeline_output('example')
output = output.dropna()
log.info(output)
context.impact = output["ts_impact"].loc[context.vxx]
But the output part really confuses me. I know every day (every bar) , It did some calculation to update our pipeline. But why the pipeline has to include thousand hundreds of securities for the indexes.(maybe it's a lot of calculation to do the loc[vxx]) Under this circumstance actually it only needs the VXX for the index. Any ideas? Check the plot below for two days output.