Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Accessing a price in history

I have a question regarding the use of the history function and how to retrieve the stock price from a certain number of days ago. My code is below, and based on my understanding, "price_history[0]" should have given me the current day price, while "price_history[-1]" should give the previous day price.

However, after running the code and comparing the "log.info" statements to the "record" graph, I see that in reality, "price_history[-1]" seems to correspond to the current day's price, while "price_history[0]" and "price_history[-2]" don't seem to correspond to any of the day's prices. Am I misunderstanding the usage? If I just want to be able to display the price from 2 days ago each day that the rebalance function is run, how should I go about doing that?

I've attached the sample code that I was using to experiment with this.

Thanks!