Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
History function includes weekends

Hello,

The history function is trying to include weekends when I am trying to find a local maximum for a pattern recognition algorithm. This makes it very inconvenient to work with. Is there some way not to include weekends when I am specifying how many bars ago something occurs? For example, I look back two days and see if its high is equal to the max of five days with two the left and two to the right. I would like weekends not to be included in this. Any suggestions?

4 responses

Hi Michael,

The history() API should be returning just daily trade bars, no weekends (we don't have data on the weekends). What's suggesting to you that it's returning data on weekends? I'm wondering if some weirdness with the plotting of the record() variable could be confusing here.

Best regards, 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.

Hello Jessica,

I think what is happening is the bar count in history is counting the number of calender days and not trading days. It wasn't so much returning weekend price data or anything. I was still able to adjust for this by increasing the number of bars used to detect a local maximum.

Thanks,
Michael

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

Jessica,

Thanks I think I got it to work, Its detecting local maximums and minimums properly now.