I'm working on some helper algorithms - which may or may not prove to be useful - but I'm having a very difficult time in getting the code to execute properly.
position = context.portfolio.positions
for s in position:
print s.symbol
print s
curr = context.portfolio.positions[s].amount
known = 0
known = context.securities[s.symbol]['known_position']
orders = get_open_orders(s)
Now in that code sample everything is correctly defined elsewhere. The issue is that context.securities only gets defined (elsewhere) when I make an actual trade in a stock. In my sample I just use XIV. The problem is when I run the code it gives me an error saying AAPL is undefined - which it is. However, if I comment out the line that is causing the problem known = context.securities[s.symbol]['known_position'] then AAPL never shows up as a potential symbol.
Blockquote
2015-09-02PRINTXIV
2015-09-02PRINTEquity(40516 [XIV])
2015-09-03PRINTXIV
2015-09-03PRINTEquity(40516 [XIV])
2015-09-04PRINTXIV
2015-09-04PRINTEquity(40516 [XIV])
2015-09-08PRINTXIV
2015-09-08PRINTEquity(40516 [XIV])
2015-09-09PRINTXIV
2015-09-09PRINTEquity(40516 [XIV])
Blockquote
So what am I doing wrong?