Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Is adjusted close price available using history()?

When performing financial time-series analysis over a long period of time, usually one must consider the occurrences of stock splits, buy-backs, and dividends. This is important because when performing some statistical analysis on previous returns, these events will alter the results one gets. For instance, if there is a 2:1 stock split the price of the stock appears to have plummeted 50%, but really the price is the same relative to the amount of outstanding shares. Obviously, this is a huge problem and virtually nullifies all analysis following the retrieval of such data.

Is it possible to return, using the history() function, the adjusted close price of whichever instruments are requested? If not, would it be possible to figure out when these events occur in history (splits, buy-backs, dividends) so one could make their own adjusted close price?

8 responses

Hello Grant,

Per https://www.quantopian.com/help#overview-datasources:

Our data uses adjusted close prices. That means that the effect of all stock splits and merger activity are applied to price and volume data. As an example: A stock is trading at $100, and has a 2:1 split. The new price is $50, and all past price data is retroactively updated 2:1 (volume data is correspondingly updated 1:2). In effect, that means you can ignore stock splits unless you are storing prices in a live trading algorithm. In a live trading algorithm, the stored variable needs to have the split applied to the price and volume. In a backtest, the split is already applied retroactively to all data.

Regarding dividends, see https://www.quantopian.com/help#ide-dividends. Note that:

Dividends are not relayed to algorithms as events that can be accessed by the API; we will add that feature in the future.

Grant

Thanks Grant!

Grant

Hi Grant, I notice that the prices are not split-adjusted for at least one specific symbol that I am interested in: UPRO. If you look at the daily closing prices of UPRO since say May 15th, 2015 to June 2nd, 2015 you can see the price appears to drop by 50%. Is there something I am missing here? I would like to get the adjusted close price for my algorithm to work. Please help.

Thanks,
Rag

Dividends are reflected as cash that magically appears:

"The portfolio's cash position is increased by the amount of the dividend on the pay date."

One could detect such events by careful accounting of one's cash. But if two or more securities pay dividends at the same time, tough luck.

We do have a change we're working on to provide dividend-adjusted prices. The plan is here, the work is still in progress.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

The data that I am getting from history() is not split adjusted for at least one stock. Just picking a random date of 10.19.2010 for AAPL, I see a price of 309.65 reported by the history() function. A quick check on yahoo for that date shows a price of 309.49 and an adjusted close of 44.21.

I checked 'open' and 'close' as well as 'price' options for history() and none of them report a split-adjusted value.

Maybe someone on the Quantopian team can address this better than I can, but I'll take a stab at it.

The history() function as well as the data returned by the pipeline ARE split adjusted. They are split adjusted as of the backtest date.

What does this mean? The prices returned by these functions are the split-adjusted prices one would have seen on the date that the pipeline or history() was run. To test this, let's use our WABAC machine to go back in time to 10/20/2010...

The 'current' 10/20/2010 price for AAPL is at $309. If we get pricing, using our history function or pipeline, for the day before on 10/19/2010, we get AAPL close of $309.65 a share. Because there were not any stock splits overnight (between 10/19 and 10/20), $309.65 is how much one would have needed to buy one share. $309.65 was the the 'real' price. That was the amount of hard cash deducted from ones account to buy one share on 10/19/2010.

Note that history and pipeline return a range of data over the previous n days. If there were no stock splits during that range then the returned prices will simply be the actual 'real' prices for those days. If there were no stock splits during that range, the history and pipeline functions simply lookup ACTUAL values for those days and return them. Period.

This makes sense. We want the backtester to reflect exactly the data one would have seen on a particular backtest date.

Now, if AAPL happened to have a 2:1 stock split effective on 10/20/2010, what would that look like? First, the current 10/20/2010 price would be $154.50 and not $309 (each share is worth only half the value but there are also twice as many shares outstanding). If we now get pricing, using our history function or pipeline, for the day before on 10/19/2010, we see AAPL close of $154.825 a share. This price was 'adjusted' for the stock split as of 10/20/2010. $154.825 is NOT how much one would have needed to buy one share on 10/19. $309.65 was the 'real' price. The adjusted $154.825 price is simply a mathematical construct to make it easier to compare 'apples to apples' (excuse the pun). Without adjusted prices, it would look like AAPL stock shot up 100% in one day.

On Quantopian, the historical prices are split-adjusted as of the backtest date.

On Yahoo, the historical prices are split-adjusted as of the current date (ie today). The adjusted prices start with the current date and march backwards 'adjusting' for each previous split. By the time Yahoo gets to 10/19/2010 it has adjusted for splits that hadn't even occurred as of 10/20/2010.

When adjusting for splits one needs to specify the 'as of' date. Different 'as of' dates may yield different adjusted prices based upon the timing of any splits. This is also why one cannot save history data, and compare it, from one day to the next. History will get 'adjusted' data with different 'as of' dates (ie the backtest date).

Maybe as clear as mud?

Bingo. That was the piece I was missing. I did a check over a time period where a stock split and verified that the prices are split-adjusted over the time period of the history() function request.

Another way to say this is that all the prices in the return of the history() request are split-adjusted consistently as compared to the first value.

(As if the first value is the present value given that we took the WABAC machine to that time and know nothing about pricing at future dates.)

Thanks!