- Julia 100%
Reviewed-on: #1 Co-authored-by: Luis Paulino <luis.manuel_20000@hotmail.com> Co-committed-by: Luis Paulino <luis.manuel_20000@hotmail.com> |
||
|---|---|---|
| examples | ||
| strategies | ||
| .gitignore | ||
| backtest_framework.jl | ||
| backtest_structs.jl | ||
| LICENSE | ||
| Project.toml | ||
| README.md | ||
Backtest
Backtest framework for trading algorithms.
Usage
-
Create your strategies.
-
Create
strategy_name.jlfiles that contain the algorithms to be executed at each step. -
Strategies must take a
::backtest_structs.backtest_instanceand a::IOStream, plus any optional arguments that may be relevant. See strategies/faber_momentum.jl for an example. The strategy must return a::Floatevery step, indicating the accrued P/L during the current step. -
Strategies must interface with the framework through
open_tradeandclose_tradefunctions.close_tradeandopen_tradedo not update any of the backtest information, instead they return relevant values that must be handled by your strategy. These values are:open_trade->Tuple{position::position_info, available_cash::Float64, equity::Float64.close_trade->Tuple{profit_loss::Float64, available_cash::Float64, equity::Float64}.
-
-
Structure your backtest.
-
Create a
::strategystruct, which contains the starting cash (::Float64), strategy (::Function), and optional arguments (::NamedTuple). -
The entry point will be
run_backtest(strategy::backtest_structs.strategy, file_out::String, in_dir::String, etfs::Vector{String}. It will run the strategy through every member ofetfswhich has data files insidein_dir. -
You can also save SVGs that plot equity over the the backtest with
plot_data(data::Vector{Float64}, filename::String; args) -
See examples/faber_bt.jl for more information.
-