As I mention before, you may create your own CustomFactor using as much data as avalable and use pipeline to get the results.
Here are CustomFactors for 100 and 1000 day moving averages of VIX.
Try them.
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline, CustomFactor
from quantopian.pipeline.data.quandl import cboe_vix
import pandas as pd
# --------------------
MA_F, MA_S = 100, 1000
# --------------------
def initialize(context):
columns = {'VixClose': GetVIX(), 'VixMavgF': GetVixMavgF(), 'VixMavgS': GetVixMavgS()}
attach_pipeline(Pipeline(columns), 'vix_pipeline')
def before_trading_start(context, data):
output = pipeline_output('vix_pipeline')
vix_last = output['VixClose'].iloc[-1]
vix_mavg_fast = output['VixMavgF'].iloc[-1]
vix_mavg_slow = output['VixMavgS'].iloc[-1]
record(vix_last = vix_last, vix_mavg_fast = vix_mavg_fast, vix_mavg_slow = vix_mavg_slow)
class GetVIX(CustomFactor):
inputs = [cboe_vix.vix_close]
window_length = 1
def compute(self, today, assets, out, vix):
out[:] = vix[-1]
class GetVixMavgF(CustomFactor):
inputs = [cboe_vix.vix_close]
window_length = MA_F
def compute(self, today, assets, out, close):
close = close.ravel()
mean_close = pd.Series(close).rolling(MA_F).mean()
out[:] = mean_close.iloc[-1]
class GetVixMavgS(CustomFactor):
inputs = [cboe_vix.vix_close]
window_length = MA_S
def compute(self, today, assets, out, close):
close = close.ravel()
mean_close = pd.Series(close).rolling(MA_S).mean()
out[:] = mean_close.iloc[-1]