I'm trying to pull the daily value of VIX from quandl and then use it to test a trading plan. I've been able to get a dataframe with the daily VIX, but I can't figure out how to pull the actual number from this. Here is my code:
"""
This is a template algorithm on Quantopian for you to adapt and fill in.
"""
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import AverageDollarVolume
from quantopian.pipeline.data.quandl import yahoo_index_vix as cboe_vix
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())
pipe = Pipeline()
attach_pipeline(pipe, name='VIX_pipeline')
pipe.add(cboe_vix.close.latest, 'vix')
def before_trading_start(context, data):
"""
Called every day before market open.
"""
context.VIX = pipeline_output('VIX_pipeline')
context.spy = sid(8554)
print context.VIX
# These are the securities that we are interested in trading each day.
#context.security_list = context.output.index
def my_rebalance(context,data):
"""
Execute orders according to our schedule_function() timing.
if context.VIX < 14:
order_target_percent(context.spy, 0.1)
if context.VIX > 30:
order_target_percent(context.spy, -0.1)
"""
pass
def handle_data(context,data):
"""
Called every minute.
"""
pass
How can I get the value of VIX into a variable I can use in the if statements?
Thanks.