Are these results good?
Are these results good?
I was trying to improve yours "Good?"
def initialize(context):
set_symbol_lookup_date('2015-01-01')
symbols("AAPL")
schedule_function(Trade, date_rules.every_day(),time_rules.market_open(minutes=60))
set_commission(commission.PerShare(cost=0))
set_slippage(slippage.FixedSlippage(spread=0.00))
def handle_data(context, data):
pass
def Trade(context, data):
price_history = history( 20, '1d','price')
prev_bar = price_history[-2]
curr_bar = price_history[-1]
if curr_bar > prev_bar:
order(symbol('AAPL'), 1)
and got an error message:
There was a runtime error on line 12
What I am doing wrong?
@Vladimir
you just never fully defined the prev_bar and the curr_bar to be for the apple stock. I came up with this code that is similar to what you have.
def initialize(context):
context.stock = sid(24)
schedule_function(Trade, date_rules.every_day(),time_rules.market_open(minutes=60))
set_commission(commission.PerShare(cost=0))
set_slippage(slippage.FixedSlippage(spread=0.00))
def handle_data(context, data):
pass
def Trade(context, data):
curr_bar = data[context.stock].price
prev_bar = data[context.stock].close_price
if curr_bar > prev_bar:
order(symbol('AAPL'), 1)