Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Symbols() with dictionary as input for a clean rotation strategy code

Dear all,
cleaning up my code, I was trying to feed in a dictionary values to Symbols() such as

    context.instrument = {'equity':'SPY', 'tresury':'TLT', 'hedge_tres':'TMV', 'cash':'SHY'}  
    context.stocks = symbols(context.instrument.values())  

I have also tried the following fomat:

context.instrument = {'equity':'SPY', 'tresury':'TLT', 'hedge_tres':'TMV', 'cash':'SHY'}  
t = context.instrument.values()  
context.stocks = symbols('\''+'\',\' '.join(t)+'\'')

neither seem to be working. Any ideas ?

I want to be able to call context.instrument['equity'] in my code rather than context.stocks[0] - It improves readability for the kind of strategies I'm working on.

2 responses

Use symbol('SPY'), etc:

context.instrument = {'equity':symbol('SPY'), 'treasury':symbol('TLT'), 'hedge_treasury':symbol('TMV'), 'cash':symbol('SHY')}  

Thx. works perfectly.

for those using zipline, you may combine with the following:

new_data = [''.join(w) for w in algo.instrument.values()]  
data = load_from_yahoo(stocks=new_data, indexes={},start=algo.startDate, end=algo.endDate)  
data = data.dropna()  
results = algo.run(data)