Hi,
I need a little help with the log.info function. I enclosed a sample algorithm which contains the problem. It simply buys 100 Apple shares once. But in the Logs I can see just this line:
"2008-01-04handle_data:11 INFO AAPL_pos: 0"
If I didn't set the condition false than it would buy more shares and keep giving logs. But always with 1 period delay. So when I have 100 shares it shows 0, when I have 200 it shows 100 etc...
I assumed that if I write the code in the attached order then:
1.) the order function buys 100 shares
2.)AAPl_pos variable sets to 100
3.)log.info shows that I have 100 shares
What is the proper use of the function if I'd like to see my share amounts without a delay?
def initialize(context):
context.test=True
context.aapl=sid(24)
def handle_data(context, data):
if context.test:
order(context.aapl,100)
AAPL_pos=context.portfolio.positions[context.aapl].amount
log.info('AAPL_pos: %s' % (AAPL_pos))
context.test=False