Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
VWAP confusion

From the details outlined on this page: http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:vwap_intraday
It states that "Remember, VWAP calculations start fresh at the open and end at the close. 150 minutes of trading have elapsed by 12:00PM. Therefore, VWAP at 12:00 would need to be compared with a 150 minute moving average. "

Within my code, I have the following: vwap[sid] = data[sid].vwap(bar_count = 1)
Using minute data, would this return all the bar data within the day? So it would only return 1 value at 9:31AM, and it would return 150 values at 12:00PM?

If that is the case, what would the return values be if I had set bar_count = 2?

2 responses

The .vwap() function isn't the best choice for this specific implementation. What I recommend that you do is call the history() function. Check out the documentation here, particularly the "Common Usage: VWAP" section.

You'll want to take that example and modify it. Change it to '1m' rather than '1d' - you want minute bars, not daily. Change the length to 390, which is the maximum number of minutes in a day. Then you're going to want to do a little bit of pandas magic and slice off the fraction of the 390 minutes for any given fraction of the day. At 9:31, you'll only look at the most recent minute; at 9:32 you'll look at the most recent two minutes; at 4:00 you'll look at the entire 390.

All that said, I'm not sure why you'd want to look at it that way. Generally, moving averages (and VWAPs) have fixed window lengths. The way that's described there will give you a really volatile number in the first few minutes and a relatively stable number at the end of the day. There's more than one way to calculate VWAP periods. That link articulates a specific one, but it's not the only one. Make sure you've got one that matches what you want.

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.

Thanks so much! This helped a lot!