I am working on an SPY trader with a VXX hedge algorithm that adjusts its positions based on the first hour of trading. It is a relatively simple program with two securities and four functions. I am trying to see what returns would look like if I changed the percentage at which I decided to be bearish or bullish for that day. My first code returned 110% with a -.006 threshold and I am currently live paper trading that. I came back to try -0.002, -0.003, -0.004, and -0.005 thresholds but I keep getting the same return for each strategy. My code is posted below. Is there anyone that can tell me why this is happening?
def initialize (context):
context.spy = sid(8554)
context.vxx = sid(38054)
schedule_function(opening_trades, date_rules.every_day(), time_rules.market_open())
schedule_function(midday_trades, date_rules.every_day(), time_rules.market_open(hours=1))
schedule_function(closing_trades, date_rules.every_day(), time_rules.market_close())
def percent_change(context, data):
hist_spy = data.history(context.spy, 'price', 2, '1d')
yest_close = hist_spy[-2]
current_price = hist_spy[-1]
percent_change = (current_price - yest_close) / yest_close
def opening_trades(context, data):
if data.can_trade(context.spy):
order_target_percent(context.spy, 0.50)
if data.can_trade(context.vxx):
order_target_percent(context.vxx, 0.50)
def midday_trades(context, data):
percent_change(context, data)
if percent_change > 0 and data.can_trade(context.vxx):
order_target_percent(context.vxx, -0.50)
if percent_change < -0.003 and data.can_trade(context.spy):
order_target_percent(context.spy, -0.50)
def closing_trades(context, data):
for security in context.portfolio.positions:
order_target_percent(security, 0)