I attempted to recreate this algorithm:
http://volatilitymadesimple.com/vix-mores-vixvxv-ratio/
with the use of this as a secondary resource
http://vixandmore.blogspot.com/2013/09/revisiting-vixvxv-ratio.html
The first article provided the bulk of the information along with decisions to invest vs to withdraw. I attempted to recreate the algorithm in the attached back test. I may have messed up somewhere in the algorithm because i'm not getting similar results to those that they included in their tests.
Did I make an error somewhere?
*not letting me attach the backtest
import pandas
import pandas as pd
VxvUrl = 'http://www.cboe.com/publish/scheduledtask/mktdata/datahouse/vxvdailyprices.csv'
"""
Geting VIX price
"""
#reference article http://volatilitymadesimple.com/vix-mores-vixvxv-ratio/
#reference article2 http://vixandmore.blogspot.com/2013/09/revisiting-vixvxv-ratio.html
def rename_col(df):
df = df.rename(columns={'CLOSE': 'price'})
df = df.rename(columns={'VIX Close': 'price'})
df = df.rename(columns={'Equity Put Volume': 'price'})
df = df.fillna(method='ffill')
df = df[['price', 'sid']]
# Correct look-ahead bias in mapping data to times
df = df.tshift(1, freq='b')
df['mean'] = pd.rolling_mean(df['price'], 2)
log.info(' \n %s ' % df.head())
return df
"""
The initialize function sets any data or variables that
you'll use in your algorithm.
It's only called once at the beginning of your algorithm.
"""
def initialize(context):
# set up XIV
context.XIV = sid(40516)
context.VXX = sid(38054)
context.UVXY = sid(41969)
#fetch VXV data
fetch_csv('https://www.quandl.com/api/v1/datasets/CBOEFE/INDEX_VXV.csv?trim_start=2012-01-01',
date_column='Date',
symbol='VXV',
post_func=rename_col,
date_format='%d-%m-%Y')
context.VXV = 'VXV'
# fetch VIX data
fetch_csv('http://www.quandl.com/api/v1/datasets/CBOEFE/INDEX_VIX.csv?trim_start=2012-01-01',
date_column='Date',
symbol='VIX',
post_func=rename_col,
date_format='%d-%m-%Y')
context.VIX = 'VIX'
# Specify that we want the 'rebalance' method to run once a day
schedule_function(rebalance, date_rule=date_rules.every_day())
"""
Rebalance function scheduled to run once per day (at market open).
"""
def rebalance(context, data):
# We get VIX's current price.
current_price_xiv = data.current(context.XIV, 'price')
current_price_vxv = data.current(context.VXV, 'price')
ratio = current_price_xiv/current_price_vxv #xiv/vxv
current_price_vxx = data.current(context.VXX, 'price')
"""
invests on xiv and vxx depending on the ratio
"""
# If XIV and VXX is currently listed on a major exchange
if data.can_trade(context.XIV) and data.can_trade(context.VXX):
#long xiv when ratio <0.92
if ratio < 0.92:
order_target_percent(context.XIV, 1)
order_target_percent(context.VXX, 0)
log.info("XIV: %s" % current_price_xiv)
#long vxx when ratio >1.08
if ratio > 1.08:
order_target_percent(context.XIV, 0)
order_target_percent(context.VXX, 1)
log.info("VXX: %s" % current_price_vxx)
record(ratio = ratio,
xiv = current_price_xiv,
vxv = current_price_vxv
)