Here's an example:
def initialize(context):
context.securities = ['AAPL', 'BIDU', 'MSFT']
def handle_data(context, data):
order(symbol(context.securities[0]), 10)
record(AAPL=data.current(symbol(context.securities[0]), 'price'))
record(BIDU=data.current(symbol(context.securities[1]), 'price'))
record(MSFT=data.current(symbol(context.securities[2]), 'price'))
I'm using zipline locally (not that it should matter), but I want to chart a security's price against my portfolio, but the only way to record the price of the stocks is to use the record function and hardcode the keyword variables (names of the securities). I've tried looping through the list and doing:
record(context.securities[0]=data.current(symbol(context.securities[0]), 'price'))
instead of
record(AAPL=data.current(symbol(context.securities[0]), 'price'))
But get a syntax error: SyntaxError: keyword can't be an expression
Any ideas?