Hi Michael,
I double checked this just to be sure. History returns only trading days, not calendar days. I took a look at your logic to see if I could understand what was confusing you - my guess is that it's the fact that history returns the current day's partial bar as its most recent entry. To step through your logic and confirm this, I added a print statement to look at the last 5 data points returned by history:
print highs[stock][-5:]
Starting the algo on 4/1/2014 that returned:
2014-04-01 PRINT
2014-03-26 20:00:00+00:00 187.34
2014-03-27 20:00:00+00:00 185.34
2014-03-28 20:00:00+00:00 186.42
2014-03-31 20:00:00+00:00 187.30
2014-04-01 19:00:00+00:00 188.23
This looks correct, this is returning the CURRENT DAY'S HIGH SO FAR (2014-04-01 data point) along with the prior 4 day's high prices.
Next I added a print statement to show what your max_local() function is treating its search window (assuming I've read and interpreted your logic correctly).
log.info('window used in max_local:%s' % highs[stock][-(5)-1 :])
2014-04-01window used in max_local:
2014-03-25 20:00:00+00:00 186.94
2014-03-26 20:00:00+00:00 187.34
2014-03-27 20:00:00+00:00 185.34
2014-03-28 20:00:00+00:00 186.42
2014-03-31 20:00:00+00:00 187.30
2014-04-01 19:00:00+00:00 188.23
By asking for highs[stock][-(5)-1 :] as your window you are getting highs[stock][-6:], which includes one prior day's data. So you now have a window that includes TODAY + the prior 5 trading days.
That may be what you want, or not depending on how you want to handle the current day's data. If you do want to ignore today and look only at the prior 5 days of trading, then you should also be excluding today's high so far from your search (its currently included based on the above log). Or alternatively, if you want to include today's high so far, you can drop the extra -1 shift you have in your max_local function and you'll look at the correct window as follows:
log.info('window used in max_local:%s' % highs[stock][-5:])
2014-04-01window used in max_local:
2014-03-26 20:00:00+00:00 187.34
2014-03-27 20:00:00+00:00 185.34
2014-03-28 20:00:00+00:00 186.42
2014-03-31 20:00:00+00:00 187.30
2014-04-01 19:00:00+00:00 188.23
Let me know if that makes sense and clears up any confusion.
Best wishes,
Jess
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.