No description
Find a file
Luis Paulino ee87f2321c Refactor (#1)
Reviewed-on: #1
Co-authored-by: Luis Paulino <luis.manuel_20000@hotmail.com>
Co-committed-by: Luis Paulino <luis.manuel_20000@hotmail.com>
2025-12-10 20:33:27 +00:00
examples Add some explanations to faber_bt.jl example 2025-12-09 01:02:40 -05:00
strategies Refactor (#1) 2025-12-10 20:33:27 +00:00
.gitignore Update gitignore 2025-12-02 15:56:02 -05:00
backtest_framework.jl Refactor (#1) 2025-12-10 20:33:27 +00:00
backtest_structs.jl Refactor (#1) 2025-12-10 20:33:27 +00:00
LICENSE Initial commit 2025-12-02 19:18:10 +00:00
Project.toml Initial commit 2025-12-02 15:57:53 -05:00
README.md Refactor (#1) 2025-12-10 20:33:27 +00:00

Backtest

Backtest framework for trading algorithms.

Usage

  1. Create your strategies.

    • Create strategy_name.jl files that contain the algorithms to be executed at each step.

    • Strategies must take a ::backtest_structs.backtest_instance and a ::IOStream, plus any optional arguments that may be relevant. See strategies/faber_momentum.jl for an example. The strategy must return a ::Float every step, indicating the accrued P/L during the current step.

    • Strategies must interface with the framework through open_trade and close_trade functions.

      • close_trade and open_trade do 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}.
  2. Structure your backtest.

    • Create a ::strategy struct, 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 of etfs which has data files inside in_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.