rs-backtester
rs-backtester is a financial backtesting library written entirely in Rust with the purpose of being easy-to-use yet flexible enough to allow a quick implementation of different strategies
Install
- To install simply add rs-backtester to your cargo.toml
rs-backtester = "0.1.0"
Get started
To get started:
- Import the necessary modules:
use Error;
use Backtest;
use Data;
use ;
- Define an instance of the Data class. Market data can be retrieved either through yahoo-finance or read from a CSV file (OHLC format, Volume is not uploaded)
let quotes = load?;
- As an alternative, you can retrieve data directly from yahoo finance with the following which makes use of the crate yahoo-finance-api
let quotes = new_from_yahoo?;
- Create a function which returns a Strategy or use one provided by the library. A Strategy is basically a vector of Choices (e.g. BUY, SHORTSELL, ...) and the indicator used
let sma_cross_strategy = sma_cross;
- Create an instance of the Backtest class
let sma_cross_tester = new;
- Now:
- you can read a report of the backtest
report; - you can produce a log period by period with the requested parameter
sma_cross_tester.log; - you can chart it (with indicators)
plot?;
- you can save it to CSV for inspection
sma_cross_tester.to_csv?; - you can also compare multiple strategies at once
- you can read a report of the backtest