Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Help with Algorithm, so stuck

Import VIX from Yahoo (this part works)

import pandas as pd

url ='http://www.quandl.com/api/v1/datasets/YAHOO/INDEX_VIX.csv?request_source=python&request_version=2&sort_order=asc&trim_start=2002-01-01'

Define variables (this part seems to work)

def initialize(context):
context.spy = symbol('SPY')
context.tlt = symbol('TLT')
context.date = None
fetch_csv(url,
symbol='VIX',
date_column='Date',
pre_func=add_fields)

Define 90 day SMA change (not sure)

def smachange(context, data):
sma = data[context.spy].mavg(90)
price = data[context.spy].price

Define 30 day VIX change (stuck here)

def vixchange

This is what I'm trying to accomplish

If SMA changes -10% or VIX +10% then move 100% from SPY to TLT

if SMA -10% and VIX +10% move from SPY to TLT

if smachange > -20% or vixchange > 20%:

order(context.tlt,100%)

if SMA +10% and VIX -10% move from TLT to SPY

if smachange > 20% and vixchange > -20%

order(context.spy,100%)

algorithm should run every 90 days based on last 30 days VIX/SMA changes

6 responses

The tricky part of this will be getting access to the historical prices of your fetched VIX series. I've done this before, I posted a workaround on this forum somewhere about three or four months ago.

Thanks..what about calculating 90 day SMA?

Yes you can calculate that using pandas rolling_mean.

I wonder if anyone on fiverr does quantopian algorithms. I'm fried.

Maybe, I know some folks on here will do algo consulting, but if you want to get someone who knows what they are doing, it might be more costly than you expect. I think Richard does this sort of work: http://quant-coder.prokopyshen.com/ContactMe