A library for backtesting trading algorithms. BackTester can be used to test your trading algorithms against years of historic data with only a few lines of code. Quickly see if your algorithm has potential or if you need to iterate!
<dependency>
<groupId>io.github.samkelsey</groupId>
<artifactId>backtester</artifactId>
<version>${backtester.version}</version>
</dependency>
To use with the default testing data, you need only 4 lines of code. Do the following steps:
- Create an algorithm class that implements Algorithm. See ExampleAlgorithm for a basic example.
- Instantiate an instance of DataSourceImpl.
- Instantiate an instance of BackTester using your Algorithm and DataSource from steps 1 & 2.
- Call
backTester.run()
to kick-off the simulation. - View the results from the BrokerReader returned by the simulation!
Example
public class BackTesterExample {
public static void main(String[] args) throws BackTesterException, IOException {
Algorithm algorithm = new ExampleAlgorithm();
DataSource dataSource = new DataSourceImpl();
BackTester backTester = new BackTester(algorithm, dataSource);
BrokerReader broker = backTester.run();
broker.getPortfolio();
}
}
The above example will return a BrokerReader, as a result. With this, you can view the effectiveness of your trading algorithm by looking at the final state of your broker account! 😃
BackTester also allows for you to try out your own algorithms against your own datasets! For more information on how to do this, visit our documentation.