investing-algorithm-framework 3.4.3__tar.gz → 3.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/PKG-INFO +46 -32
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/README.md +45 -31
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/app.py +79 -52
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/stateless/action_handlers/check_online_handler.py +1 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/controllers/orders.py +3 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/schemas/position.py +1 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/__init__.py +17 -17
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/backtesting/backtest_report.py +3 -2
- investing_algorithm_framework-3.5.0/investing_algorithm_framework/domain/models/backtesting/backtest_reports_evaluation.py +66 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/order/order.py +6 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/trade/trade.py +6 -4
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/services/market_service.py +3 -1
- investing_algorithm_framework-3.5.0/investing_algorithm_framework/domain/utils/backtesting.py +490 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py +12 -12
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/repositories/order_repository.py +3 -4
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/services/performance_service/performance_service.py +1 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/backtesting/backtest_report_writer_service.py +10 -5
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/backtesting/backtest_service.py +3 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/market_credential_service.py +1 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/market_data_source_service/backtest_market_data_source_service.py +1 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/market_data_source_service/market_data_source_service.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/order_service/order_service.py +2 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/portfolios/__init__.py +3 -4
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/portfolios/portfolio_sync_service.py +1 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/strategy_orchestrator_service.py +3 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/pyproject.toml +1 -1
- investing_algorithm_framework-3.4.3/investing_algorithm_framework/domain/models/backtesting/backtest_reports_evaluation.py +0 -21
- investing_algorithm_framework-3.4.3/investing_algorithm_framework/domain/utils/backtesting.py +0 -283
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/LICENSE +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/__init__.py +3 -3
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/__init__.py +2 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/algorithm.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/stateless/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/stateless/action_handlers/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/stateless/action_handlers/action_handler_strategy.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/stateless/action_handlers/run_strategy_handler.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/stateless/exception_handler.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/strategy.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/task.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/controllers/__init__.py +2 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/controllers/portfolio.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/controllers/positions.py +2 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/create_app.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/error_handler.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/responses.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/run_strategies.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/schemas/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/schemas/order.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/schemas/portfolio.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/app/web/setup_cors.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/create_app.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/dependency_container.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/config.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/constants.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/data_structures.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/decimal_parsing.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/exceptions.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/__init__.py +8 -8
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/app_mode.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/backtesting/__init__.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/backtesting/backtest_position.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/base_model.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/market/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/market/market_credential.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/order/__init__.py +3 -3
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/order/order_fee.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/order/order_side.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/order/order_status.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/order/order_type.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/portfolio/__init__.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/portfolio/portfolio.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/position/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/position/position.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/position/position_snapshot.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/strategy_profile.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/time_frame.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/time_interval.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/time_unit.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/trade/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/trade/trade_status.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/trading_data_types.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/models/trading_time_frame.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/services/__init__.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/services/market_credential_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/services/market_data_sources.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/services/portfolios/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/services/portfolios/portfolio_sync_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/services/rounding_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/singleton.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/stateless_actions.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/strategy.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/utils/__init__.py +4 -4
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/utils/csv.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/utils/random.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/utils/signatures.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/utils/stoppable_thread.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/domain/utils/synchronized.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/__init__.py +4 -4
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/database/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/database/sql_alchemy.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/__init__.py +3 -3
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/decimal_parser.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/market_data_sources/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py +2 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/model_extension.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/order/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/order/order.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/order/order_fee.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/position/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/position/position.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/models/position/position_snapshot.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/repositories/__init__.py +3 -3
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/repositories/order_fee_repository.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/repositories/portfolio_snapshot_repository.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/repositories/position_repository.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/repositories/position_snapshot_repository.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/repositories/repository.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/services/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/services/market_service/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/services/performance_service/__init__.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/infrastructure/services/performance_service/backtest_performance_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/backtesting/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/configuration_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/market_data_source_service/__init__.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/order_service/__init__.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/order_service/order_backtest_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/portfolios/backtest_portfolio_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/portfolios/portfolio_configuration_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/portfolios/portfolio_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/portfolios/portfolio_snapshot_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/position_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/position_snapshot_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/repository_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/trade_service/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.0}/investing_algorithm_framework/services/trade_service/trade_service.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: investing-algorithm-framework
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.5.0
|
|
4
4
|
Summary: A framework for creating trading bots
|
|
5
5
|
Author: MDUYN
|
|
6
6
|
Requires-Python: >=3.8.1,<4.0.0
|
|
@@ -166,52 +166,66 @@ For example if you run the [moving average example trading bot](./examples/cross
|
|
|
166
166
|
you will get the following backtesting report:
|
|
167
167
|
|
|
168
168
|
```bash
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
169
|
+
|
|
170
|
+
/&# #&( Backtest report
|
|
171
|
+
&&&&&&&&&&&# &&&&&&&&&&&& ---------------------------
|
|
172
|
+
&&&&&&&&&&&&&&&& (&&&&&&&&&&&&&&& Start date: 2023-08-24 00:00:00
|
|
173
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& End date: 2023-12-02 00:00:00
|
|
174
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Number of days: 100
|
|
175
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Number of runs: 1201
|
|
176
|
+
.&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Number of orders: 10
|
|
177
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&. Initial balance: 400.0
|
|
178
|
+
&&&&&&&# /((( &&&&&&&&&&&&*((( .&&&&&&&. Final balance: 431.1499
|
|
179
|
+
&&&&&&&&&&&&&&&&&&& (((( &&&&&&&& (((( &&&&&&&&&&&&&&&&&&& Total net gain: 28.5542 7.139%
|
|
180
|
+
(((&&&&&&&& (((( &&&&&& (((( &&&&&&&&&(( Growth: 31.1499 7.787%
|
|
181
|
+
/((((((((((&&&&&&&&&& (((, &&&&&& (((**&&&&&&&&&((((((((((( Number of trades closed: 4
|
|
182
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Number of trades open(end of backtest): 2
|
|
183
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Percentage positive trades: 60.0%
|
|
184
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Percentage negative trades: 20.0%
|
|
185
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&( Average trade size: 98.9886 EUR
|
|
186
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&, Average trade duration: 184.0 hours
|
|
187
|
+
((((( &&&&&&&&&&&&&#
|
|
188
|
+
((((( #&&&&&&&&&&###
|
|
189
|
+
((((( &&&&&&&&&&&###.
|
|
190
|
+
.((((( &&&&&&&&&&&&&&###(
|
|
191
|
+
((((( &&&&&&&&&&&&&&&&#(((/
|
|
192
|
+
((((( &&&&&&&&&&&&&&&&&&&@((((
|
|
193
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&((((
|
|
194
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&((((,
|
|
195
|
+
.((((( &&&&&&&&&&&&&&&&&&&&&&&&&&((((
|
|
196
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&((((
|
|
197
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&&((((
|
|
198
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&((((
|
|
199
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&&#((((
|
|
200
|
+
(((((((((((((((((((#########&&&&&&&&&&&&&&&&&&&&&&&&&&&&(((((
|
|
201
|
+
(((((((((((((((((((((######&&&&&&&&&&&&&&&&&&&&&&&&&&&&((((
|
|
202
|
+
|
|
203
|
+
Positions overview
|
|
183
204
|
╭────────────┬──────────┬──────────────────────┬───────────────────────┬──────────────┬───────────────┬───────────────────────────┬────────────────┬───────────────╮
|
|
184
205
|
│ Position │ Amount │ Pending buy amount │ Pending sell amount │ Cost (EUR) │ Value (EUR) │ Percentage of portfolio │ Growth (EUR) │ Growth_rate │
|
|
185
206
|
├────────────┼──────────┼──────────────────────┼───────────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
|
|
186
|
-
│ EUR │
|
|
207
|
+
│ EUR │ 217.044 │ 0 │ 0 │ 217.044 │ 217.044 │ 50.3407% │ 0 │ 0.0000% │
|
|
187
208
|
├────────────┼──────────┼──────────────────────┼───────────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
|
|
188
|
-
│ BTC │ 0.
|
|
209
|
+
│ BTC │ 0.003 │ 0 │ 0 │ 104.372 │ 106.84 │ 24.7802% │ 2.4678 │ 2.3644% │
|
|
189
210
|
├────────────┼──────────┼──────────────────────┼───────────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
|
|
190
|
-
│ DOT │ 21.
|
|
211
|
+
│ DOT │ 21.3295 │ 0 │ 0 │ 107.138 │ 107.266 │ 24.8791% │ 0.128 │ 0.1195% │
|
|
191
212
|
╰────────────┴──────────┴──────────────────────┴───────────────────────┴──────────────┴───────────────┴───────────────────────────┴────────────────┴───────────────╯
|
|
192
|
-
|
|
193
|
-
* Number of trades closed: 4
|
|
194
|
-
* Number of trades open: 2
|
|
195
|
-
* Percentage of positive trades: 60.0%
|
|
196
|
-
* Percentage of negative trades: 20.0%
|
|
197
|
-
* Average trade size: 98.8728 EUR
|
|
198
|
-
* Average trade duration: 183.5 hours
|
|
213
|
+
Trades overview
|
|
199
214
|
╭─────────┬─────────────────────┬─────────────────────┬────────────────────┬──────────────┬──────────────────┬───────────────────────┬────────────────────┬─────────────────────╮
|
|
200
215
|
│ Pair │ Open date │ Close date │ Duration (hours) │ Size (EUR) │ Net gain (EUR) │ Net gain percentage │ Open price (EUR) │ Close price (EUR) │
|
|
201
216
|
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
|
|
202
|
-
│ DOT-EUR │ 2023-11-30
|
|
217
|
+
│ DOT-EUR │ 2023-11-30 18:00:00 │ │ 3207.26 │ 107.138 │ 0 │ 0.0000% │ 5.023 │ │
|
|
203
218
|
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
|
|
204
|
-
│ BTC-EUR │ 2023-11-29
|
|
219
|
+
│ BTC-EUR │ 2023-11-29 12:00:00 │ │ 3237.26 │ 104.372 │ 0 │ 0.0000% │ 34790.7 │ │
|
|
205
220
|
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
|
|
206
|
-
│ BTC-EUR │ 2023-11-
|
|
221
|
+
│ BTC-EUR │ 2023-11-07 22:00:00 │ 2023-11-14 14:00:00 │ 160 │ 99.2337 │ 2.5395 │ 2.5591% │ 33077.9 │ 33924.4 │
|
|
207
222
|
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
|
|
208
|
-
│ BTC-EUR │ 2023-11-06
|
|
223
|
+
│ BTC-EUR │ 2023-11-06 14:00:00 │ 2023-11-06 18:00:00 │ 4 │ 98.2854 │ -0.4248 │ -0.4322% │ 32761.8 │ 32620.2 │
|
|
209
224
|
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
|
|
210
|
-
│ DOT-EUR │ 2023-10-30
|
|
225
|
+
│ DOT-EUR │ 2023-10-30 04:00:00 │ 2023-11-14 00:00:00 │ 356 │ 100.537 │ 24.2886 │ 24.1588% │ 4.0565 │ 5.0365 │
|
|
211
226
|
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
|
|
212
|
-
│ BTC-EUR │ 2023-09-13
|
|
227
|
+
│ BTC-EUR │ 2023-09-13 14:00:00 │ 2023-09-22 14:00:00 │ 216 │ 97.8976 │ 2.1508 │ 2.1970% │ 24474.4 │ 25012.1 │
|
|
213
228
|
╰─────────┴─────────────────────┴─────────────────────┴────────────────────┴──────────────┴──────────────────┴───────────────────────┴────────────────────┴─────────────────────╯
|
|
214
|
-
==================================================================
|
|
215
229
|
```
|
|
216
230
|
|
|
217
231
|
### Backtest experiments
|
|
@@ -139,52 +139,66 @@ For example if you run the [moving average example trading bot](./examples/cross
|
|
|
139
139
|
you will get the following backtesting report:
|
|
140
140
|
|
|
141
141
|
```bash
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
142
|
+
|
|
143
|
+
/&# #&( Backtest report
|
|
144
|
+
&&&&&&&&&&&# &&&&&&&&&&&& ---------------------------
|
|
145
|
+
&&&&&&&&&&&&&&&& (&&&&&&&&&&&&&&& Start date: 2023-08-24 00:00:00
|
|
146
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& End date: 2023-12-02 00:00:00
|
|
147
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Number of days: 100
|
|
148
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Number of runs: 1201
|
|
149
|
+
.&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Number of orders: 10
|
|
150
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&. Initial balance: 400.0
|
|
151
|
+
&&&&&&&# /((( &&&&&&&&&&&&*((( .&&&&&&&. Final balance: 431.1499
|
|
152
|
+
&&&&&&&&&&&&&&&&&&& (((( &&&&&&&& (((( &&&&&&&&&&&&&&&&&&& Total net gain: 28.5542 7.139%
|
|
153
|
+
(((&&&&&&&& (((( &&&&&& (((( &&&&&&&&&(( Growth: 31.1499 7.787%
|
|
154
|
+
/((((((((((&&&&&&&&&& (((, &&&&&& (((**&&&&&&&&&((((((((((( Number of trades closed: 4
|
|
155
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Number of trades open(end of backtest): 2
|
|
156
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Percentage positive trades: 60.0%
|
|
157
|
+
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Percentage negative trades: 20.0%
|
|
158
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&( Average trade size: 98.9886 EUR
|
|
159
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&, Average trade duration: 184.0 hours
|
|
160
|
+
((((( &&&&&&&&&&&&&#
|
|
161
|
+
((((( #&&&&&&&&&&###
|
|
162
|
+
((((( &&&&&&&&&&&###.
|
|
163
|
+
.((((( &&&&&&&&&&&&&&###(
|
|
164
|
+
((((( &&&&&&&&&&&&&&&&#(((/
|
|
165
|
+
((((( &&&&&&&&&&&&&&&&&&&@((((
|
|
166
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&((((
|
|
167
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&((((,
|
|
168
|
+
.((((( &&&&&&&&&&&&&&&&&&&&&&&&&&((((
|
|
169
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&((((
|
|
170
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&&((((
|
|
171
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&((((
|
|
172
|
+
((((( &&&&&&&&&&&&&&&&&&&&&&&&&&&&&#((((
|
|
173
|
+
(((((((((((((((((((#########&&&&&&&&&&&&&&&&&&&&&&&&&&&&(((((
|
|
174
|
+
(((((((((((((((((((((######&&&&&&&&&&&&&&&&&&&&&&&&&&&&((((
|
|
175
|
+
|
|
176
|
+
Positions overview
|
|
156
177
|
╭────────────┬──────────┬──────────────────────┬───────────────────────┬──────────────┬───────────────┬───────────────────────────┬────────────────┬───────────────╮
|
|
157
178
|
│ Position │ Amount │ Pending buy amount │ Pending sell amount │ Cost (EUR) │ Value (EUR) │ Percentage of portfolio │ Growth (EUR) │ Growth_rate │
|
|
158
179
|
├────────────┼──────────┼──────────────────────┼───────────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
|
|
159
|
-
│ EUR │
|
|
180
|
+
│ EUR │ 217.044 │ 0 │ 0 │ 217.044 │ 217.044 │ 50.3407% │ 0 │ 0.0000% │
|
|
160
181
|
├────────────┼──────────┼──────────────────────┼───────────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
|
|
161
|
-
│ BTC │ 0.
|
|
182
|
+
│ BTC │ 0.003 │ 0 │ 0 │ 104.372 │ 106.84 │ 24.7802% │ 2.4678 │ 2.3644% │
|
|
162
183
|
├────────────┼──────────┼──────────────────────┼───────────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
|
|
163
|
-
│ DOT │ 21.
|
|
184
|
+
│ DOT │ 21.3295 │ 0 │ 0 │ 107.138 │ 107.266 │ 24.8791% │ 0.128 │ 0.1195% │
|
|
164
185
|
╰────────────┴──────────┴──────────────────────┴───────────────────────┴──────────────┴───────────────┴───────────────────────────┴────────────────┴───────────────╯
|
|
165
|
-
|
|
166
|
-
* Number of trades closed: 4
|
|
167
|
-
* Number of trades open: 2
|
|
168
|
-
* Percentage of positive trades: 60.0%
|
|
169
|
-
* Percentage of negative trades: 20.0%
|
|
170
|
-
* Average trade size: 98.8728 EUR
|
|
171
|
-
* Average trade duration: 183.5 hours
|
|
186
|
+
Trades overview
|
|
172
187
|
╭─────────┬─────────────────────┬─────────────────────┬────────────────────┬──────────────┬──────────────────┬───────────────────────┬────────────────────┬─────────────────────╮
|
|
173
188
|
│ Pair │ Open date │ Close date │ Duration (hours) │ Size (EUR) │ Net gain (EUR) │ Net gain percentage │ Open price (EUR) │ Close price (EUR) │
|
|
174
189
|
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
|
|
175
|
-
│ DOT-EUR │ 2023-11-30
|
|
190
|
+
│ DOT-EUR │ 2023-11-30 18:00:00 │ │ 3207.26 │ 107.138 │ 0 │ 0.0000% │ 5.023 │ │
|
|
176
191
|
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
|
|
177
|
-
│ BTC-EUR │ 2023-11-29
|
|
192
|
+
│ BTC-EUR │ 2023-11-29 12:00:00 │ │ 3237.26 │ 104.372 │ 0 │ 0.0000% │ 34790.7 │ │
|
|
178
193
|
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
|
|
179
|
-
│ BTC-EUR │ 2023-11-
|
|
194
|
+
│ BTC-EUR │ 2023-11-07 22:00:00 │ 2023-11-14 14:00:00 │ 160 │ 99.2337 │ 2.5395 │ 2.5591% │ 33077.9 │ 33924.4 │
|
|
180
195
|
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
|
|
181
|
-
│ BTC-EUR │ 2023-11-06
|
|
196
|
+
│ BTC-EUR │ 2023-11-06 14:00:00 │ 2023-11-06 18:00:00 │ 4 │ 98.2854 │ -0.4248 │ -0.4322% │ 32761.8 │ 32620.2 │
|
|
182
197
|
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
|
|
183
|
-
│ DOT-EUR │ 2023-10-30
|
|
198
|
+
│ DOT-EUR │ 2023-10-30 04:00:00 │ 2023-11-14 00:00:00 │ 356 │ 100.537 │ 24.2886 │ 24.1588% │ 4.0565 │ 5.0365 │
|
|
184
199
|
├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
|
|
185
|
-
│ BTC-EUR │ 2023-09-13
|
|
200
|
+
│ BTC-EUR │ 2023-09-13 14:00:00 │ 2023-09-22 14:00:00 │ 216 │ 97.8976 │ 2.1508 │ 2.1970% │ 24474.4 │ 25012.1 │
|
|
186
201
|
╰─────────┴─────────────────────┴─────────────────────┴────────────────────┴──────────────┴──────────────────┴───────────────────────┴────────────────────┴─────────────────────╯
|
|
187
|
-
==================================================================
|
|
188
202
|
```
|
|
189
203
|
|
|
190
204
|
### Backtest experiments
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import inspect
|
|
1
2
|
import logging
|
|
2
3
|
import os
|
|
3
4
|
import shutil
|
|
4
5
|
import threading
|
|
6
|
+
from abc import abstractmethod
|
|
5
7
|
from datetime import datetime
|
|
6
8
|
from distutils.sysconfig import get_python_lib
|
|
7
9
|
from time import sleep
|
|
8
|
-
from typing import List
|
|
9
|
-
import inspect
|
|
10
|
+
from typing import List, Optional, Tuple
|
|
10
11
|
|
|
11
|
-
from abc import abstractmethod
|
|
12
12
|
from flask import Flask
|
|
13
13
|
|
|
14
14
|
from investing_algorithm_framework.app.algorithm import Algorithm
|
|
@@ -28,6 +28,9 @@ from investing_algorithm_framework.services import OrderBacktestService, \
|
|
|
28
28
|
MarketDataSourceService, MarketCredentialService
|
|
29
29
|
|
|
30
30
|
logger = logging.getLogger("investing_algorithm_framework")
|
|
31
|
+
COLOR_RESET = '\033[0m'
|
|
32
|
+
COLOR_GREEN = '\033[92m'
|
|
33
|
+
COLOR_YELLOW = '\033[93m'
|
|
31
34
|
|
|
32
35
|
|
|
33
36
|
class AppHook:
|
|
@@ -236,7 +239,8 @@ class App:
|
|
|
236
239
|
self,
|
|
237
240
|
backtest_start_date,
|
|
238
241
|
backtest_end_date,
|
|
239
|
-
pending_order_check_interval
|
|
242
|
+
pending_order_check_interval,
|
|
243
|
+
market_data_sources,
|
|
240
244
|
) -> None:
|
|
241
245
|
"""
|
|
242
246
|
Initialize the app for backtesting by setting the configuration
|
|
@@ -267,12 +271,6 @@ class App:
|
|
|
267
271
|
# Override the MarketDataSourceService service with the backtest
|
|
268
272
|
# market data source service equivalent. Additionally, convert the
|
|
269
273
|
# market data sources to backtest market data sources
|
|
270
|
-
# market_data_sources = self.get_market_data_sources()
|
|
271
|
-
# backtest_market_data_sources = []
|
|
272
|
-
market_data_source_service: MarketDataSourceService = \
|
|
273
|
-
self.container.market_data_source_service()
|
|
274
|
-
market_data_sources = market_data_source_service \
|
|
275
|
-
.get_market_data_sources()
|
|
276
274
|
|
|
277
275
|
if market_data_sources is not None:
|
|
278
276
|
backtest_market_data_sources = [
|
|
@@ -435,10 +433,10 @@ class App:
|
|
|
435
433
|
shutil.copy(management_commands_template, destination)
|
|
436
434
|
|
|
437
435
|
def run(
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
436
|
+
self,
|
|
437
|
+
payload: dict = None,
|
|
438
|
+
number_of_iterations: int = None,
|
|
439
|
+
sync=False
|
|
442
440
|
):
|
|
443
441
|
"""
|
|
444
442
|
Entry point to run the application. This method should be called to
|
|
@@ -673,12 +671,12 @@ class App:
|
|
|
673
671
|
return self.algorithm.get_portfolio_configurations()
|
|
674
672
|
|
|
675
673
|
def run_backtest(
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
674
|
+
self,
|
|
675
|
+
algorithm,
|
|
676
|
+
start_date,
|
|
677
|
+
end_date,
|
|
678
|
+
pending_order_check_interval='1h',
|
|
679
|
+
output_directory=None
|
|
682
680
|
) -> BacktestReport:
|
|
683
681
|
"""
|
|
684
682
|
Run a backtest for an algorithm. This method should be called when
|
|
@@ -699,10 +697,14 @@ class App:
|
|
|
699
697
|
if end_date is None:
|
|
700
698
|
end_date = datetime.utcnow()
|
|
701
699
|
|
|
700
|
+
market_data_sources = self._market_data_source_service\
|
|
701
|
+
.get_market_data_sources()
|
|
702
|
+
|
|
702
703
|
self._initialize_app_for_backtest(
|
|
703
704
|
backtest_start_date=start_date,
|
|
704
705
|
backtest_end_date=end_date,
|
|
705
|
-
pending_order_check_interval=pending_order_check_interval
|
|
706
|
+
pending_order_check_interval=pending_order_check_interval,
|
|
707
|
+
market_data_sources=market_data_sources
|
|
706
708
|
)
|
|
707
709
|
|
|
708
710
|
self._initialize_algorithm_for_backtest(
|
|
@@ -733,12 +735,13 @@ class App:
|
|
|
733
735
|
return report
|
|
734
736
|
|
|
735
737
|
def run_backtests(
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
738
|
+
self,
|
|
739
|
+
algorithms,
|
|
740
|
+
start_date: Optional[datetime] = None,
|
|
741
|
+
end_date: Optional[datetime] = None,
|
|
742
|
+
date_ranges: Optional[Tuple[datetime, datetime]] = None,
|
|
743
|
+
pending_order_check_interval='1h',
|
|
744
|
+
output_directory=None
|
|
742
745
|
) -> List[BacktestReport]:
|
|
743
746
|
"""
|
|
744
747
|
Run a backtest for a set algorithm. This method should be called when
|
|
@@ -749,6 +752,8 @@ class App:
|
|
|
749
752
|
:param start_date: The start date of the backtest
|
|
750
753
|
:param end_date: The end date of the backtest
|
|
751
754
|
:param pending_order_check_interval: The interval at which to check
|
|
755
|
+
:param date_ranges: The date ranges to run the backtests for (list of
|
|
756
|
+
tuples of start and end dates)
|
|
752
757
|
pending orders
|
|
753
758
|
:param output_directory: The directory to write the backtest report to
|
|
754
759
|
:return: List of BacktestReport intances
|
|
@@ -756,39 +761,61 @@ class App:
|
|
|
756
761
|
logger.info("Initializing backtests")
|
|
757
762
|
reports = []
|
|
758
763
|
|
|
759
|
-
if
|
|
760
|
-
end_date = datetime.utcnow()
|
|
764
|
+
if start_date is not None:
|
|
761
765
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
backtest_end_date=end_date,
|
|
765
|
-
pending_order_check_interval=pending_order_check_interval
|
|
766
|
-
)
|
|
766
|
+
if end_date is None:
|
|
767
|
+
end_date = datetime.utcnow()
|
|
767
768
|
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
769
|
+
date_ranges = [(start_date, end_date)]
|
|
770
|
+
else:
|
|
771
|
+
if date_ranges is None:
|
|
772
|
+
raise OperationalException("No date ranges specified")
|
|
773
|
+
|
|
774
|
+
market_data_sources = self._market_data_source_service\
|
|
775
|
+
.get_market_data_sources()
|
|
776
|
+
|
|
777
|
+
for date_range in date_ranges:
|
|
778
|
+
start_date, end_date = date_range
|
|
779
|
+
self._initialize_app_for_backtest(
|
|
780
|
+
backtest_start_date=start_date,
|
|
781
|
+
backtest_end_date=end_date,
|
|
782
|
+
pending_order_check_interval=pending_order_check_interval,
|
|
783
|
+
market_data_sources=market_data_sources
|
|
773
784
|
)
|
|
774
785
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
786
|
+
print(
|
|
787
|
+
f"{COLOR_YELLOW}Running backtests for date "
|
|
788
|
+
f"range:{COLOR_RESET} {COLOR_GREEN}{start_date} - "
|
|
789
|
+
f"{end_date} for a "
|
|
790
|
+
f"total of {len(algorithms)} algorithms.{COLOR_RESET}"
|
|
778
791
|
)
|
|
779
|
-
|
|
780
|
-
.
|
|
792
|
+
for algorithm in algorithms:
|
|
793
|
+
self._initialize_algorithm_for_backtest(algorithm)
|
|
794
|
+
backtest_service = self.container.backtest_service()
|
|
795
|
+
backtest_service.resource_directory = self.config.get(
|
|
796
|
+
RESOURCE_DIRECTORY
|
|
797
|
+
)
|
|
781
798
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
799
|
+
# Run the backtest with the backtest_service
|
|
800
|
+
# and collect the report
|
|
801
|
+
report = backtest_service.run_backtest(
|
|
802
|
+
algorithm=algorithm,
|
|
803
|
+
start_date=start_date,
|
|
804
|
+
end_date=end_date
|
|
786
805
|
)
|
|
806
|
+
backtest_report_writer_service = self.container \
|
|
807
|
+
.backtest_report_writer_service()
|
|
787
808
|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
809
|
+
if output_directory is None:
|
|
810
|
+
output_directory = os.path.join(
|
|
811
|
+
self.config.get(RESOURCE_DIRECTORY),
|
|
812
|
+
"backtest_reports"
|
|
813
|
+
)
|
|
814
|
+
|
|
815
|
+
backtest_report_writer_service.write_report_to_csv(
|
|
816
|
+
report=report, output_directory=output_directory
|
|
817
|
+
)
|
|
818
|
+
reports.append(report)
|
|
792
819
|
|
|
793
820
|
return reports
|
|
794
821
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
|
|
3
|
-
from flask import Blueprint, request
|
|
4
3
|
from dependency_injector.wiring import inject, Provide
|
|
5
|
-
from
|
|
4
|
+
from flask import Blueprint, request
|
|
5
|
+
|
|
6
6
|
from investing_algorithm_framework.app.web.responses import create_response
|
|
7
|
+
from investing_algorithm_framework.app.web.schemas import OrderSerializer
|
|
7
8
|
from investing_algorithm_framework.dependency_container import \
|
|
8
9
|
DependencyContainer
|
|
9
10
|
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
from .config import Config, Environment
|
|
2
|
-
from .models import OrderStatus, OrderSide, OrderType, TimeInterval, \
|
|
3
|
-
TimeUnit, TimeFrame, TradingTimeFrame, TradingDataType, \
|
|
4
|
-
PortfolioConfiguration, Portfolio, Position, Order, TradeStatus, \
|
|
5
|
-
OrderFee, BacktestReport, PortfolioSnapshot, StrategyProfile, \
|
|
6
|
-
BacktestPosition, Trade, MarketCredential, PositionSnapshot, \
|
|
7
|
-
BacktestReportsEvaluation, AppMode
|
|
8
|
-
from .exceptions import OperationalException, ApiException, \
|
|
9
|
-
PermissionDeniedApiException, ImproperlyConfigured
|
|
10
2
|
from .constants import ITEMIZE, ITEMIZED, PER_PAGE, PAGE, ENVIRONMENT, \
|
|
11
3
|
DATABASE_DIRECTORY_PATH, DATABASE_NAME, DEFAULT_PER_PAGE_VALUE, \
|
|
12
4
|
DEFAULT_PAGE_VALUE, SQLALCHEMY_DATABASE_URI, RESOURCE_DIRECTORY, \
|
|
13
5
|
DATETIME_FORMAT, DATETIME_FORMAT_BACKTESTING, BACKTESTING_FLAG, \
|
|
14
6
|
BACKTESTING_INDEX_DATETIME, BACKTESTING_START_DATE, CCXT_DATETIME_FORMAT, \
|
|
15
7
|
BACKTEST_DATA_DIRECTORY_NAME, TICKER_DATA_TYPE, OHLCV_DATA_TYPE, \
|
|
16
|
-
CURRENT_UTC_DATETIME, BACKTESTING_END_DATE,
|
|
8
|
+
CURRENT_UTC_DATETIME, BACKTESTING_END_DATE, SYMBOLS, \
|
|
17
9
|
CCXT_DATETIME_FORMAT_WITH_TIMEZONE, RESERVED_BALANCES, \
|
|
18
10
|
BACKTESTING_PENDING_ORDER_CHECK_INTERVAL, APP_MODE
|
|
19
|
-
from .
|
|
20
|
-
from .utils import random_string, append_dict_as_row_to_csv, \
|
|
21
|
-
add_column_headers_to_csv, get_total_amount_of_rows, \
|
|
22
|
-
csv_to_list, StoppableThread, pretty_print_backtest_reports_evaluation, \
|
|
23
|
-
pretty_print_backtest, load_csv_into_dict, load_backtest_reports
|
|
24
|
-
from .strategy import Strategy
|
|
25
|
-
from .stateless_actions import StatelessActions
|
|
11
|
+
from .data_structures import PeekableQueue
|
|
26
12
|
from .decimal_parsing import parse_decimal_to_string, parse_string_to_decimal
|
|
13
|
+
from .exceptions import OperationalException, ApiException, \
|
|
14
|
+
PermissionDeniedApiException, ImproperlyConfigured
|
|
15
|
+
from .models import OrderStatus, OrderSide, OrderType, TimeInterval, \
|
|
16
|
+
TimeUnit, TimeFrame, TradingTimeFrame, TradingDataType, \
|
|
17
|
+
PortfolioConfiguration, Portfolio, Position, Order, TradeStatus, \
|
|
18
|
+
OrderFee, BacktestReport, PortfolioSnapshot, StrategyProfile, \
|
|
19
|
+
BacktestPosition, Trade, MarketCredential, PositionSnapshot, \
|
|
20
|
+
BacktestReportsEvaluation, AppMode
|
|
27
21
|
from .services import TickerMarketDataSource, OrderBookMarketDataSource, \
|
|
28
22
|
OHLCVMarketDataSource, BacktestMarketDataSource, MarketDataSource, \
|
|
29
23
|
MarketService, MarketCredentialService, AbstractPortfolioSyncService, \
|
|
30
24
|
RoundingService
|
|
31
|
-
from .
|
|
25
|
+
from .singleton import Singleton
|
|
26
|
+
from .stateless_actions import StatelessActions
|
|
27
|
+
from .strategy import Strategy
|
|
28
|
+
from .utils import random_string, append_dict_as_row_to_csv, \
|
|
29
|
+
add_column_headers_to_csv, get_total_amount_of_rows, \
|
|
30
|
+
csv_to_list, StoppableThread, pretty_print_backtest_reports_evaluation, \
|
|
31
|
+
pretty_print_backtest, load_csv_into_dict, load_backtest_reports
|
|
32
32
|
|
|
33
33
|
__all__ = [
|
|
34
34
|
'Config',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
+
|
|
2
3
|
from investing_algorithm_framework.domain.models.base_model import BaseModel
|
|
3
4
|
from investing_algorithm_framework.domain.models.time_unit import TimeUnit
|
|
4
5
|
|
|
@@ -213,7 +214,7 @@ class BacktestReport(BaseModel):
|
|
|
213
214
|
|
|
214
215
|
@property
|
|
215
216
|
def percentage_positive_trades(self):
|
|
216
|
-
return self._percentage_positive_trades
|
|
217
|
+
return float(self._percentage_positive_trades)
|
|
217
218
|
|
|
218
219
|
@percentage_positive_trades.setter
|
|
219
220
|
def percentage_positive_trades(self, value):
|
|
@@ -221,7 +222,7 @@ class BacktestReport(BaseModel):
|
|
|
221
222
|
|
|
222
223
|
@property
|
|
223
224
|
def percentage_negative_trades(self):
|
|
224
|
-
return self._percentage_negative_trades
|
|
225
|
+
return float(self._percentage_negative_trades)
|
|
225
226
|
|
|
226
227
|
@percentage_negative_trades.setter
|
|
227
228
|
def percentage_negative_trades(self, value):
|