Skip to content

Coding: Backtesting

Robin Drew edited this page Jun 30, 2018 · 5 revisions

Backtesting is an essential part of algorithmic trading. This particular part of the project is under continuous development and is evolving rapidly. I have built a backtesting framework to simplify the process, however there are two parts that you will need to prepare/write yourself:

  1. Price Data Files
  2. Trading Strategy

Although you can not perform any backtesting without historic price data to test against, sourcing it is relatively straight forward. Importantly though you will need to the strategy to be backtested. There are a few simplistic strategies included in the api to get you started, but do not use them to trade with!

Simple Example

BacktestContextBuilder builder = new BacktestContextBuilder();
builder.setDataDirectory("c:/temp/data/"); // Set the root data directory from which historic price data will be sourced
builder.setProvider(TradingProvider.FXCM); // Select the data provider we want to use
builder.setInstrument(Instruments.EUR_USD); // Select the instrument we will be trading
BacktestContext context = builder.build(); // Build the context from these options

// Get the implementation of the ITradingPlatform we can use to trade with
BacktestTradingPlatform platform = context.getPlatform();

// Register the strategy with the price stream
IBacktestStreamingService streaming = platform.getStreamingService();
IBacktestInstrumentPriceStream priceStream = streaming.getPriceStream(instrument);
priceStream.register(new SimpleVolatilityStrategy(platform, instrument));

// Run the price stream, which pushes prices in to the strategy ....
priceStream.run();

N.B. This is all you need to get started backtesting, but you need the historic data and to write a strategy first!

Clone this wiki locally