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

I would like to verify if stock price is not too far (less that 5%) from VWAP before i can place an order (long or short). In case stock gap up/down I would like to sell my existing position but not to get in to new position until price and VWAP come close to each other. Any suggestion.

8 responses

This is what I came up with but only works if we know the trend and need to make below changes

((vwap - price) - (price * 0.04)) < price * 0.05: for negative trend for selling ((price - vwap) - (price * 0.04)) > price * 0.05 for negative trend for buying

((vwap - price) - (price * 0.04)) > price * 0.05: for positive trend for selling
((price - vwap) - (price * 0.04)) < price * 0.05 for positive trend for buying

good question:
positivive or negativa trend = Regression equation & Correlation coefficient (encapsulate for algorithm: what cod?) + historical data --> new inflexion point --> order low risk

init positivive or negative trend = Regression equation & Correlation coefficient (encapsulate for algorithm: what cod?) + micro/nano (milliseconds) historical data --> order high risk

Hi Jaydip,
You need to make a variable to store whether the trend is upward or downward. You can set that variable in one of the if statements, then have an "and" in the if statement to check which direction that variable is pointing. Hope this helps, but I did have some trouble understanding the question.

Gus

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.

Here is sample code with 2 back test results. I have comment in code and what I would like to happen.

Here is another back test for another block of code.

We have implemented similar strategy at tick level with FAS in live trade, it has both trend following and mean reverting, it makes profit few days but mostly loss.

So I think you want to do something like this. Note, though, that there is a warm-up period like I talked about in your other thread. It's only 5 days, so it shouldn't have too much of an effect, but let me know if you want help dealing with this. Also, you may want to trade multiple stocks, like many algorithms do. There are quite a few examples of that on the discussion board here, see if you can implement one of those!

I have put this on live trading with FAS:
https://www.quantopian.com/live_algorithms/53c6669e1c36800a5a0001ef

Return : -25% yesterday.