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

I am experimenting backtest with basic algorithm that is posted on site with TWTR and made change to vwap to 10 days from 3 days.

Question. I am running backtest from 02/04/2014 to 06/02/2014 where stock price went from $65 to $30 but backtest only give me 6.29% profit. Can someone explain what is this number represent. My expectation would be more than 6% since most of these time stock was going down so I would be holding short for long time. Any comment? Advice?

def initialize(context):
context.twtr = sid(45815)
context.max_notional = 40000.0
context.min_notional = -40000.0

def handle_data(context, data):
vwap = data[context.twtr].vwap(10)
price = data[context.twtr].price
notional = context.portfolio.positions[context.twtr].amount * price
record(cash = context.portfolio.cash)
if price < vwap * 0.995 and notional > context.min_notional:
order(context.twtr,-100)
log.info("Selling %s" % (context.twtr))
elif price > vwap * 1.005 and notional < context.max_notional:
order(context.twtr,+100)
log.info("Buying %s" % (context.twtr))

6 responses

What was the capital base in the backtest? The code is limiting the position to 40k, so perhaps you had a starting cash balance of $1M? The denominator in the performance is the starting cash.

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.

I had my capital starting balances of 40k as well.

Jaydip, I think it is because the algo was ordering the +-100 shares on every bar, I think what you meant was to order a target of +-100 shares. I also put in a check for the current position size also. I went with order_target_percent so that the algo uses its entire account.

Thanks David,

 I also see that you have added context.long = False but I would like to participate in short as well if price goes below 10 day vwap and buy when its goes above 10 days vwap. Why is backtest result has huge difference when you use order vs order_target_percent? 6% vs. 37%?  

 Seems like original issue with my algo was i did not set benchmark during backtest.  

Here is back test result with Order

Jaydip, the reason that order does not do as well is because it does not take your current position into account. If you have 100 shares, order(stock, -100), will leave you with 0 shares. The 'target' style orders do take your current positions into account. If you have 100 shares, order_target(stock, -100), will leave you with -100 shares, it actually ordered -200 because that's what was required to reach the target position size of -100 shares.
Hope this makes sense, it is important to understand this if you plan to use the target style orders. Play with the attached backtest some and it should make sense.