Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Split-adjusting a stored pre-split stock price

I use the concept of Historical High (HH) (i.e. 52-wk-high) in my algorithm.
This will get me that:

context.HH_FOR_THIS_CYCLE = max(price_history2[s])  

However, during a longer sequence of buys, I want to hold that value and not update it constantly.
This is because in the scenario of a gradually rising market the HH continually gets reset each day/minute and you can't make a decision based on the original value.
I have already tried storing the HH and using it throughout the buy-sequence, which worked fine until I hit a stock split.
The stored HH doesn't get split and ends up being completely nonsensical relative to the new stock price.

Is there an easy way to take a stock price for a given time/date, and automatically adjust it to the (post-split-adjusted) price of a different time period?
Any alternative ways of getting to the same goal?

3 responses

It's generally never good to store stock price or volume data for just the reasons stated above. If all one wants is the historical high over the past n days then simply fetch the past n days of data and find the high. Don't store it. Something like this

context.HH_FOR_THIS_CYCLE = get.history(stocks, "high", bar_count=n, frequency='1d').max()

It may seem wasteful to re-fetch the same data each day, however, it's also re-adjusting for any splits and dividends to ensure prices are all comparable.

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.

Hi Dan. Understood, but the point is that my algorithm doesn't work well if the HH gets reset constantly. For example if I wanted to end the buy-cycle (i.e. sell) at 110% of the original HH, I can't do that because 110% is never reached, because the previous day/minute is always updating the HH to the current value (so always 100% roughly).
So: combining the two ideas (not storing, and directly accessing), is there a way to get the HH for a specific time period (start, end)?
Then I can just repeatedly go back and find the same (split-adjusted) HH value to trigger my sell off of.

You could simply store the date of the HH you want to store in order to access it from newly requested (and thus adjusted) data. Here's an implementation, note how the stored HH changes with the split that occured on 2014-06-09. The algo stores a new HH when the current high is >= 110 % of the stored HH (see the comments in the code for more detailed explanations).