Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Tracking securities across the days

Hi!
I'm new here and after reading the tutorial i still feel a little lost. (by the way https://www.quantopian.com/tutorials/getting-started#lesson3 -> 'way to refrence a security. ')

If i want to track a security data (id/name, currentprice) for comparison purposes the next day. Where should i store the data?

Should i create a new var in "context" to store the possible portfolio? like

security = sid(24);

context.futurePortfolio = {}; // dunno how python works yet  
context.futurePortfolio[security.id] = security;  

or should i store them somewhere else? Searching for "save/recording vars" only led me to "def record_vars(context, data):" (https://www.quantopian.com/help#sample-record) but looks more focused on saving them for plot purporses.

All i want is a key-array dictionary so i can iterate it and fastly check if i'm already tracking a certain value by using it's index.

1 response

Welcome!

First off, and this is important, don't EVER store prices, volumes, or any values that are calculated from those, from day to day. Any stock splits will render those values meaningless and misleading (a 2:1 stock splits looks like the price dropped 50%). Simply re-query and re-calculate that data every day. The data provided by Quantopian automatically adjusts all the prices and volumes for you each day.

If you haven't looked at it already, look over the pipeline tutorial (https://www.quantopian.com/tutorials/pipeline). That is the preferred way to get stock data and it's all split adjusted. Set up the pipeline with the data you wish to track. If you want yesterdays price and todays price, then query for those two values (again don't save the values for more than the current trading day). Then simply run the pipeline every day (before trading typically) and you will get all your refreshed current data.

Good luck!