investing-algorithm-framework 3.7.0__py3-none-any.whl → 7.19.15__py3-none-any.whl
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.
Potentially problematic release.
This version of investing-algorithm-framework might be problematic. Click here for more details.
- investing_algorithm_framework/__init__.py +168 -45
- investing_algorithm_framework/app/__init__.py +32 -1
- investing_algorithm_framework/app/algorithm/__init__.py +7 -0
- investing_algorithm_framework/app/algorithm/algorithm.py +239 -0
- investing_algorithm_framework/app/algorithm/algorithm_factory.py +114 -0
- investing_algorithm_framework/app/analysis/__init__.py +15 -0
- investing_algorithm_framework/app/analysis/backtest_data_ranges.py +121 -0
- investing_algorithm_framework/app/analysis/backtest_utils.py +107 -0
- investing_algorithm_framework/app/analysis/permutation.py +116 -0
- investing_algorithm_framework/app/analysis/ranking.py +297 -0
- investing_algorithm_framework/app/app.py +1933 -589
- investing_algorithm_framework/app/app_hook.py +28 -0
- investing_algorithm_framework/app/context.py +1725 -0
- investing_algorithm_framework/app/eventloop.py +590 -0
- investing_algorithm_framework/app/reporting/__init__.py +27 -0
- investing_algorithm_framework/app/reporting/ascii.py +921 -0
- investing_algorithm_framework/app/reporting/backtest_report.py +349 -0
- investing_algorithm_framework/app/reporting/charts/__init__.py +19 -0
- investing_algorithm_framework/app/reporting/charts/entry_exist_signals.py +66 -0
- investing_algorithm_framework/app/reporting/charts/equity_curve.py +37 -0
- investing_algorithm_framework/app/reporting/charts/equity_curve_drawdown.py +74 -0
- investing_algorithm_framework/app/reporting/charts/line_chart.py +11 -0
- investing_algorithm_framework/app/reporting/charts/monthly_returns_heatmap.py +70 -0
- investing_algorithm_framework/app/reporting/charts/ohlcv_data_completeness.py +51 -0
- investing_algorithm_framework/app/reporting/charts/rolling_sharp_ratio.py +79 -0
- investing_algorithm_framework/app/reporting/charts/yearly_returns_barchart.py +55 -0
- investing_algorithm_framework/app/reporting/generate.py +185 -0
- investing_algorithm_framework/app/reporting/tables/__init__.py +11 -0
- investing_algorithm_framework/app/reporting/tables/key_metrics_table.py +217 -0
- investing_algorithm_framework/app/reporting/tables/stop_loss_table.py +0 -0
- investing_algorithm_framework/app/reporting/tables/time_metrics_table.py +80 -0
- investing_algorithm_framework/app/reporting/tables/trade_metrics_table.py +147 -0
- investing_algorithm_framework/app/reporting/tables/trades_table.py +75 -0
- investing_algorithm_framework/app/reporting/tables/utils.py +29 -0
- investing_algorithm_framework/app/reporting/templates/report_template.html.j2 +154 -0
- investing_algorithm_framework/app/stateless/action_handlers/__init__.py +4 -2
- investing_algorithm_framework/app/stateless/action_handlers/action_handler_strategy.py +1 -1
- investing_algorithm_framework/app/stateless/action_handlers/check_online_handler.py +1 -1
- investing_algorithm_framework/app/stateless/action_handlers/run_strategy_handler.py +14 -7
- investing_algorithm_framework/app/strategy.py +664 -84
- investing_algorithm_framework/app/task.py +5 -3
- investing_algorithm_framework/app/web/__init__.py +2 -1
- investing_algorithm_framework/app/web/create_app.py +4 -2
- investing_algorithm_framework/cli/__init__.py +0 -0
- investing_algorithm_framework/cli/cli.py +226 -0
- investing_algorithm_framework/cli/deploy_to_aws_lambda.py +501 -0
- investing_algorithm_framework/cli/deploy_to_azure_function.py +718 -0
- investing_algorithm_framework/cli/initialize_app.py +603 -0
- investing_algorithm_framework/cli/templates/.gitignore.template +178 -0
- investing_algorithm_framework/cli/templates/app.py.template +18 -0
- investing_algorithm_framework/cli/templates/app_aws_lambda_function.py.template +48 -0
- investing_algorithm_framework/cli/templates/app_azure_function.py.template +14 -0
- investing_algorithm_framework/cli/templates/app_web.py.template +18 -0
- investing_algorithm_framework/cli/templates/aws_lambda_dockerfile.template +22 -0
- investing_algorithm_framework/cli/templates/aws_lambda_dockerignore.template +92 -0
- investing_algorithm_framework/cli/templates/aws_lambda_readme.md.template +110 -0
- investing_algorithm_framework/cli/templates/aws_lambda_requirements.txt.template +2 -0
- investing_algorithm_framework/cli/templates/azure_function_function_app.py.template +65 -0
- investing_algorithm_framework/cli/templates/azure_function_host.json.template +15 -0
- investing_algorithm_framework/cli/templates/azure_function_local.settings.json.template +8 -0
- investing_algorithm_framework/cli/templates/azure_function_requirements.txt.template +3 -0
- investing_algorithm_framework/cli/templates/data_providers.py.template +17 -0
- investing_algorithm_framework/cli/templates/env.example.template +2 -0
- investing_algorithm_framework/cli/templates/env_azure_function.example.template +4 -0
- investing_algorithm_framework/cli/templates/market_data_providers.py.template +9 -0
- investing_algorithm_framework/cli/templates/readme.md.template +135 -0
- investing_algorithm_framework/cli/templates/requirements.txt.template +2 -0
- investing_algorithm_framework/cli/templates/run_backtest.py.template +20 -0
- investing_algorithm_framework/cli/templates/strategy.py.template +124 -0
- investing_algorithm_framework/create_app.py +40 -6
- investing_algorithm_framework/dependency_container.py +72 -56
- investing_algorithm_framework/domain/__init__.py +71 -47
- investing_algorithm_framework/domain/backtesting/__init__.py +21 -0
- investing_algorithm_framework/domain/backtesting/backtest.py +503 -0
- investing_algorithm_framework/domain/backtesting/backtest_date_range.py +96 -0
- investing_algorithm_framework/domain/backtesting/backtest_evaluation_focuss.py +242 -0
- investing_algorithm_framework/domain/backtesting/backtest_metrics.py +459 -0
- investing_algorithm_framework/domain/backtesting/backtest_permutation_test.py +275 -0
- investing_algorithm_framework/domain/backtesting/backtest_run.py +605 -0
- investing_algorithm_framework/domain/backtesting/backtest_summary_metrics.py +162 -0
- investing_algorithm_framework/domain/backtesting/combine_backtests.py +280 -0
- investing_algorithm_framework/domain/config.py +59 -91
- investing_algorithm_framework/domain/constants.py +13 -38
- investing_algorithm_framework/domain/data_provider.py +334 -0
- investing_algorithm_framework/domain/data_structures.py +3 -2
- investing_algorithm_framework/domain/exceptions.py +51 -1
- investing_algorithm_framework/domain/models/__init__.py +17 -12
- investing_algorithm_framework/domain/models/data/__init__.py +7 -0
- investing_algorithm_framework/domain/models/data/data_source.py +214 -0
- investing_algorithm_framework/domain/models/data/data_type.py +46 -0
- investing_algorithm_framework/domain/models/event.py +35 -0
- investing_algorithm_framework/domain/models/market/market_credential.py +55 -1
- investing_algorithm_framework/domain/models/order/order.py +77 -83
- investing_algorithm_framework/domain/models/order/order_status.py +2 -2
- investing_algorithm_framework/domain/models/order/order_type.py +1 -3
- investing_algorithm_framework/domain/models/portfolio/portfolio.py +81 -3
- investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +26 -3
- investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +108 -11
- investing_algorithm_framework/domain/models/position/__init__.py +2 -1
- investing_algorithm_framework/domain/models/position/position.py +12 -0
- investing_algorithm_framework/domain/models/position/position_size.py +41 -0
- investing_algorithm_framework/domain/models/risk_rules/__init__.py +7 -0
- investing_algorithm_framework/domain/models/risk_rules/stop_loss_rule.py +51 -0
- investing_algorithm_framework/domain/models/risk_rules/take_profit_rule.py +55 -0
- investing_algorithm_framework/domain/models/snapshot_interval.py +45 -0
- investing_algorithm_framework/domain/models/strategy_profile.py +19 -151
- investing_algorithm_framework/domain/models/time_frame.py +37 -0
- investing_algorithm_framework/domain/models/time_interval.py +33 -0
- investing_algorithm_framework/domain/models/time_unit.py +66 -2
- investing_algorithm_framework/domain/models/trade/__init__.py +8 -1
- investing_algorithm_framework/domain/models/trade/trade.py +295 -171
- investing_algorithm_framework/domain/models/trade/trade_status.py +9 -2
- investing_algorithm_framework/domain/models/trade/trade_stop_loss.py +332 -0
- investing_algorithm_framework/domain/models/trade/trade_take_profit.py +365 -0
- investing_algorithm_framework/domain/order_executor.py +112 -0
- investing_algorithm_framework/domain/portfolio_provider.py +118 -0
- investing_algorithm_framework/domain/services/__init__.py +2 -9
- investing_algorithm_framework/domain/services/portfolios/portfolio_sync_service.py +0 -6
- investing_algorithm_framework/domain/services/state_handler.py +38 -0
- investing_algorithm_framework/domain/strategy.py +1 -29
- investing_algorithm_framework/domain/utils/__init__.py +12 -7
- investing_algorithm_framework/domain/utils/custom_tqdm.py +22 -0
- investing_algorithm_framework/domain/utils/dates.py +57 -0
- investing_algorithm_framework/domain/utils/jupyter_notebook_detection.py +19 -0
- investing_algorithm_framework/domain/utils/polars.py +53 -0
- investing_algorithm_framework/domain/utils/random.py +29 -0
- investing_algorithm_framework/download_data.py +108 -0
- investing_algorithm_framework/infrastructure/__init__.py +31 -18
- investing_algorithm_framework/infrastructure/data_providers/__init__.py +36 -0
- investing_algorithm_framework/infrastructure/data_providers/ccxt.py +1143 -0
- investing_algorithm_framework/infrastructure/data_providers/csv.py +568 -0
- investing_algorithm_framework/infrastructure/data_providers/pandas.py +599 -0
- investing_algorithm_framework/infrastructure/database/__init__.py +6 -2
- investing_algorithm_framework/infrastructure/database/sql_alchemy.py +86 -12
- investing_algorithm_framework/infrastructure/models/__init__.py +6 -11
- investing_algorithm_framework/infrastructure/models/order/__init__.py +2 -1
- investing_algorithm_framework/infrastructure/models/order/order.py +35 -49
- investing_algorithm_framework/infrastructure/models/order/order_metadata.py +44 -0
- investing_algorithm_framework/infrastructure/models/order_trade_association.py +10 -0
- investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +1 -1
- investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +8 -0
- investing_algorithm_framework/infrastructure/models/portfolio/{portfolio.py → sql_portfolio.py} +17 -5
- investing_algorithm_framework/infrastructure/models/trades/__init__.py +9 -0
- investing_algorithm_framework/infrastructure/models/trades/trade.py +130 -0
- investing_algorithm_framework/infrastructure/models/trades/trade_stop_loss.py +59 -0
- investing_algorithm_framework/infrastructure/models/trades/trade_take_profit.py +55 -0
- investing_algorithm_framework/infrastructure/order_executors/__init__.py +21 -0
- investing_algorithm_framework/infrastructure/order_executors/backtest_oder_executor.py +28 -0
- investing_algorithm_framework/infrastructure/order_executors/ccxt_order_executor.py +200 -0
- investing_algorithm_framework/infrastructure/portfolio_providers/__init__.py +19 -0
- investing_algorithm_framework/infrastructure/portfolio_providers/ccxt_portfolio_provider.py +199 -0
- investing_algorithm_framework/infrastructure/repositories/__init__.py +8 -0
- investing_algorithm_framework/infrastructure/repositories/order_metadata_repository.py +17 -0
- investing_algorithm_framework/infrastructure/repositories/order_repository.py +5 -0
- investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +1 -1
- investing_algorithm_framework/infrastructure/repositories/position_repository.py +11 -0
- investing_algorithm_framework/infrastructure/repositories/repository.py +81 -27
- investing_algorithm_framework/infrastructure/repositories/trade_repository.py +71 -0
- investing_algorithm_framework/infrastructure/repositories/trade_stop_loss_repository.py +29 -0
- investing_algorithm_framework/infrastructure/repositories/trade_take_profit_repository.py +29 -0
- investing_algorithm_framework/infrastructure/services/__init__.py +4 -4
- investing_algorithm_framework/infrastructure/services/aws/__init__.py +6 -0
- investing_algorithm_framework/infrastructure/services/aws/state_handler.py +113 -0
- investing_algorithm_framework/infrastructure/services/azure/__init__.py +5 -0
- investing_algorithm_framework/infrastructure/services/azure/state_handler.py +158 -0
- investing_algorithm_framework/services/__init__.py +113 -16
- investing_algorithm_framework/services/backtesting/__init__.py +0 -7
- investing_algorithm_framework/services/backtesting/backtest_service.py +566 -359
- investing_algorithm_framework/services/configuration_service.py +77 -11
- investing_algorithm_framework/services/data_providers/__init__.py +5 -0
- investing_algorithm_framework/services/data_providers/data_provider_service.py +850 -0
- investing_algorithm_framework/services/market_credential_service.py +16 -1
- investing_algorithm_framework/services/metrics/__init__.py +114 -0
- investing_algorithm_framework/services/metrics/alpha.py +0 -0
- investing_algorithm_framework/services/metrics/beta.py +0 -0
- investing_algorithm_framework/services/metrics/cagr.py +60 -0
- investing_algorithm_framework/services/metrics/calmar_ratio.py +40 -0
- investing_algorithm_framework/services/metrics/drawdown.py +181 -0
- investing_algorithm_framework/services/metrics/equity_curve.py +24 -0
- investing_algorithm_framework/services/metrics/exposure.py +210 -0
- investing_algorithm_framework/services/metrics/generate.py +358 -0
- investing_algorithm_framework/services/metrics/mean_daily_return.py +83 -0
- investing_algorithm_framework/services/metrics/profit_factor.py +165 -0
- investing_algorithm_framework/services/metrics/recovery.py +113 -0
- investing_algorithm_framework/services/metrics/returns.py +452 -0
- investing_algorithm_framework/services/metrics/risk_free_rate.py +28 -0
- investing_algorithm_framework/services/metrics/sharpe_ratio.py +137 -0
- investing_algorithm_framework/services/metrics/sortino_ratio.py +74 -0
- investing_algorithm_framework/services/metrics/standard_deviation.py +157 -0
- investing_algorithm_framework/services/metrics/trades.py +500 -0
- investing_algorithm_framework/services/metrics/treynor_ratio.py +0 -0
- investing_algorithm_framework/services/metrics/ulcer.py +0 -0
- investing_algorithm_framework/services/metrics/value_at_risk.py +0 -0
- investing_algorithm_framework/services/metrics/volatility.py +97 -0
- investing_algorithm_framework/services/metrics/win_rate.py +177 -0
- investing_algorithm_framework/services/order_service/__init__.py +3 -1
- investing_algorithm_framework/services/order_service/order_backtest_service.py +76 -89
- investing_algorithm_framework/services/order_service/order_executor_lookup.py +110 -0
- investing_algorithm_framework/services/order_service/order_service.py +407 -326
- investing_algorithm_framework/services/portfolios/__init__.py +3 -1
- investing_algorithm_framework/services/portfolios/backtest_portfolio_service.py +37 -3
- investing_algorithm_framework/services/portfolios/portfolio_configuration_service.py +22 -8
- investing_algorithm_framework/services/portfolios/portfolio_provider_lookup.py +106 -0
- investing_algorithm_framework/services/portfolios/portfolio_service.py +96 -28
- investing_algorithm_framework/services/portfolios/portfolio_snapshot_service.py +97 -28
- investing_algorithm_framework/services/portfolios/portfolio_sync_service.py +116 -313
- investing_algorithm_framework/services/positions/__init__.py +7 -0
- investing_algorithm_framework/services/positions/position_service.py +210 -0
- investing_algorithm_framework/services/repository_service.py +8 -2
- investing_algorithm_framework/services/trade_order_evaluator/__init__.py +9 -0
- investing_algorithm_framework/services/trade_order_evaluator/backtest_trade_oder_evaluator.py +113 -0
- investing_algorithm_framework/services/trade_order_evaluator/default_trade_order_evaluator.py +51 -0
- investing_algorithm_framework/services/trade_order_evaluator/trade_order_evaluator.py +80 -0
- investing_algorithm_framework/services/trade_service/__init__.py +7 -1
- investing_algorithm_framework/services/trade_service/trade_service.py +1013 -315
- investing_algorithm_framework/services/trade_service/trade_stop_loss_service.py +39 -0
- investing_algorithm_framework/services/trade_service/trade_take_profit_service.py +41 -0
- investing_algorithm_framework-7.19.15.dist-info/METADATA +537 -0
- investing_algorithm_framework-7.19.15.dist-info/RECORD +263 -0
- investing_algorithm_framework-7.19.15.dist-info/entry_points.txt +3 -0
- investing_algorithm_framework/app/algorithm.py +0 -1105
- investing_algorithm_framework/domain/graphs.py +0 -382
- investing_algorithm_framework/domain/metrics/__init__.py +0 -6
- investing_algorithm_framework/domain/models/backtesting/__init__.py +0 -11
- investing_algorithm_framework/domain/models/backtesting/backtest_date_range.py +0 -43
- investing_algorithm_framework/domain/models/backtesting/backtest_position.py +0 -120
- investing_algorithm_framework/domain/models/backtesting/backtest_report.py +0 -580
- investing_algorithm_framework/domain/models/backtesting/backtest_reports_evaluation.py +0 -243
- investing_algorithm_framework/domain/models/trading_data_types.py +0 -47
- investing_algorithm_framework/domain/models/trading_time_frame.py +0 -223
- investing_algorithm_framework/domain/services/market_data_sources.py +0 -344
- investing_algorithm_framework/domain/services/market_service.py +0 -153
- investing_algorithm_framework/domain/singleton.py +0 -9
- investing_algorithm_framework/domain/utils/backtesting.py +0 -472
- investing_algorithm_framework/infrastructure/models/market_data_sources/__init__.py +0 -12
- investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py +0 -559
- investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py +0 -254
- investing_algorithm_framework/infrastructure/models/market_data_sources/us_treasury_yield.py +0 -47
- investing_algorithm_framework/infrastructure/services/market_service/__init__.py +0 -5
- investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py +0 -455
- investing_algorithm_framework/infrastructure/services/performance_service/__init__.py +0 -7
- investing_algorithm_framework/infrastructure/services/performance_service/backtest_performance_service.py +0 -2
- investing_algorithm_framework/infrastructure/services/performance_service/performance_service.py +0 -350
- investing_algorithm_framework/services/backtesting/backtest_report_writer_service.py +0 -53
- investing_algorithm_framework/services/backtesting/graphs.py +0 -61
- investing_algorithm_framework/services/market_data_source_service/__init__.py +0 -8
- investing_algorithm_framework/services/market_data_source_service/backtest_market_data_source_service.py +0 -150
- investing_algorithm_framework/services/market_data_source_service/market_data_source_service.py +0 -189
- investing_algorithm_framework/services/position_service.py +0 -31
- investing_algorithm_framework/services/strategy_orchestrator_service.py +0 -264
- investing_algorithm_framework-3.7.0.dist-info/METADATA +0 -339
- investing_algorithm_framework-3.7.0.dist-info/RECORD +0 -147
- /investing_algorithm_framework/{domain → services}/metrics/price_efficiency.py +0 -0
- /investing_algorithm_framework/services/{position_snapshot_service.py → positions/position_snapshot_service.py} +0 -0
- {investing_algorithm_framework-3.7.0.dist-info → investing_algorithm_framework-7.19.15.dist-info}/LICENSE +0 -0
- {investing_algorithm_framework-3.7.0.dist-info → investing_algorithm_framework-7.19.15.dist-info}/WHEEL +0 -0
|
@@ -1,141 +1,25 @@
|
|
|
1
|
-
from
|
|
2
|
-
from .time_unit import TimeUnit
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class StrategyProfile(BaseModel):
|
|
6
|
-
|
|
7
|
-
def __init__(
|
|
8
|
-
self,
|
|
9
|
-
strategy_id=None,
|
|
10
|
-
interval=None,
|
|
11
|
-
time_unit=None,
|
|
12
|
-
trading_time_frame=None,
|
|
13
|
-
trading_time_frame_start_date=None,
|
|
14
|
-
symbols=None,
|
|
15
|
-
market=None,
|
|
16
|
-
backtest_start_date_data=None,
|
|
17
|
-
backtest_data_index_date=None,
|
|
18
|
-
trading_data_type=None,
|
|
19
|
-
trading_data_types=None,
|
|
20
|
-
market_data_sources=None,
|
|
21
|
-
):
|
|
22
|
-
self._strategy_id = strategy_id
|
|
23
|
-
self._interval = interval
|
|
24
|
-
self._time_unit = time_unit
|
|
25
|
-
self._number_of_runs = 0
|
|
26
|
-
self._trading_time_frame = trading_time_frame
|
|
27
|
-
self._trading_time_frame_start_date = trading_time_frame_start_date
|
|
28
|
-
self._backtest_start_date_data = backtest_start_date_data
|
|
29
|
-
self._backtest_data_index_date = backtest_data_index_date
|
|
30
|
-
self._symbols = symbols
|
|
31
|
-
self._market = market
|
|
32
|
-
self._trading_data_type = trading_data_type
|
|
33
|
-
self._trading_data_types = trading_data_types
|
|
34
|
-
self._market_data_sources = market_data_sources
|
|
35
|
-
|
|
36
|
-
@property
|
|
37
|
-
def strategy_id(self):
|
|
38
|
-
return self._strategy_id
|
|
39
|
-
|
|
40
|
-
@strategy_id.setter
|
|
41
|
-
def strategy_id(self, strategy_id):
|
|
42
|
-
self._strategy_id = strategy_id
|
|
43
|
-
|
|
44
|
-
@property
|
|
45
|
-
def interval(self):
|
|
46
|
-
return self._interval
|
|
47
|
-
|
|
48
|
-
@interval.setter
|
|
49
|
-
def interval(self, value):
|
|
50
|
-
self._interval = value
|
|
51
|
-
|
|
52
|
-
@property
|
|
53
|
-
def time_unit(self):
|
|
54
|
-
return self._time_unit
|
|
55
|
-
|
|
56
|
-
@time_unit.setter
|
|
57
|
-
def time_unit(self, value):
|
|
58
|
-
self._time_unit = value
|
|
59
|
-
|
|
60
|
-
@property
|
|
61
|
-
def symbols(self):
|
|
62
|
-
return self._symbols
|
|
63
|
-
|
|
64
|
-
@property
|
|
65
|
-
def trading_time_frame(self):
|
|
66
|
-
return self._trading_time_frame
|
|
67
|
-
|
|
68
|
-
@property
|
|
69
|
-
def trading_time_frame_start_date(self):
|
|
70
|
-
return self._trading_time_frame_start_date
|
|
71
|
-
|
|
72
|
-
@property
|
|
73
|
-
def number_of_runs(self):
|
|
74
|
-
return self._number_of_runs
|
|
75
|
-
|
|
76
|
-
@property
|
|
77
|
-
def market(self):
|
|
78
|
-
return self._market
|
|
1
|
+
from dataclasses import dataclass
|
|
79
2
|
|
|
80
|
-
|
|
81
|
-
def symbols(self, value):
|
|
82
|
-
self._symbols = value
|
|
83
|
-
|
|
84
|
-
@market.setter
|
|
85
|
-
def market(self, value):
|
|
86
|
-
self._market = value
|
|
87
|
-
|
|
88
|
-
@number_of_runs.setter
|
|
89
|
-
def number_of_runs(self, value):
|
|
90
|
-
self._number_of_runs = value
|
|
91
|
-
|
|
92
|
-
@trading_time_frame.setter
|
|
93
|
-
def trading_time_frame(self, value):
|
|
94
|
-
self._trading_time_frame = value
|
|
95
|
-
|
|
96
|
-
@property
|
|
97
|
-
def backtest_start_date_data(self):
|
|
98
|
-
return self._backtest_start_date_data
|
|
99
|
-
|
|
100
|
-
@backtest_start_date_data.setter
|
|
101
|
-
def backtest_start_date_data(self, value):
|
|
102
|
-
self._backtest_start_date_data = value
|
|
103
|
-
|
|
104
|
-
@property
|
|
105
|
-
def backtest_data_index_date(self):
|
|
106
|
-
return self._backtest_data_index_date
|
|
107
|
-
|
|
108
|
-
@backtest_data_index_date.setter
|
|
109
|
-
def backtest_data_index_date(self, value):
|
|
110
|
-
self._backtest_data_index_date = value
|
|
111
|
-
|
|
112
|
-
@property
|
|
113
|
-
def trading_data_type(self):
|
|
114
|
-
return self._trading_data_type
|
|
115
|
-
|
|
116
|
-
@trading_data_type.setter
|
|
117
|
-
def trading_data_type(self, value):
|
|
118
|
-
self._trading_data_type = value
|
|
119
|
-
|
|
120
|
-
@property
|
|
121
|
-
def trading_data_types(self):
|
|
122
|
-
|
|
123
|
-
if self.trading_data_type is not None:
|
|
124
|
-
return [self.trading_data_type]
|
|
125
|
-
|
|
126
|
-
return self._trading_data_types
|
|
127
|
-
|
|
128
|
-
@trading_data_types.setter
|
|
129
|
-
def trading_data_types(self, value):
|
|
130
|
-
self._trading_data_types = value
|
|
3
|
+
from .time_unit import TimeUnit
|
|
131
4
|
|
|
132
|
-
@property
|
|
133
|
-
def market_data_sources(self):
|
|
134
|
-
return self._market_data_sources
|
|
135
5
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
6
|
+
@dataclass(frozen=True)
|
|
7
|
+
class StrategyProfile:
|
|
8
|
+
"""
|
|
9
|
+
StrategyProfile class that represents the profile of a trading strategy.
|
|
10
|
+
"""
|
|
11
|
+
strategy_id: str = None
|
|
12
|
+
interval: int = None
|
|
13
|
+
time_unit: TimeUnit = None
|
|
14
|
+
trading_time_frame: str = None
|
|
15
|
+
trading_time_frame_start_date: str = None
|
|
16
|
+
backtest_start_date_data: str = None
|
|
17
|
+
backtest_data_index_date: str = None
|
|
18
|
+
symbols: list = None
|
|
19
|
+
market: str = None
|
|
20
|
+
trading_data_type: str = None
|
|
21
|
+
trading_data_types: list = None
|
|
22
|
+
data_sources: list = None
|
|
139
23
|
|
|
140
24
|
def get_runs_per_day(self):
|
|
141
25
|
|
|
@@ -147,19 +31,3 @@ class StrategyProfile(BaseModel):
|
|
|
147
31
|
return 1440 / self.interval
|
|
148
32
|
else:
|
|
149
33
|
return 24 / self.interval
|
|
150
|
-
|
|
151
|
-
def __repr__(self):
|
|
152
|
-
return self.repr(
|
|
153
|
-
strategy_id=self._strategy_id,
|
|
154
|
-
number_of_runs=self._number_of_runs,
|
|
155
|
-
trading_time_frame=self._trading_time_frame,
|
|
156
|
-
trading_time_frame_start_date=self._trading_time_frame_start_date,
|
|
157
|
-
symbols=self._symbols,
|
|
158
|
-
time_unit=self.time_unit,
|
|
159
|
-
interval=self.interval,
|
|
160
|
-
market=self._market,
|
|
161
|
-
backtest_start_date_data=self._backtest_start_date_data,
|
|
162
|
-
backtest_data_index_date=self._backtest_data_index_date,
|
|
163
|
-
trading_data_type=self._trading_data_type,
|
|
164
|
-
trading_data_types=self._trading_data_types,
|
|
165
|
-
)
|
|
@@ -36,6 +36,15 @@ class TimeFrame(Enum):
|
|
|
36
36
|
if value == entry.value.replace("H", "h"):
|
|
37
37
|
return entry
|
|
38
38
|
|
|
39
|
+
# For hour timeframes compare with and without H
|
|
40
|
+
if "d" in entry.value:
|
|
41
|
+
|
|
42
|
+
if value == entry.value:
|
|
43
|
+
return entry
|
|
44
|
+
|
|
45
|
+
if value == entry.value.replace("d", "D"):
|
|
46
|
+
return entry
|
|
47
|
+
|
|
39
48
|
if value == entry.value:
|
|
40
49
|
return entry
|
|
41
50
|
|
|
@@ -114,3 +123,31 @@ class TimeFrame(Enum):
|
|
|
114
123
|
|
|
115
124
|
if self.equals(TimeFrame.ONE_MONTH):
|
|
116
125
|
return 40320
|
|
126
|
+
|
|
127
|
+
if self.equals(TimeFrame.ONE_YEAR):
|
|
128
|
+
return 525600
|
|
129
|
+
|
|
130
|
+
raise ValueError(
|
|
131
|
+
f"Could not determine amount of minutes for {self.value}"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# Add comparison methods for ordering
|
|
135
|
+
def __lt__(self, other):
|
|
136
|
+
if isinstance(other, TimeFrame):
|
|
137
|
+
return self.amount_of_minutes < other.amount_of_minutes
|
|
138
|
+
raise TypeError(f"Cannot compare TimeFrame with {type(other)}")
|
|
139
|
+
|
|
140
|
+
def __le__(self, other):
|
|
141
|
+
if isinstance(other, TimeFrame):
|
|
142
|
+
return self.amount_of_minutes <= other.amount_of_minutes
|
|
143
|
+
raise TypeError(f"Cannot compare TimeFrame with {type(other)}")
|
|
144
|
+
|
|
145
|
+
def __gt__(self, other):
|
|
146
|
+
if isinstance(other, TimeFrame):
|
|
147
|
+
return self.amount_of_minutes > other.amount_of_minutes
|
|
148
|
+
raise TypeError(f"Cannot compare TimeFrame with {type(other)}")
|
|
149
|
+
|
|
150
|
+
def __ge__(self, other):
|
|
151
|
+
if isinstance(other, TimeFrame):
|
|
152
|
+
return self.amount_of_minutes >= other.amount_of_minutes
|
|
153
|
+
raise TypeError(f"Cannot compare TimeFrame with {type(other)}")
|
|
@@ -25,6 +25,39 @@ class TimeInterval(Enum):
|
|
|
25
25
|
f"Could not convert {value} to TimeInterval"
|
|
26
26
|
)
|
|
27
27
|
|
|
28
|
+
@staticmethod
|
|
29
|
+
def from_ohlcv_data_file(file_path: str):
|
|
30
|
+
"""
|
|
31
|
+
Extracts the time interval from the file name of an OHLCV data file.
|
|
32
|
+
The file name should contain the time interval in the format
|
|
33
|
+
'symbol_timeinterval.csv'.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
file_path (str): The file path of the OHLCV data file.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
TimeInterval: The extracted time interval.
|
|
40
|
+
"""
|
|
41
|
+
if not isinstance(file_path, str):
|
|
42
|
+
raise ValueError("File path must be a string.")
|
|
43
|
+
|
|
44
|
+
parts = file_path.split('_')
|
|
45
|
+
if len(parts) < 2:
|
|
46
|
+
raise ValueError(
|
|
47
|
+
"File name does not contain a valid time interval."
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
time_interval_str = parts[-1].split('.')[0].upper()
|
|
51
|
+
try:
|
|
52
|
+
return TimeInterval.from_string(time_interval_str)
|
|
53
|
+
except ValueError:
|
|
54
|
+
raise ValueError(
|
|
55
|
+
"Could not extract time interval from "
|
|
56
|
+
f"file name: {file_path}. "
|
|
57
|
+
"Expected format 'symbol_timeinterval.csv', "
|
|
58
|
+
f"got '{time_interval_str}'."
|
|
59
|
+
)
|
|
60
|
+
|
|
28
61
|
def equals(self, other):
|
|
29
62
|
|
|
30
63
|
if isinstance(other, Enum):
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
from datetime import timedelta
|
|
2
2
|
from enum import Enum
|
|
3
|
+
from investing_algorithm_framework.domain.exceptions import \
|
|
4
|
+
OperationalException
|
|
3
5
|
|
|
4
6
|
|
|
5
7
|
class TimeUnit(Enum):
|
|
8
|
+
"""
|
|
9
|
+
Enum class the represents a time unit such as
|
|
10
|
+
second, minute, hour or day. This can class
|
|
11
|
+
can be used to specify time specification within
|
|
12
|
+
the framework.
|
|
13
|
+
"""
|
|
6
14
|
SECOND = "SECOND"
|
|
7
15
|
MINUTE = "MINUTE"
|
|
8
16
|
HOUR = "HOUR"
|
|
@@ -18,10 +26,50 @@ class TimeUnit(Enum):
|
|
|
18
26
|
if value.upper() == entry.value:
|
|
19
27
|
return entry
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
raise OperationalException(
|
|
30
|
+
f"Could not convert string {value} to time unit"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
raise OperationalException(
|
|
34
|
+
f"Could not convert value {value} to time unit," +
|
|
35
|
+
" please make sure that the value is either of type string or" +
|
|
36
|
+
f"TimeUnit. Its current type is {type(value)}"
|
|
23
37
|
)
|
|
24
38
|
|
|
39
|
+
@staticmethod
|
|
40
|
+
def from_ohlcv_data_file(file_path: str):
|
|
41
|
+
"""
|
|
42
|
+
Extracts the time unit from the file name of an OHLCV data file.
|
|
43
|
+
The file name should contain the time unit in the
|
|
44
|
+
format 'symbol_timeunit.csv'.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
file_path (str): The file path of the OHLCV data file.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
TimeUnit: The extracted time unit.
|
|
51
|
+
"""
|
|
52
|
+
if not isinstance(file_path, str):
|
|
53
|
+
raise OperationalException(
|
|
54
|
+
"File path must be a string."
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
parts = file_path.split('_')
|
|
58
|
+
if len(parts) < 2:
|
|
59
|
+
raise OperationalException(
|
|
60
|
+
"File name does not contain a valid time unit."
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
time_unit_str = parts[-1].split('.')[0].upper()
|
|
64
|
+
try:
|
|
65
|
+
return TimeUnit.from_string(time_unit_str)
|
|
66
|
+
except ValueError:
|
|
67
|
+
raise OperationalException(
|
|
68
|
+
f"Could not extract time unit from file name: {file_path}. "
|
|
69
|
+
"Expected format 'symbol_timeunit.csv', "
|
|
70
|
+
f"got '{time_unit_str}'."
|
|
71
|
+
)
|
|
72
|
+
|
|
25
73
|
def equals(self, other):
|
|
26
74
|
|
|
27
75
|
if isinstance(other, Enum):
|
|
@@ -83,3 +131,19 @@ class TimeUnit(Enum):
|
|
|
83
131
|
|
|
84
132
|
if TimeUnit.DAY.equals(self.value):
|
|
85
133
|
return "days"
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def amount_of_minutes(self):
|
|
137
|
+
if TimeUnit.SECOND.equals(self):
|
|
138
|
+
return 1 / 60
|
|
139
|
+
|
|
140
|
+
if TimeUnit.MINUTE.equals(self):
|
|
141
|
+
return 1
|
|
142
|
+
|
|
143
|
+
if TimeUnit.HOUR.equals(self):
|
|
144
|
+
return 60
|
|
145
|
+
|
|
146
|
+
if TimeUnit.DAY.equals(self):
|
|
147
|
+
return 60 * 24
|
|
148
|
+
|
|
149
|
+
raise ValueError(f"Unsupported time unit: {self}")
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
from .trade import Trade
|
|
2
2
|
from .trade_status import TradeStatus
|
|
3
|
+
from .trade_stop_loss import TradeStopLoss
|
|
4
|
+
from .trade_take_profit import TradeTakeProfit
|
|
3
5
|
|
|
4
|
-
__all__ = [
|
|
6
|
+
__all__ = [
|
|
7
|
+
"Trade",
|
|
8
|
+
"TradeStatus",
|
|
9
|
+
"TradeStopLoss",
|
|
10
|
+
"TradeTakeProfit",
|
|
11
|
+
]
|