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

In an algo I have these two commands:

vwap = data[context.aapl].vwap(3)
price = data[context.aapl].price

When the vwap is calculated, does it the 3 day average start at the timestamp of the calculation, or by end of day prices?

Similar with price, does it represent the end-of-day price, or the price at the time of the program execution?

Thank-you

1 response

The short answers are that vwap and price both use closing prices, which is end-of-day close for daily bars and end-of-minute close for minute bars.

Longer answer: those two commands are going to be in handle_data(). handle_data() runs once per data bar. The bars are either minute bars or daily bars, depending on which mode you're in. vwap() and price both use the closing price in the most recent bar.

So, for instance, if you're in daily mode and you call that code, and handle_data() is processing the third trading day of the month, then the vwap(3) is the average of the 3 closing prices that month, and the price is the close of the third trading day.

If you're in minute mode it gets a bit trickier because there are 390 minute bars in most trading days. Take a similar example to the one before, but this time it's 12:30PM on the 4th day of trading. The vwap(3) uses the closing bars on the 1170 most recent minutes (210 bars from the first day, all of the 2nd and 3rd, and all 180 bars in the 4th day). The price is the close price on the most recent minute.

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.