27

Aside from Zipline, there are a number of algorithmic trading libraries in various stages of development for Python. From the commercial side, RapidQuant looks very interesting though I haven't tried it yet. It's from some of same developers that brought us the excellent Pandas data analysis library. I think Wes McKinney (Pandas's main author) is involved....


16

You're not really asking how to backtest a strategy. You already have run a backtest to generate simulated trades. What you're asking for is a way to assess the performance of those simulated trades. You can do this with the R package blotter. You'll need to setup your account and portfolio, then loop over each row in your CSV and call addTxn. For ...


14

Edit (2016-06-21): Now with live data/trading integration with Interactive Brokers. It has taken a while but it has finally arrived. Edit (2017-09-20): live data/trading includes Visual Chart and Oanda (legacy accounts), order types, timers and market calendars, update with Python 3.6 and the community and other links updated A (now) very mature (imho) ...


14

If you do this, you would destroy the value of the statistical tests that you performed on the backtest. You had a hypothesis that the strategy would make money, but the hypothesis was rejected. You cannot say "I will accept the hypothesis that the opposite strategy is successful"; no statistician would agree with this conclusion. In that case, you might as ...


11

I find this one very helpful: Re-Examining the Hidden Costs of the Stop-Loss by Wilson Ma, Guy Morita, Kira Detko Abstract: In this paper, we present general implications of the impact of stop-losses to future returns. The use of stop-losses change return distributions, but not in the way that one would typically expect. We find that while stop-...


10

This is an evergreen. I've been discussing this with many people - without any clear-cut conclusion. The answer and the preferred solution depend on your trading style (e.g. frequency), your skills, the size of the team, and many other factors. For simplicity, I call "Research" the Matlab/R/etc. environments, whereas "Live" refers to the re-programmed C++/...


9

We cannot give you a relative bid-ask spread that would make sense. The reason for that is that it really depends on several parameters: The type of financial asset you invest in (futures, funds, index, options, ...) The period during which you're trading (I think the liquidity in markets hasn't been the same over time). If you trade intraday, it depends on ...


9

A Sharpe ratio of at least 1 in backtesting is a promising start, but that is just one of many statistics of interest. The Sharpe ratio measures return per unit volatility, i.e., return per unit risk. Some other important Sharpe-like measures with different definitions of risk include: Return per unit turnover (aka yield): A high yielding strategy is more ...


8

The short answer (which represents one way of surely many ways to do it) is to watch the t-stat of a performance metric such as information coefficient vanish over time. IC is the correlation of predicted expected returns from your alpha strategy to the underlying benchmark. Look at the expected returns your alpha strategy predicted over the past N time ...


8

You can find everything you want to know about this here (and in a very readable and easily reproducible form): How Students Can Backtest Madoff’s Claims by Michael J. Stutzer (2009) From the abstract: Markopolos’ writings neither described nor included any specific backtests of the strike conversion strategy. Fortunately, a backtest is relatively ...


8

Mostly because of convention and tradition. As Student T mentioned earlier, part of this is that it is common practice. You report to your clients or managers how well something performed in the past; you cannot report to them how well it performed in the future. You may have thought of some useful forward-looking measures, but unfortunately the adoption ...


8

This is a very difficult question. First of all you should read Almgren's slides on the topic: Using a Simulator to Develop Execution Algorithms. First you need to backtest your strategy against a "replayer". Ok it is not perfect, but it gives you information anyway. Provided you add some "sanity limitation" to this simulator (i.e. do not allow you ...


7

Yes, there is in fact a whole literature on this subject coming from the field of non-linear dynamics-- it is known as the method of surrogates. The idea is essentially to come up with a "scrambled" version of your original data set that preserves many of the basic statistical properties, though perhaps not the serial dependence structure which might be ...


7

In this case, the t-statistic is used to determine if the returns are statistically different from zero (the theoretical mean). A small t-statistic would imply that the null hypothesis (no significant excess return) cannot be rejected. Newey-West standard errors are used to correct for the correlations of error terms over time. I have written a Matlab ...


7

To elaborate and emphasize a bit on what @Antoine says, using adjusted prices will be reasonable from a returns point of view, with dividends reinvested. That point, dividend reinvestment, is important because dividend reinvestment itself is a backtesting assumption, namely that dividends could be and would have been invested at the price you have in your ...


