Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Weird problem in implementing EWA/EWC pair trading: different prices in Logs and Full Backtest

I was trying to implement Ernie Chan's EWA/EWC pair trading strategy. However, I encountered a weird problem. When I print the prices of EWA and EWC in "Build Algorithm", the Logs says that the price of EWA is $20.37 on 2006-06-06, and the price of EWC is $23.78 on 2006-06-06. However, when I run full back test, the Transaction Details says that EWA is $20.23 on 2006-06-06, and EWC is $23.23. There is some difference in the price in the Logs and Transaction Details everyday. Why is that? Can anyone help to explain? This strategy is supposed to be a winning strategy, but this price difference totally screwed the algorithm up. Thanks a lot

3 responses

Hello,

You are printing $20.37/$23.78 on 2006-06-06 which are the closing prices for that day. You are placing orders on that day that are filled with the next day's closing prices which are $20.20/$23.26. With the default commission model of $0.03 per share your orders are filled at $20.23/$23.23.

If you add

set_commission(commission.PerShare(cost=0.00))  

in initialize you can disable the commision model.

P.

Peter,

Thanks a lot for the explanation. What I intended to do is that if I see the price of that day decreases, I go long at the end of that day, not the next day. What should I do to realize this? Do I have to use the minute data and place the order at the end of the day? Thanks.

You definitely need intra-day trading if you're looking at an early-day price and a late-day price.

It's not actually possible to trade at the close price while also knowing the close price. You can know the price a few minutes before the close, and then place your order, and then you'll get the price as it approaches the close.

At first it seems simple to just look at they daily open and close and try to act with those prices, but when you think about it, it's actually more complex. The close price is only the close price AFTER the opportunity to trade is past. You have to put the trade in before you know what the close price will be.

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.