26

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


15

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


12

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


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


9

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

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


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


7

I will be glad to help, but let me first advise you away from working on this topic until you have an academic position. This topic has been poison for me, but I am slogging on anyways. Before you use anything I do, get permission from your academic advisor. I have an unpublished article on options pricing, and I am proposing a new branch of stochastic ...


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


6

How can a trading strategy that happened to perform well in one sample path be guaranteed to perform as well out of sample? I think you are having it backwards - this is how I do it: Intuition about some economic, psychological, behavioral, technical etc. phenomenon. Trying to make my intuition precise in the form of a hypothesis. Trying to translate my ...


6

QuantConnect uses L1 data (bid and ask quotes) for its US Equities Backtesting. QuantConnect has a full break down of the data library, including free data for download in LEAN format at the data library page: https://www.quantconnect.com/data The open-source LEAN algorithmic trading engine can support trades and quotes, however, on QuantConnect website the ...


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


5

My understanding, in that context, is that signal indicates that you want to hold a share (signal is 1) or hold no shares (signal is zero). Therefore taking the diff will tell you if you want to buy (signal zero to 1, diff is 1), sell (signal 1 to zero, diff is -1) or do nothing (signal stays at zero or stays at 1, diff is zero).


5

The problem you describe isn't trivial. Mainly because once you have it solved for all current known cases someone will figure out a way to do something different and mess up your system. Here are some approaches that I have seen somewhat successfully used. I won't claim they will give you complete coverage of every case, but they may give you some ideas to ...


4

There is one more solution available now to backtest option strategies: www.oscreener.com! This tool allows to screen and backtest bull put spreads, long calls, short puts, debit spreads etc and validate these strategies in seconds.


4

Having developed many custom backtesting programs in the past, I wish I would have just started out by purchasing a decent commercial backtester for a few hundred dollars. The cost of buying one already completed will save you hours of time on learning the nuances and problems that come with backtesting implementation. Once you are adept at the ins and outs ...


4

These are the libraries I most prominently use for C++: QuantLib Boost C++ Libraries This is not specifically a library however it is extremely helpful, the Anaconda Compiler Tools. The Armadillo C++ library for linear algebra & scientific computing. The Intel Math Kernel Library for C++ (MKL). The Ta_Lib Technical Analysis Library has an API for C/C++...


4

As explained in the comments best bid and best offer (best ask) are the best prices at which you can respectively sell and buy at least one unit of the asset your are considering. When backtesting a strategy, most people usually either use best bid and best offer or even worse last price. The problem is that these prices are only available for a limited ...


4

I do know of a largish prop shop that (as of 2009) had a deal with their prime broker to trade Nasdaq ETFs at the closing price, in size, so long as they gave a few hours' notice of order size and direction and never cancelled. After commissions and fees, the price was naturally worse. Generally speaking, you have to assume slippage, as mentioned by ...


4

There is a module called visualize-wealth that provides: Documentation auto-generation capability with sphinx Portfolio construction methodologies in 3 ways (trade blotter, weight allocation frame, and static allocation series) All basic statistical measures, including many sophisticated ones such as CVaR, Mean Absolute Tracking Error, Cornish Fisher ...


4

Interactive Brokers hosted a webinar on Nov. 10 2016 about Implement Algo Trading coded in Python using Interactive Brokers API. The presenter gave a good explanation on the applicability of IBridgePy, which is a Python package used to connect to Interactive Brokers C++ API for execution of python codes in live markets. The webinar was recorded so that you ...


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