6

I'd say it depends on how close you want to be to reality and what the strategy entails. For instance one scenario when actual currency makes sense is when you want to take contract sizes and position limits into account, for instance agricultural futures contracts nearly always impose a position limit for one party in one or all contracts. If your ...


6

http://www.portfolioprobe.com/2010/11/05/backtesting-almost-wordless/ shows an example of how the results from a backtest can be deceiving. This would be true with either returns or value. The main issue is that the portfolio you start with can have an impact on what "good" means.


6

When testing your strategy, what you need to pay particular attention to is performance attribution, in other words why did you see the returns you did? Let me give you a simple example to illustrate what I mean. Suppose I have an algorithm to pick stocks and you have a testing database of stock prices for one year. Suppose also that in that year the market ...


6

The IB website have a demo version of TWS for download which you can use with their C++, Java etc API. The price feed is stale and orders are not cleared but it shouldn't matter for your purposes. The demo version doesn't require a account/username. There are also active groups which can be very helpful for details on IB API. One large group is, for ...


6

If you want to backtest with closing prices, the best bet is to add a slippage to the trade price. Note, however, that transaction cost modeling is a large field within quantitative finance and there is no simple solution to estimate this.


6

possible update: http://pmorissette.github.io/bt/ based on http://pmorissette.github.io/ffn/ both were easily installed and somewhat usable for a novice. would love some examples other that github documentatiion


6

I think you are having it backwards: Optimising your lookback period is a sure recipe for disaster because it introduces data snooping bias. To develop a robust trading strategy you have to check whether it is sufficiently stable with different lookback periods (e.g. in a certain range). If results differ significantly that is a good sign that your system ...


5

We don't give strategies a dollar amount during backtesting, rather backtesting shows how much capital would be required to successfully deploy a strategy. We also don't look just at returns but many different metrics including but not limited to, max drawdown, variance of draw downs, number of trades, holding period, correlation (or lack of) with various ...


5

I can share my own experience working with the Deltix product suite. As a research and development platform it's very feature rich with support for every back-testing mode there is (BBO, Trade, Midprice, Bar, Level 2 Order Book) and advanced optimization modes (walk-forward, genetic, mean-variance, portfolio optimization, etc). I have built components and ...


5

The blog post http://www.portfolioprobe.com/2011/11/21/asynchrony-in-market-data/ explains a bit more about the problem and it also points to a paper that shows that a moving average model is the way to make the adjustment that Tal is seeking. The paper is presented in the context of a multivariate garch model. That is gratuitous, really -- the MA estimate ...


5

I suggest you avoid using the VIX for implied vols. Why? One has to consider that the VIX is not simply solely dependant on the dynamics on the S&P 500 anymore because the VIX can be traded via options, etc. Thus many more parameters affect the trajectory of the VIX. The VIX has to equal the ATM option vol because this is where arbitrage assumption ...


5

Other answers all give helpful advice, but none actually answer your question, so I will try. First off, backtesting based on close is reasonable only as a poor-man's first approximation, and before committing serious capital I would recommend collecting some higher frequency data. Having said that, it is actually quite common to investigate ideas quickly ...


5

The basic idea of pair trading is to find two symbols (I'll use that to mean stocks, futures, anything you can trade) that historically have correlated price movements. Then if just one of them increases in price you short that symbol, and buy its pair, on the assumption that they will soon go back in sync. However when you think there is a genuine reason ...


5

Quantopian provides both the fundamental data (from Morningstar), as well as the backtest platform to reproduce results from the books you mentioned. Here's the introduction to our fundamentals offering: https://www.quantopian.com/posts/fundamental-data-from-morningstar-now-available-for-backtesting (disclosure: I'm the ceo of quantopian)


5

While I've never used SIT, I have used quantstrat quite a bit and can attest to its strength. It has a solid developer community backing it (7 contributors on Github), is part of the TradeAnalytics project on R-Forge, and while it's still technically in beta, it should provide plenty of functionality. There is admittedly a pretty steep learning curve when ...


Only top voted, non community-wiki answers of a minimum length are eligible