Hi everyone,
Apologies in advance for the dumb questions - this is my first Quantopian algorithm and I am new to Python as well.
The strategy that I am trying to test:
- we are using Vanguard S&P500 ETF all the way (VOO);
- we are in a buy and hold position all the time, EXCEPT when two conditions are met:
-VOO is below its 12-month moving average
AND
- unemployment rate is above its 12-month moving average.
This is the code that I ended up having:
def initialize (context):
context.voo = sid(40107)
date_rule=date_rules.month_start(days_offset=5)
time_rules.market_open(hours=1)
def handle_data (context, data):
hist = data.history(context.voo, 'price', 400, '1d')
monthly_voo = hist.resample('1M').last()
sma_12_voo=hist[-12:].mean()
from quantopian.pipeline.data.quandl import fred_unrate
sma_12_unempl=hist[-12].mean()
if monthly_voo>sma_12_voo or fred_unrate<sma_12_unempl:
order_target_percent(context.voo,1,0,style=MarketOrder)
else:
order_target_percent(context.voo,0,0,style=MarketOrder)
The error that I am getting:
Runtime exception: NameError: name 'monthly_voo' is not defined
I would really appreciate is someone could help me debugging this.
Also - if you see any other errors, please let me know. Many thanks in advance for all your help!