investing-algorithm-framework 3.4.3__tar.gz → 3.5.1__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.1}/PKG-INFO +46 -32
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/README.md +45 -31
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/app.py +84 -56
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/stateless/action_handlers/check_online_handler.py +1 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/strategy.py +5 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/controllers/orders.py +3 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/schemas/position.py +1 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/__init__.py +17 -17
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/backtesting/backtest_report.py +3 -2
- investing_algorithm_framework-3.5.1/investing_algorithm_framework/domain/models/backtesting/backtest_reports_evaluation.py +66 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/order/order.py +6 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/trade/trade.py +6 -4
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/services/market_service.py +3 -1
- investing_algorithm_framework-3.5.1/investing_algorithm_framework/domain/utils/backtesting.py +490 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py +21 -14
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/repositories/order_repository.py +3 -4
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/services/performance_service/performance_service.py +1 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/backtesting/backtest_report_writer_service.py +10 -5
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/backtesting/backtest_service.py +4 -3
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/market_credential_service.py +1 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/market_data_source_service/backtest_market_data_source_service.py +7 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/market_data_source_service/market_data_source_service.py +17 -5
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/order_service/order_backtest_service.py +8 -4
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/order_service/order_service.py +2 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/portfolios/__init__.py +3 -4
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/portfolios/portfolio_sync_service.py +1 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/strategy_orchestrator_service.py +3 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/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.1}/LICENSE +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/__init__.py +3 -3
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/__init__.py +2 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/algorithm.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/stateless/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/stateless/action_handlers/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/stateless/action_handlers/action_handler_strategy.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/stateless/action_handlers/run_strategy_handler.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/stateless/exception_handler.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/task.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/controllers/__init__.py +2 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/controllers/portfolio.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/controllers/positions.py +2 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/create_app.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/error_handler.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/responses.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/run_strategies.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/schemas/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/schemas/order.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/schemas/portfolio.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/app/web/setup_cors.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/create_app.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/dependency_container.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/config.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/constants.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/data_structures.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/decimal_parsing.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/exceptions.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/__init__.py +8 -8
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/app_mode.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/backtesting/__init__.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/backtesting/backtest_position.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/base_model.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/market/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/market/market_credential.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/order/__init__.py +3 -3
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/order/order_fee.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/order/order_side.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/order/order_status.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/order/order_type.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/portfolio/__init__.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/portfolio/portfolio.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/position/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/position/position.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/position/position_snapshot.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/strategy_profile.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/time_frame.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/time_interval.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/time_unit.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/trade/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/trade/trade_status.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/trading_data_types.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/models/trading_time_frame.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/services/__init__.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/services/market_credential_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/services/market_data_sources.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/services/portfolios/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/services/portfolios/portfolio_sync_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/services/rounding_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/singleton.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/stateless_actions.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/strategy.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/utils/__init__.py +4 -4
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/utils/csv.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/utils/random.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/utils/signatures.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/utils/stoppable_thread.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/domain/utils/synchronized.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/__init__.py +4 -4
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/database/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/database/sql_alchemy.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/__init__.py +3 -3
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/decimal_parser.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/market_data_sources/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py +2 -2
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/model_extension.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/order/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/order/order.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/order/order_fee.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/position/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/position/position.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/models/position/position_snapshot.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/repositories/__init__.py +3 -3
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/repositories/order_fee_repository.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/repositories/portfolio_snapshot_repository.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/repositories/position_repository.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/repositories/position_snapshot_repository.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/repositories/repository.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/services/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/services/market_service/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/services/performance_service/__init__.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/infrastructure/services/performance_service/backtest_performance_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/backtesting/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/configuration_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/market_data_source_service/__init__.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/order_service/__init__.py +1 -1
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/portfolios/backtest_portfolio_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/portfolios/portfolio_configuration_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/portfolios/portfolio_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/portfolios/portfolio_snapshot_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/position_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/position_snapshot_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/repository_service.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/investing_algorithm_framework/services/trade_service/__init__.py +0 -0
- {investing_algorithm_framework-3.4.3 → investing_algorithm_framework-3.5.1}/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.1
|
|
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
|
-
|
|
242
|
+
market_data_sources,
|
|
243
|
+
pending_order_check_interval=None,
|
|
240
244
|
) -> None:
|
|
241
245
|
"""
|
|
242
246
|
Initialize the app for backtesting by setting the configuration
|
|
@@ -257,9 +261,11 @@ class App:
|
|
|
257
261
|
configuration_service.config[BACKTESTING_START_DATE] = \
|
|
258
262
|
backtest_start_date
|
|
259
263
|
configuration_service.config[BACKTESTING_END_DATE] = backtest_end_date
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
264
|
+
|
|
265
|
+
if pending_order_check_interval is not None:
|
|
266
|
+
configuration_service.config[
|
|
267
|
+
BACKTESTING_PENDING_ORDER_CHECK_INTERVAL
|
|
268
|
+
] = pending_order_check_interval
|
|
263
269
|
|
|
264
270
|
# Create resource dir if not exits
|
|
265
271
|
self._create_resource_directory_if_not_exists()
|
|
@@ -267,12 +273,6 @@ class App:
|
|
|
267
273
|
# Override the MarketDataSourceService service with the backtest
|
|
268
274
|
# market data source service equivalent. Additionally, convert the
|
|
269
275
|
# 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
276
|
|
|
277
277
|
if market_data_sources is not None:
|
|
278
278
|
backtest_market_data_sources = [
|
|
@@ -435,10 +435,10 @@ class App:
|
|
|
435
435
|
shutil.copy(management_commands_template, destination)
|
|
436
436
|
|
|
437
437
|
def run(
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
438
|
+
self,
|
|
439
|
+
payload: dict = None,
|
|
440
|
+
number_of_iterations: int = None,
|
|
441
|
+
sync=False
|
|
442
442
|
):
|
|
443
443
|
"""
|
|
444
444
|
Entry point to run the application. This method should be called to
|
|
@@ -500,7 +500,6 @@ class App:
|
|
|
500
500
|
while self.algorithm.running:
|
|
501
501
|
if number_of_iterations_since_last_orders_check == 30:
|
|
502
502
|
logger.info("Checking pending orders")
|
|
503
|
-
self.algorithm.check_pending_orders()
|
|
504
503
|
number_of_iterations_since_last_orders_check = 1
|
|
505
504
|
|
|
506
505
|
self.algorithm.run_jobs()
|
|
@@ -673,12 +672,12 @@ class App:
|
|
|
673
672
|
return self.algorithm.get_portfolio_configurations()
|
|
674
673
|
|
|
675
674
|
def run_backtest(
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
675
|
+
self,
|
|
676
|
+
algorithm,
|
|
677
|
+
start_date,
|
|
678
|
+
end_date,
|
|
679
|
+
pending_order_check_interval=None,
|
|
680
|
+
output_directory=None
|
|
682
681
|
) -> BacktestReport:
|
|
683
682
|
"""
|
|
684
683
|
Run a backtest for an algorithm. This method should be called when
|
|
@@ -699,10 +698,14 @@ class App:
|
|
|
699
698
|
if end_date is None:
|
|
700
699
|
end_date = datetime.utcnow()
|
|
701
700
|
|
|
701
|
+
market_data_sources = self._market_data_source_service\
|
|
702
|
+
.get_market_data_sources()
|
|
703
|
+
|
|
702
704
|
self._initialize_app_for_backtest(
|
|
703
705
|
backtest_start_date=start_date,
|
|
704
706
|
backtest_end_date=end_date,
|
|
705
|
-
pending_order_check_interval=pending_order_check_interval
|
|
707
|
+
pending_order_check_interval=pending_order_check_interval,
|
|
708
|
+
market_data_sources=market_data_sources
|
|
706
709
|
)
|
|
707
710
|
|
|
708
711
|
self._initialize_algorithm_for_backtest(
|
|
@@ -733,12 +736,13 @@ class App:
|
|
|
733
736
|
return report
|
|
734
737
|
|
|
735
738
|
def run_backtests(
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
739
|
+
self,
|
|
740
|
+
algorithms,
|
|
741
|
+
start_date: Optional[datetime] = None,
|
|
742
|
+
end_date: Optional[datetime] = None,
|
|
743
|
+
date_ranges: Optional[Tuple[datetime, datetime]] = None,
|
|
744
|
+
pending_order_check_interval=None,
|
|
745
|
+
output_directory=None
|
|
742
746
|
) -> List[BacktestReport]:
|
|
743
747
|
"""
|
|
744
748
|
Run a backtest for a set algorithm. This method should be called when
|
|
@@ -749,6 +753,8 @@ class App:
|
|
|
749
753
|
:param start_date: The start date of the backtest
|
|
750
754
|
:param end_date: The end date of the backtest
|
|
751
755
|
:param pending_order_check_interval: The interval at which to check
|
|
756
|
+
:param date_ranges: The date ranges to run the backtests for (list of
|
|
757
|
+
tuples of start and end dates)
|
|
752
758
|
pending orders
|
|
753
759
|
:param output_directory: The directory to write the backtest report to
|
|
754
760
|
:return: List of BacktestReport intances
|
|
@@ -756,39 +762,61 @@ class App:
|
|
|
756
762
|
logger.info("Initializing backtests")
|
|
757
763
|
reports = []
|
|
758
764
|
|
|
759
|
-
if
|
|
760
|
-
end_date = datetime.utcnow()
|
|
765
|
+
if start_date is not None:
|
|
761
766
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
backtest_end_date=end_date,
|
|
765
|
-
pending_order_check_interval=pending_order_check_interval
|
|
766
|
-
)
|
|
767
|
+
if end_date is None:
|
|
768
|
+
end_date = datetime.utcnow()
|
|
767
769
|
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
770
|
+
date_ranges = [(start_date, end_date)]
|
|
771
|
+
else:
|
|
772
|
+
if date_ranges is None:
|
|
773
|
+
raise OperationalException("No date ranges specified")
|
|
774
|
+
|
|
775
|
+
market_data_sources = self._market_data_source_service\
|
|
776
|
+
.get_market_data_sources()
|
|
777
|
+
|
|
778
|
+
for date_range in date_ranges:
|
|
779
|
+
start_date, end_date = date_range
|
|
780
|
+
self._initialize_app_for_backtest(
|
|
781
|
+
backtest_start_date=start_date,
|
|
782
|
+
backtest_end_date=end_date,
|
|
783
|
+
pending_order_check_interval=pending_order_check_interval,
|
|
784
|
+
market_data_sources=market_data_sources
|
|
773
785
|
)
|
|
774
786
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
787
|
+
print(
|
|
788
|
+
f"{COLOR_YELLOW}Running backtests for date "
|
|
789
|
+
f"range:{COLOR_RESET} {COLOR_GREEN}{start_date} - "
|
|
790
|
+
f"{end_date} for a "
|
|
791
|
+
f"total of {len(algorithms)} algorithms.{COLOR_RESET}"
|
|
778
792
|
)
|
|
779
|
-
|
|
780
|
-
.
|
|
793
|
+
for algorithm in algorithms:
|
|
794
|
+
self._initialize_algorithm_for_backtest(algorithm)
|
|
795
|
+
backtest_service = self.container.backtest_service()
|
|
796
|
+
backtest_service.resource_directory = self.config.get(
|
|
797
|
+
RESOURCE_DIRECTORY
|
|
798
|
+
)
|
|
781
799
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
800
|
+
# Run the backtest with the backtest_service
|
|
801
|
+
# and collect the report
|
|
802
|
+
report = backtest_service.run_backtest(
|
|
803
|
+
algorithm=algorithm,
|
|
804
|
+
start_date=start_date,
|
|
805
|
+
end_date=end_date
|
|
786
806
|
)
|
|
807
|
+
backtest_report_writer_service = self.container \
|
|
808
|
+
.backtest_report_writer_service()
|
|
787
809
|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
810
|
+
if output_directory is None:
|
|
811
|
+
output_directory = os.path.join(
|
|
812
|
+
self.config.get(RESOURCE_DIRECTORY),
|
|
813
|
+
"backtest_reports"
|
|
814
|
+
)
|
|
815
|
+
|
|
816
|
+
backtest_report_writer_service.write_report_to_csv(
|
|
817
|
+
report=report, output_directory=output_directory
|
|
818
|
+
)
|
|
819
|
+
reports.append(report)
|
|
792
820
|
|
|
793
821
|
return reports
|
|
794
822
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
from investing_algorithm_framework.domain import OperationalException
|
|
1
2
|
from investing_algorithm_framework.domain import \
|
|
2
3
|
TimeUnit, StrategyProfile, Trade
|
|
3
4
|
from .algorithm import Algorithm
|
|
4
|
-
from investing_algorithm_framework.domain import OperationalException
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class TradingStrategy:
|
|
@@ -60,6 +60,10 @@ class TradingStrategy:
|
|
|
60
60
|
)
|
|
61
61
|
|
|
62
62
|
def run_strategy(self, algorithm, market_data):
|
|
63
|
+
# Check pending orders before running the strategy
|
|
64
|
+
algorithm.check_pending_orders()
|
|
65
|
+
|
|
66
|
+
# Run user defined strategy
|
|
63
67
|
self.apply_strategy(algorithm=algorithm, market_data=market_data)
|
|
64
68
|
|
|
65
69
|
def apply_strategy(self, algorithm, market_data):
|
|
@@ -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):
|