Back to Community
get data as vector instead of scalar?

Is there any way to replace code like this:

for k,stock in enumerate(context.stocks):  
        prices[-1,k] = data[stock].price  

with code that would pull in all of the data as a vector, from the object data? Note that I'm using this code in before_trading_start so history is not officially supported.

The loop works, but it is kinda inelegant, and maybe inefficient if the data can be retrieved as a vector.

2 responses

Something like

prices[-1,:] = [data[stk].price for stk in context.stocks]

will work, but might not be more efficient.

+1 this would be a decent option instead of the regular data arg.