Back

Questions about VWAP

Hello everyone,

I'd like to implent VWAP in my algorithm and I'm wondering about two things.

On my trading platform I can apply VWAP to a chart without specifying anything else. I think it's calculated from the beginning of every day as a cumulative indicator. I'd like to have the same VWAP in my algorithm. What should I take as a time period? Is it even possible to do it as on my platform?

I've tried to implent VWAP using a dictionary for the values of each stock I want to trade as I do with my rolling windows but something is not working. If I log it there is a value for VWAP but when I change

if (last_bar > 0 and second_bar > 0 and third_bar > 0 and last_min_open < last_close):

to

if (last_bar > 0 and second_bar > 0 and third_bar > 0 and last_min_open < vwap < last_close):

I get an error "Cannot get managed object". What am I doing wrong?

Attached is the working version of the algorithm without the change.

Thank you in advance!

Kind regards,

Christian Lauer

Update Backtest








The issue is your assignment statement

# This is defined in the 'Initialize' method
self.vwap[symbol]= self.VWAP(symbol, 20000)
.
.
# Then it's referenced later in the algorithm
# vwap is the indictor object NOT the value
vwap = self.vwap[symbol]

'vwap' in this case is the indicator object and NOT the value. To get the current value of an indicator use the '.Current.Value' method. Something like this should work and eliminate the error "Cannot get managed object".

# Use the '.Current.Value' method to get the value
vwap = self.vwap[symbol].Current.Value

You may also want to use a different local variable name other than 'vwap' to avoid confusion with variable 'self.vwap' . It works fine (and is why we always need to explicitly specify 'self' to avoid ambiguity) but just a precaution.

Good luck!

0

Thank you for your answer!

Now that I get values I have to solve the other issue to get the correct ones calculating VWAP from the beginning of the trading day. Does anyone know how I could achieve this? Maybe counting the seconds somehow and then using this value for the time period?

Kind regards,

Christian Lauer

0

Christian Lauer I would do it manually using the VWAP object instead of the helper. Each day create a new VolumeWeightedAverageVolume() indicator and update it.

You can't do indicator.Update in python yet but I've asked Alexandre Catarino to look into it and hopefully we'll have that option today.

0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Here's an example of using the built-in VWAP indicator along with resetting each day. It's important to set the period of the VWAP indicator to something larger than the number of resolution steps per day. For minutes, this is 390 (6.5hrs*60min/hr). I've also provided a plot of the VWAP and Price.

0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Thank you very much for your answers. I think now everything is working as it should even though the values are slightly off from my source. Could you maybe check my algorithm to see if I've done everything right?

Kind regards,

Christian Lauer

0


Update Backtest





0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed