27
27
BacktestMarketDataSourceService , BacktestPortfolioService , \
28
28
BacktestService
29
29
from .app_hook import AppHook
30
- from .reporting import BacktestReport
31
30
32
31
logger = logging .getLogger ("investing_algorithm_framework" )
33
32
COLOR_RESET = '\033 [0m'
@@ -762,7 +761,7 @@ def run_backtest(
762
761
date and time.
763
762
764
763
Returns:
765
- Instance of BacktestReport
764
+ Backtest: Instance of Backtest
766
765
"""
767
766
768
767
# Add backtest configuration to the config
@@ -853,16 +852,18 @@ def run_backtest(
853
852
def run_backtests (
854
853
self ,
855
854
algorithms = None ,
856
- strategies = None ,
855
+ strategies : List [ TradingStrategy ] = None ,
857
856
initial_amount = None ,
858
857
backtest_date_ranges : List [BacktestDateRange ] = None ,
858
+ snapshot_interval : SnapshotInterval = SnapshotInterval .TRADE_CLOSE ,
859
+ risk_free_rate : Optional [float ] = None ,
860
+ save = True ,
859
861
output_directory = None ,
860
862
checkpoint = False ,
861
-
862
- ) -> List [BacktestReport ]:
863
+ ) -> List [Backtest ]:
863
864
"""
864
- Run a backtest for a set algorithm. This method should be called when
865
- running a backtest .
865
+ Run a set of backtests for the provided algorithms or strategies
866
+ with the given date ranges .
866
867
867
868
Args:
868
869
algorithms (List[Algorithm]) (Optional): The algorithms to run
@@ -885,14 +886,15 @@ def run_backtests(
885
886
when running backtests for a large number of algorithms
886
887
and date ranges where some of the backtests may fail
887
888
and you want to re-run only the failed backtests.
888
- save_strategy: bool - Whether to save the strategy as part
889
- of the backtest report. You can only save in-memory strategies
890
- when running multiple backtests. This is because we can't
891
- differentiate between which folders belong to a specific
892
- strategy.
889
+ save (bool): Whether to save the backtest report
890
+ to the output directory. If True, then the backtest report
891
+ will be saved to the output directory.
892
+ snapshot_interval (SnapshotInterval): The snapshot interval to
893
+ use for the backtest. This is used to determine how often
894
+ the portfolio snapshot should be taken during the backtest.
893
895
894
896
Returns
895
- List of BacktestReport instances
897
+ List[Backtest]: List of Backtest instances
896
898
"""
897
899
logger .info ("Initializing backtests" )
898
900
reports = []
@@ -959,6 +961,9 @@ def run_backtests(
959
961
initial_amount = initial_amount ,
960
962
output_directory = output_directory ,
961
963
algorithm = algorithm ,
964
+ save = save ,
965
+ snapshot_interval = snapshot_interval ,
966
+ risk_free_rate = risk_free_rate
962
967
)
963
968
reports .append (report )
964
969
0 commit comments