Hello everybody. I am just getting started with Quantopian.
I have a simple code where I buy at open and sell at close. But when I log it seems that I don't sell. I assume I would get zeros for share.
I can't figure where I went wrong.
I appreciate any help.
def initialize(context):
context.data = symbol('AAPL')
schedule_function(buy,
date_rules.every_day(),
time_rules.market_open())
schedule_function(sell,
date_rules.every_day(),
time_rules.market_open())
def handle_data(context, data):
pass
def buy(context,data):
order_percent(symbol('AAPL'), 0.50)
order_share = context.portfolio.positions[symbol('AAPL')].amount
#print("check order_share=",security.symbol," share=",order_share)
def sell(context,data):
order_target_value(symbol('AAPL'),0)
order_share = context.portfolio.positions[symbol('AAPL')].amount
print("check order_share=",security.symbol," share=",order_share)
Log:
2015-01-05PRINT('check order_share=', u'AAPL', ' share=', 0)
2015-01-06PRINT('check order_share=', u'AAPL', ' share=', 4705)
2015-01-07PRINT('check order_share=', u'AAPL', ' share=', 4706)
2015-01-08PRINT('check order_share=', u'AAPL', ' share=', 4671)
2015-01-09PRINT('check order_share=', u'AAPL', ' share=', 4584)
2015-01-12PRINT('check order_share=', u'AAPL', ' share=', 4581)
2015-01-13PRINT('check order_share=', u'AAPL', ' share=', 4637)
2015-01-14PRINT('check order_share=', u'AAPL', ' share=', 4615)
2015-01-15PRINT('check order_share=', u'AAPL', ' share=', 4623)