Hi,
I am building this simple algo on S&P500 ETF, buying the SP when VIX has decreased past 24hours, selling it otherwise.
For some reason my algo is systematically long (meaning that VIX[t1]-VIX[t0] is systematically negative...) But I can monitor the VIX data. Would you have a solution, or at least a way to monitor the output to check the data computed in my function?
Here is my code:
class last_diff1 (CustomFactor):
#out is the 1st difference of the VIX today compared to yesterday
inputs = [cboe_vix.vix_close]
window_length=2
def compute (self, today, assets, out, close):
out[:] = close[-1] - close[-2]
def my_rebalance(context, data):
# Calculating the last VIX delta
dta = last_diff1()
threshold_vix= 0
if dta < threshold_vix:
order_target_percent(context.sp500, 1)
elif dta > threshold_vix:
order_target_percent(context.sp500, -1)
Thanks.