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

Hello everyone,

I am very new to quantopian and trying to learn how to code in it. I'm an industrial engineering student, graduating next semester and trying to enter the field of data science. I backtested an already written vwap code from 2016-11-16 to 2016-12-01 with $100,000 initial capital. But i do not completely understand the backtest results as I dont have prior programming or finance experience/knowledge. Can someone please explain the code to me and the result summary tab. It would be of great help. I am working on a project and my goal is to built an algorithm based on the concepts of co-integration and pairs trading. I did see the lecture videos on co-integration and pairs trading and also went through the sample pairs trading example. But again, couldn't understand much. It would be really helpful if someone could explain this example atleast so I could proceed further.

Thank you.

Looking forward.

2 responses

I am not sure that if statement is doing what you think it is. Comparing a string "price" to be less than a variable that is an float does not seem like the correct logic?

No It's not the correct thing to do, you just need to replace 'price' with the actual price of the stock at that moment which you can get doing data.current(stock,'price'). So the full code would be:

for s in context.securities:  
        current_price  = data.current(s,'price')  
        if current_price < vwap1[s]:  
            order_target_percent(s, 1.0)  
        else:  
            order_target_percent(s, -1.0)