We’re rewarding the question askers & reputations are being recalculated! Read more.
43

Consider the standard error, and in particular the distance between the upper and lower limits: \begin{equation} \Delta = (\bar{x} + SE \cdot \alpha) - (\bar{x} - SE \cdot \alpha) = 2 \cdot SE \cdot \alpha \end{equation} Using the formula for standard error, we can solve for sample size: \begin{equation} n = \left(\frac{2 \cdot s \cdot \alpha}{\Delta}\...


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

I unfortunately can't point you to a great book on the exact subject that you're describing. The closest thing for beginners is "Quantitative Trading". It's a reasonable introduction, but I really wouldn't recommend it as a primary source. The author is at best incomplete (if not misleading) on a number of issues. My favorite book at the moment is ...


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) ...


13

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 ...


12

I'll not say how most people do it, but rather how I think most people should do it. You should compare the actual strategy with a number of goes of randomly trading through the time period using the same constraints as the strategy. Basically this is a way of not mixing species of fruit and seeing what the distribution of luck is for the particular fruit ...


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-...


9

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

High VIX arguably leads to less predictability of the market factor (i.e. market timing), but high volatility does lead to greater predictability of the cross-section of returns. Indeed, linear risk factor models have higher explanatory power during bear markets. However, your goal is to build a better market timing model where the forecasts (and perhaps ...


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

This is a partial explanation in that trading strategies with longer horizons have higher information ratios, t-statistics, slope coefficients, and R^2 in general. In other words, if information ratios for both strategies are identical then the longer-term trading strategy is already worse. John Cochrane illustrates how longer horizons have higher t-stats ...


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

There is a huge difference between R (and Matlab, SAS, or other statistical languages) and relatively low-level languages such as C/C++/C#/Java in exactly this regard. The latter category is used more often for stable end-products, where speed and performance can be crucial, whereas the former category is used more often for model testing and prototyping. ...


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

I think the way to see the real effect in a backtest is to produce the distribution achieved with zero skill. You can get one point from this distribution by starting with the same initial portfolio, then do random trading through the time period conditional on obeying the same set of constraints. Do that several times to get the approximate distribution. ...


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 ...


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