Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Help on iterating ticker symbols in context

Thank you guys for this amazing platform. It's fun to play with it. I am not a very experienced Python programmer, so I need some help now. Sorry for my unprofessional questions.
I think it was allowed to iterate data object to reference the ticker symbol of securities. But now, the data object is not iterable. How could I reference the ticker symbol of securities I pre-assigned (or fetched from CSVs) to context object?

The logic of my code is very simple:

def rebalance(context, data):  
    for my_equity in data:  
        if my_equity.symbol == my_trading_candidate_symbol:  
            equity_to_trade = my_equity  
3 responses

Hmm, do you simply want to get an equity object if you know the symbol? Assuming 'my_trading_candidate_symbol' is a string? If so, try this...

equity_to_trade = symbol(my_trading_candidate_symbol)

Check out the symbol method in the docs https://www.quantopian.com/help#api-symbol .

Thank you very much Dan for the reply! Unfortunately, my_trading_candidate_symbol is a variable not a static string. I know quantopian has this restriction. This is making a simple problem complicated. Do I have to use pipeline instead?

Ah yes. Forgot one can't use a variable with the 'symbol' method.