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.

Files changed (256) hide show
  1. investing_algorithm_framework/__init__.py +168 -45
  2. investing_algorithm_framework/app/__init__.py +32 -1
  3. investing_algorithm_framework/app/algorithm/__init__.py +7 -0
  4. investing_algorithm_framework/app/algorithm/algorithm.py +239 -0
  5. investing_algorithm_framework/app/algorithm/algorithm_factory.py +114 -0
  6. investing_algorithm_framework/app/analysis/__init__.py +15 -0
  7. investing_algorithm_framework/app/analysis/backtest_data_ranges.py +121 -0
  8. investing_algorithm_framework/app/analysis/backtest_utils.py +107 -0
  9. investing_algorithm_framework/app/analysis/permutation.py +116 -0
  10. investing_algorithm_framework/app/analysis/ranking.py +297 -0
  11. investing_algorithm_framework/app/app.py +1933 -589
  12. investing_algorithm_framework/app/app_hook.py +28 -0
  13. investing_algorithm_framework/app/context.py +1725 -0
  14. investing_algorithm_framework/app/eventloop.py +590 -0
  15. investing_algorithm_framework/app/reporting/__init__.py +27 -0
  16. investing_algorithm_framework/app/reporting/ascii.py +921 -0
  17. investing_algorithm_framework/app/reporting/backtest_report.py +349 -0
  18. investing_algorithm_framework/app/reporting/charts/__init__.py +19 -0
  19. investing_algorithm_framework/app/reporting/charts/entry_exist_signals.py +66 -0
  20. investing_algorithm_framework/app/reporting/charts/equity_curve.py +37 -0
  21. investing_algorithm_framework/app/reporting/charts/equity_curve_drawdown.py +74 -0
  22. investing_algorithm_framework/app/reporting/charts/line_chart.py +11 -0
  23. investing_algorithm_framework/app/reporting/charts/monthly_returns_heatmap.py +70 -0
  24. investing_algorithm_framework/app/reporting/charts/ohlcv_data_completeness.py +51 -0
  25. investing_algorithm_framework/app/reporting/charts/rolling_sharp_ratio.py +79 -0
  26. investing_algorithm_framework/app/reporting/charts/yearly_returns_barchart.py +55 -0
  27. investing_algorithm_framework/app/reporting/generate.py +185 -0
  28. investing_algorithm_framework/app/reporting/tables/__init__.py +11 -0
  29. investing_algorithm_framework/app/reporting/tables/key_metrics_table.py +217 -0
  30. investing_algorithm_framework/app/reporting/tables/stop_loss_table.py +0 -0
  31. investing_algorithm_framework/app/reporting/tables/time_metrics_table.py +80 -0
  32. investing_algorithm_framework/app/reporting/tables/trade_metrics_table.py +147 -0
  33. investing_algorithm_framework/app/reporting/tables/trades_table.py +75 -0
  34. investing_algorithm_framework/app/reporting/tables/utils.py +29 -0
  35. investing_algorithm_framework/app/reporting/templates/report_template.html.j2 +154 -0
  36. investing_algorithm_framework/app/stateless/action_handlers/__init__.py +4 -2
  37. investing_algorithm_framework/app/stateless/action_handlers/action_handler_strategy.py +1 -1
  38. investing_algorithm_framework/app/stateless/action_handlers/check_online_handler.py +1 -1
  39. investing_algorithm_framework/app/stateless/action_handlers/run_strategy_handler.py +14 -7
  40. investing_algorithm_framework/app/strategy.py +664 -84
  41. investing_algorithm_framework/app/task.py +5 -3
  42. investing_algorithm_framework/app/web/__init__.py +2 -1
  43. investing_algorithm_framework/app/web/create_app.py +4 -2
  44. investing_algorithm_framework/cli/__init__.py +0 -0
  45. investing_algorithm_framework/cli/cli.py +226 -0
  46. investing_algorithm_framework/cli/deploy_to_aws_lambda.py +501 -0
  47. investing_algorithm_framework/cli/deploy_to_azure_function.py +718 -0
  48. investing_algorithm_framework/cli/initialize_app.py +603 -0
  49. investing_algorithm_framework/cli/templates/.gitignore.template +178 -0
  50. investing_algorithm_framework/cli/templates/app.py.template +18 -0
  51. investing_algorithm_framework/cli/templates/app_aws_lambda_function.py.template +48 -0
  52. investing_algorithm_framework/cli/templates/app_azure_function.py.template +14 -0
  53. investing_algorithm_framework/cli/templates/app_web.py.template +18 -0
  54. investing_algorithm_framework/cli/templates/aws_lambda_dockerfile.template +22 -0
  55. investing_algorithm_framework/cli/templates/aws_lambda_dockerignore.template +92 -0
  56. investing_algorithm_framework/cli/templates/aws_lambda_readme.md.template +110 -0
  57. investing_algorithm_framework/cli/templates/aws_lambda_requirements.txt.template +2 -0
  58. investing_algorithm_framework/cli/templates/azure_function_function_app.py.template +65 -0
  59. investing_algorithm_framework/cli/templates/azure_function_host.json.template +15 -0
  60. investing_algorithm_framework/cli/templates/azure_function_local.settings.json.template +8 -0
  61. investing_algorithm_framework/cli/templates/azure_function_requirements.txt.template +3 -0
  62. investing_algorithm_framework/cli/templates/data_providers.py.template +17 -0
  63. investing_algorithm_framework/cli/templates/env.example.template +2 -0
  64. investing_algorithm_framework/cli/templates/env_azure_function.example.template +4 -0
  65. investing_algorithm_framework/cli/templates/market_data_providers.py.template +9 -0
  66. investing_algorithm_framework/cli/templates/readme.md.template +135 -0
  67. investing_algorithm_framework/cli/templates/requirements.txt.template +2 -0
  68. investing_algorithm_framework/cli/templates/run_backtest.py.template +20 -0
  69. investing_algorithm_framework/cli/templates/strategy.py.template +124 -0
  70. investing_algorithm_framework/create_app.py +40 -6
  71. investing_algorithm_framework/dependency_container.py +72 -56
  72. investing_algorithm_framework/domain/__init__.py +71 -47
  73. investing_algorithm_framework/domain/backtesting/__init__.py +21 -0
  74. investing_algorithm_framework/domain/backtesting/backtest.py +503 -0
  75. investing_algorithm_framework/domain/backtesting/backtest_date_range.py +96 -0
  76. investing_algorithm_framework/domain/backtesting/backtest_evaluation_focuss.py +242 -0
  77. investing_algorithm_framework/domain/backtesting/backtest_metrics.py +459 -0
  78. investing_algorithm_framework/domain/backtesting/backtest_permutation_test.py +275 -0
  79. investing_algorithm_framework/domain/backtesting/backtest_run.py +605 -0
  80. investing_algorithm_framework/domain/backtesting/backtest_summary_metrics.py +162 -0
  81. investing_algorithm_framework/domain/backtesting/combine_backtests.py +280 -0
  82. investing_algorithm_framework/domain/config.py +59 -91
  83. investing_algorithm_framework/domain/constants.py +13 -38
  84. investing_algorithm_framework/domain/data_provider.py +334 -0
  85. investing_algorithm_framework/domain/data_structures.py +3 -2
  86. investing_algorithm_framework/domain/exceptions.py +51 -1
  87. investing_algorithm_framework/domain/models/__init__.py +17 -12
  88. investing_algorithm_framework/domain/models/data/__init__.py +7 -0
  89. investing_algorithm_framework/domain/models/data/data_source.py +214 -0
  90. investing_algorithm_framework/domain/models/data/data_type.py +46 -0
  91. investing_algorithm_framework/domain/models/event.py +35 -0
  92. investing_algorithm_framework/domain/models/market/market_credential.py +55 -1
  93. investing_algorithm_framework/domain/models/order/order.py +77 -83
  94. investing_algorithm_framework/domain/models/order/order_status.py +2 -2
  95. investing_algorithm_framework/domain/models/order/order_type.py +1 -3
  96. investing_algorithm_framework/domain/models/portfolio/portfolio.py +81 -3
  97. investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +26 -3
  98. investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +108 -11
  99. investing_algorithm_framework/domain/models/position/__init__.py +2 -1
  100. investing_algorithm_framework/domain/models/position/position.py +12 -0
  101. investing_algorithm_framework/domain/models/position/position_size.py +41 -0
  102. investing_algorithm_framework/domain/models/risk_rules/__init__.py +7 -0
  103. investing_algorithm_framework/domain/models/risk_rules/stop_loss_rule.py +51 -0
  104. investing_algorithm_framework/domain/models/risk_rules/take_profit_rule.py +55 -0
  105. investing_algorithm_framework/domain/models/snapshot_interval.py +45 -0
  106. investing_algorithm_framework/domain/models/strategy_profile.py +19 -151
  107. investing_algorithm_framework/domain/models/time_frame.py +37 -0
  108. investing_algorithm_framework/domain/models/time_interval.py +33 -0
  109. investing_algorithm_framework/domain/models/time_unit.py +66 -2
  110. investing_algorithm_framework/domain/models/trade/__init__.py +8 -1
  111. investing_algorithm_framework/domain/models/trade/trade.py +295 -171
  112. investing_algorithm_framework/domain/models/trade/trade_status.py +9 -2
  113. investing_algorithm_framework/domain/models/trade/trade_stop_loss.py +332 -0
  114. investing_algorithm_framework/domain/models/trade/trade_take_profit.py +365 -0
  115. investing_algorithm_framework/domain/order_executor.py +112 -0
  116. investing_algorithm_framework/domain/portfolio_provider.py +118 -0
  117. investing_algorithm_framework/domain/services/__init__.py +2 -9
  118. investing_algorithm_framework/domain/services/portfolios/portfolio_sync_service.py +0 -6
  119. investing_algorithm_framework/domain/services/state_handler.py +38 -0
  120. investing_algorithm_framework/domain/strategy.py +1 -29
  121. investing_algorithm_framework/domain/utils/__init__.py +12 -7
  122. investing_algorithm_framework/domain/utils/custom_tqdm.py +22 -0
  123. investing_algorithm_framework/domain/utils/dates.py +57 -0
  124. investing_algorithm_framework/domain/utils/jupyter_notebook_detection.py +19 -0
  125. investing_algorithm_framework/domain/utils/polars.py +53 -0
  126. investing_algorithm_framework/domain/utils/random.py +29 -0
  127. investing_algorithm_framework/download_data.py +108 -0
  128. investing_algorithm_framework/infrastructure/__init__.py +31 -18
  129. investing_algorithm_framework/infrastructure/data_providers/__init__.py +36 -0
  130. investing_algorithm_framework/infrastructure/data_providers/ccxt.py +1143 -0
  131. investing_algorithm_framework/infrastructure/data_providers/csv.py +568 -0
  132. investing_algorithm_framework/infrastructure/data_providers/pandas.py +599 -0
  133. investing_algorithm_framework/infrastructure/database/__init__.py +6 -2
  134. investing_algorithm_framework/infrastructure/database/sql_alchemy.py +86 -12
  135. investing_algorithm_framework/infrastructure/models/__init__.py +6 -11
  136. investing_algorithm_framework/infrastructure/models/order/__init__.py +2 -1
  137. investing_algorithm_framework/infrastructure/models/order/order.py +35 -49
  138. investing_algorithm_framework/infrastructure/models/order/order_metadata.py +44 -0
  139. investing_algorithm_framework/infrastructure/models/order_trade_association.py +10 -0
  140. investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +1 -1
  141. investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +8 -0
  142. investing_algorithm_framework/infrastructure/models/portfolio/{portfolio.py โ†’ sql_portfolio.py} +17 -5
  143. investing_algorithm_framework/infrastructure/models/trades/__init__.py +9 -0
  144. investing_algorithm_framework/infrastructure/models/trades/trade.py +130 -0
  145. investing_algorithm_framework/infrastructure/models/trades/trade_stop_loss.py +59 -0
  146. investing_algorithm_framework/infrastructure/models/trades/trade_take_profit.py +55 -0
  147. investing_algorithm_framework/infrastructure/order_executors/__init__.py +21 -0
  148. investing_algorithm_framework/infrastructure/order_executors/backtest_oder_executor.py +28 -0
  149. investing_algorithm_framework/infrastructure/order_executors/ccxt_order_executor.py +200 -0
  150. investing_algorithm_framework/infrastructure/portfolio_providers/__init__.py +19 -0
  151. investing_algorithm_framework/infrastructure/portfolio_providers/ccxt_portfolio_provider.py +199 -0
  152. investing_algorithm_framework/infrastructure/repositories/__init__.py +8 -0
  153. investing_algorithm_framework/infrastructure/repositories/order_metadata_repository.py +17 -0
  154. investing_algorithm_framework/infrastructure/repositories/order_repository.py +5 -0
  155. investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +1 -1
  156. investing_algorithm_framework/infrastructure/repositories/position_repository.py +11 -0
  157. investing_algorithm_framework/infrastructure/repositories/repository.py +81 -27
  158. investing_algorithm_framework/infrastructure/repositories/trade_repository.py +71 -0
  159. investing_algorithm_framework/infrastructure/repositories/trade_stop_loss_repository.py +29 -0
  160. investing_algorithm_framework/infrastructure/repositories/trade_take_profit_repository.py +29 -0
  161. investing_algorithm_framework/infrastructure/services/__init__.py +4 -4
  162. investing_algorithm_framework/infrastructure/services/aws/__init__.py +6 -0
  163. investing_algorithm_framework/infrastructure/services/aws/state_handler.py +113 -0
  164. investing_algorithm_framework/infrastructure/services/azure/__init__.py +5 -0
  165. investing_algorithm_framework/infrastructure/services/azure/state_handler.py +158 -0
  166. investing_algorithm_framework/services/__init__.py +113 -16
  167. investing_algorithm_framework/services/backtesting/__init__.py +0 -7
  168. investing_algorithm_framework/services/backtesting/backtest_service.py +566 -359
  169. investing_algorithm_framework/services/configuration_service.py +77 -11
  170. investing_algorithm_framework/services/data_providers/__init__.py +5 -0
  171. investing_algorithm_framework/services/data_providers/data_provider_service.py +850 -0
  172. investing_algorithm_framework/services/market_credential_service.py +16 -1
  173. investing_algorithm_framework/services/metrics/__init__.py +114 -0
  174. investing_algorithm_framework/services/metrics/alpha.py +0 -0
  175. investing_algorithm_framework/services/metrics/beta.py +0 -0
  176. investing_algorithm_framework/services/metrics/cagr.py +60 -0
  177. investing_algorithm_framework/services/metrics/calmar_ratio.py +40 -0
  178. investing_algorithm_framework/services/metrics/drawdown.py +181 -0
  179. investing_algorithm_framework/services/metrics/equity_curve.py +24 -0
  180. investing_algorithm_framework/services/metrics/exposure.py +210 -0
  181. investing_algorithm_framework/services/metrics/generate.py +358 -0
  182. investing_algorithm_framework/services/metrics/mean_daily_return.py +83 -0
  183. investing_algorithm_framework/services/metrics/profit_factor.py +165 -0
  184. investing_algorithm_framework/services/metrics/recovery.py +113 -0
  185. investing_algorithm_framework/services/metrics/returns.py +452 -0
  186. investing_algorithm_framework/services/metrics/risk_free_rate.py +28 -0
  187. investing_algorithm_framework/services/metrics/sharpe_ratio.py +137 -0
  188. investing_algorithm_framework/services/metrics/sortino_ratio.py +74 -0
  189. investing_algorithm_framework/services/metrics/standard_deviation.py +157 -0
  190. investing_algorithm_framework/services/metrics/trades.py +500 -0
  191. investing_algorithm_framework/services/metrics/treynor_ratio.py +0 -0
  192. investing_algorithm_framework/services/metrics/ulcer.py +0 -0
  193. investing_algorithm_framework/services/metrics/value_at_risk.py +0 -0
  194. investing_algorithm_framework/services/metrics/volatility.py +97 -0
  195. investing_algorithm_framework/services/metrics/win_rate.py +177 -0
  196. investing_algorithm_framework/services/order_service/__init__.py +3 -1
  197. investing_algorithm_framework/services/order_service/order_backtest_service.py +76 -89
  198. investing_algorithm_framework/services/order_service/order_executor_lookup.py +110 -0
  199. investing_algorithm_framework/services/order_service/order_service.py +407 -326
  200. investing_algorithm_framework/services/portfolios/__init__.py +3 -1
  201. investing_algorithm_framework/services/portfolios/backtest_portfolio_service.py +37 -3
  202. investing_algorithm_framework/services/portfolios/portfolio_configuration_service.py +22 -8
  203. investing_algorithm_framework/services/portfolios/portfolio_provider_lookup.py +106 -0
  204. investing_algorithm_framework/services/portfolios/portfolio_service.py +96 -28
  205. investing_algorithm_framework/services/portfolios/portfolio_snapshot_service.py +97 -28
  206. investing_algorithm_framework/services/portfolios/portfolio_sync_service.py +116 -313
  207. investing_algorithm_framework/services/positions/__init__.py +7 -0
  208. investing_algorithm_framework/services/positions/position_service.py +210 -0
  209. investing_algorithm_framework/services/repository_service.py +8 -2
  210. investing_algorithm_framework/services/trade_order_evaluator/__init__.py +9 -0
  211. investing_algorithm_framework/services/trade_order_evaluator/backtest_trade_oder_evaluator.py +113 -0
  212. investing_algorithm_framework/services/trade_order_evaluator/default_trade_order_evaluator.py +51 -0
  213. investing_algorithm_framework/services/trade_order_evaluator/trade_order_evaluator.py +80 -0
  214. investing_algorithm_framework/services/trade_service/__init__.py +7 -1
  215. investing_algorithm_framework/services/trade_service/trade_service.py +1013 -315
  216. investing_algorithm_framework/services/trade_service/trade_stop_loss_service.py +39 -0
  217. investing_algorithm_framework/services/trade_service/trade_take_profit_service.py +41 -0
  218. investing_algorithm_framework-7.19.15.dist-info/METADATA +537 -0
  219. investing_algorithm_framework-7.19.15.dist-info/RECORD +263 -0
  220. investing_algorithm_framework-7.19.15.dist-info/entry_points.txt +3 -0
  221. investing_algorithm_framework/app/algorithm.py +0 -1105
  222. investing_algorithm_framework/domain/graphs.py +0 -382
  223. investing_algorithm_framework/domain/metrics/__init__.py +0 -6
  224. investing_algorithm_framework/domain/models/backtesting/__init__.py +0 -11
  225. investing_algorithm_framework/domain/models/backtesting/backtest_date_range.py +0 -43
  226. investing_algorithm_framework/domain/models/backtesting/backtest_position.py +0 -120
  227. investing_algorithm_framework/domain/models/backtesting/backtest_report.py +0 -580
  228. investing_algorithm_framework/domain/models/backtesting/backtest_reports_evaluation.py +0 -243
  229. investing_algorithm_framework/domain/models/trading_data_types.py +0 -47
  230. investing_algorithm_framework/domain/models/trading_time_frame.py +0 -223
  231. investing_algorithm_framework/domain/services/market_data_sources.py +0 -344
  232. investing_algorithm_framework/domain/services/market_service.py +0 -153
  233. investing_algorithm_framework/domain/singleton.py +0 -9
  234. investing_algorithm_framework/domain/utils/backtesting.py +0 -472
  235. investing_algorithm_framework/infrastructure/models/market_data_sources/__init__.py +0 -12
  236. investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py +0 -559
  237. investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py +0 -254
  238. investing_algorithm_framework/infrastructure/models/market_data_sources/us_treasury_yield.py +0 -47
  239. investing_algorithm_framework/infrastructure/services/market_service/__init__.py +0 -5
  240. investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py +0 -455
  241. investing_algorithm_framework/infrastructure/services/performance_service/__init__.py +0 -7
  242. investing_algorithm_framework/infrastructure/services/performance_service/backtest_performance_service.py +0 -2
  243. investing_algorithm_framework/infrastructure/services/performance_service/performance_service.py +0 -350
  244. investing_algorithm_framework/services/backtesting/backtest_report_writer_service.py +0 -53
  245. investing_algorithm_framework/services/backtesting/graphs.py +0 -61
  246. investing_algorithm_framework/services/market_data_source_service/__init__.py +0 -8
  247. investing_algorithm_framework/services/market_data_source_service/backtest_market_data_source_service.py +0 -150
  248. investing_algorithm_framework/services/market_data_source_service/market_data_source_service.py +0 -189
  249. investing_algorithm_framework/services/position_service.py +0 -31
  250. investing_algorithm_framework/services/strategy_orchestrator_service.py +0 -264
  251. investing_algorithm_framework-3.7.0.dist-info/METADATA +0 -339
  252. investing_algorithm_framework-3.7.0.dist-info/RECORD +0 -147
  253. /investing_algorithm_framework/{domain โ†’ services}/metrics/price_efficiency.py +0 -0
  254. /investing_algorithm_framework/services/{position_snapshot_service.py โ†’ positions/position_snapshot_service.py} +0 -0
  255. {investing_algorithm_framework-3.7.0.dist-info โ†’ investing_algorithm_framework-7.19.15.dist-info}/LICENSE +0 -0
  256. {investing_algorithm_framework-3.7.0.dist-info โ†’ investing_algorithm_framework-7.19.15.dist-info}/WHEEL +0 -0
@@ -0,0 +1,39 @@
1
+ import logging
2
+ from datetime import datetime
3
+
4
+ from investing_algorithm_framework.services.repository_service import \
5
+ RepositoryService
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+
10
+ class TradeStopLossService(RepositoryService):
11
+
12
+ def mark_triggered(
13
+ self,
14
+ stop_loss_ids,
15
+ trigger_date: datetime
16
+ ) -> None:
17
+ """
18
+ Mark stop losses as triggered.
19
+
20
+ Args:
21
+ stop_loss_ids (List[str]): List of stop loss IDs to
22
+ mark as triggered.
23
+ trigger_date (datetime): The date when the stop loss
24
+ was triggered.
25
+
26
+ Returns:
27
+ None
28
+ """
29
+ update_data = {
30
+ "triggered": True,
31
+ "triggered_at": trigger_date,
32
+ "updated_at": trigger_date
33
+ }
34
+
35
+ for id in stop_loss_ids:
36
+ try:
37
+ self.update(id, update_data)
38
+ except Exception as e:
39
+ logger.error(f"Error marking stop loss {id} as triggered: {e}")
@@ -0,0 +1,41 @@
1
+ import logging
2
+ from datetime import datetime
3
+
4
+ from investing_algorithm_framework.services.repository_service import \
5
+ RepositoryService
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+
10
+ class TradeTakeProfitService(RepositoryService):
11
+
12
+ def mark_triggered(
13
+ self,
14
+ take_profit_ids,
15
+ trigger_date: datetime
16
+ ) -> None:
17
+ """
18
+ Mark take profits as triggered.
19
+
20
+ Args:
21
+ take_profit_ids (List[str]): List of take profit IDs to
22
+ mark as triggered.
23
+ trigger_date (datetime): The date and time when the
24
+ take profits were triggered.
25
+
26
+ Returns:
27
+ None
28
+ """
29
+ update_data = {
30
+ "triggered": True,
31
+ "triggered_at": trigger_date,
32
+ "updated_at": trigger_date
33
+ }
34
+
35
+ for id in take_profit_ids:
36
+ try:
37
+ self.update(id, update_data)
38
+ except Exception as e:
39
+ logger.error(
40
+ f"Error marking take profit {id} as triggered: {e}"
41
+ )
@@ -0,0 +1,537 @@
1
+ Metadata-Version: 2.1
2
+ Name: investing-algorithm-framework
3
+ Version: 7.19.15
4
+ Summary: A framework for creating trading bots
5
+ Author: MDUYN
6
+ Requires-Python: >=3.10
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Requires-Dist: Flask (>=3.1.0)
12
+ Requires-Dist: Flask-Cors (>=3.0.9,<5.0.0)
13
+ Requires-Dist: Flask-Migrate (>=2.6.0)
14
+ Requires-Dist: SQLAlchemy (>=2.0.18)
15
+ Requires-Dist: azure-identity (>=1.19.0,<2.0.0)
16
+ Requires-Dist: azure-mgmt-resource (>=23.2.0,<24.0.0)
17
+ Requires-Dist: azure-mgmt-storage (>=21.2.1,<22.0.0)
18
+ Requires-Dist: azure-mgmt-web (>=7.3.1,<8.0.0)
19
+ Requires-Dist: azure-storage-blob (>=12.24.0,<13.0.0)
20
+ Requires-Dist: boto3 (>=1.38.41,<2.0.0)
21
+ Requires-Dist: ccxt (>=4.2.48)
22
+ Requires-Dist: dependency-injector (>=4.40.0)
23
+ Requires-Dist: jupyter (>=1.0.0)
24
+ Requires-Dist: marshmallow (>=3.5.0)
25
+ Requires-Dist: plotly (>=6.1.2,<7.0.0)
26
+ Requires-Dist: polars[numpy,pandas] (>=0.20.10)
27
+ Requires-Dist: pyarrow (>=19.0.1)
28
+ Requires-Dist: python-dateutil (>=2.8.2)
29
+ Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
30
+ Requires-Dist: schedule (>=1.1.0)
31
+ Requires-Dist: tabulate (>=0.9.0)
32
+ Requires-Dist: tqdm (>=4.66.1)
33
+ Requires-Dist: wrapt (>=1.16.0)
34
+ Requires-Dist: yfinance (>=0.2.61,<0.3.0)
35
+ Description-Content-Type: text/markdown
36
+
37
+ <div align="center">
38
+ <h1>โšก Investing Algorithm Framework</h1>
39
+
40
+ <p style="font-size: 18px; font-weight: 600; margin: 15px 0;">
41
+ ๐Ÿš€ <b>Build. Backtest. Deploy.</b> Quantitative Trading Strategies at Scale
42
+ </p>
43
+
44
+ <p style="font-size: 14px; color: #666; margin-bottom: 25px;">
45
+ The fastest way to go from trading idea to production-ready trading bot
46
+ </p>
47
+
48
+ <!-- Quick Links -->
49
+ <div style="margin: 20px 0;">
50
+ <a target="_blank" href="https://coding-kitties.github.io/investing-algorithm-framework/">
51
+ <img src="https://img.shields.io/badge/๐Ÿ“–_Documentation-blue?style=for-the-badge">
52
+ </a>
53
+ &nbsp;
54
+ <a href="https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/installation">
55
+ <img src="https://img.shields.io/badge/๐Ÿš€_Quick_Start-green?style=for-the-badge">
56
+ </a>
57
+ </div>
58
+
59
+ <!-- Badges -->
60
+ <div style="margin-bottom: 20px;">
61
+ <a target="_blank" href="https://discord.gg/dQsRmGZP"><img src="https://img.shields.io/discord/1345358169777635410.svg?color=7289da&label=Discord&logo=discord&style=flat-square" alt="Discord"></a>
62
+ &nbsp;
63
+ <a href="https://github.com/coding-kitties/investing-algorithm-framework/actions/workflows/test.yml"><img src="https://github.com/coding-kitties/investing-algorithm-framework/actions/workflows/test.yml/badge.svg?style=flat-square" alt="Tests"></a>
64
+ &nbsp;
65
+ <a href="https://pypi.org/project/investing-algorithm-framework/"><img src="https://img.shields.io/pypi/v/investing-algorithm-framework.svg?style=flat-square" alt="PyPI"></a>
66
+ &nbsp;
67
+ <a href="https://pepy.tech/project/investing-algorithm-framework"><img src="https://pepy.tech/badge/investing-algorithm-framework/month?style=flat-square" alt="Downloads"></a>
68
+ &nbsp;
69
+ <a href="https://github.com/coding-kitties/investing-algorithm-framework/stargazers"><img src="https://img.shields.io/github/stars/coding-kitties/investing-algorithm-framework?style=flat-square" alt="Stars"></a>
70
+ </div>
71
+
72
+ <img src="static/showcase.svg" alt="Investing Algorithm Framework" style="height: 400px; max-width: 100%; margin: 30px 0;">
73
+
74
+ <hr style="margin: 30px 0; border: none; border-top: 2px solid #ddd;">
75
+
76
+ > โญ **If you like this project, please consider [starring](https://github.com/coding-kitties/investing-algorithm-framework) it!** Your support helps us build better tools for the community.
77
+
78
+ </div>
79
+
80
+ ---
81
+
82
+ ## ๐Ÿ’ก Why Investing Algorithm Framework?
83
+
84
+ Stop wasting time on boilerplate. The **Investing Algorithm Framework** handles all the heavy lifting:
85
+
86
+ โœจ **From Idea to Production** โ€” Write your strategy once, deploy everywhere
87
+ ๐Ÿ“Š **Accurate Backtesting** โ€” Event-driven and vectorized engines for realistic results
88
+ โšก **Lightning Fast** โ€” Optimized for speed and efficiency
89
+ ๐Ÿ”ง **Extensible** โ€” Connect any exchange, broker, or data source
90
+ ๐Ÿ“ˆ **Production Ready** โ€” Built for real money trading
91
+
92
+ ## Sponsors
93
+
94
+ <a href="https://www.finterion.com/" target="_blank">
95
+ <picture style="height: 30px;">
96
+ <source media="(prefers-color-scheme: dark)" srcset="static/sponsors/finterion-dark.png">
97
+ <source media="(prefers-color-scheme: light)" srcset="static/sponsors/finterion-light.png">
98
+ <img src="static/sponsors/finterion-light.png" alt="Finterion Logo" width="200px" height="50px">
99
+ </picture>
100
+ </a>
101
+
102
+
103
+ ## ๐Ÿ”Œ Plugins & Integrations
104
+
105
+ Extend your trading bot with powerful plugins:
106
+
107
+ | Plugin | Description |
108
+ |--------|-----------------------------------------------------------------------------|
109
+ | ๐ŸŽฏ **[PyIndicators](https://github.com/coding-kitties/PyIndicators)** | Technical analysis indicators for strategy development |
110
+ | ๐Ÿช **[Finterion Plugin](https://github.com/Finterion/finterion-investing-algorithm-framework-plugin)** | Monetize & share your strategies with the public on Finterion's marketplace |
111
+
112
+ ## ๐ŸŒŸ Powerful Features
113
+
114
+ | Feature | Description |
115
+ |---------|-------------|
116
+ | ๐Ÿ **Python 3.10+** | Cross-platform support for Windows, macOS, and Linux |
117
+ | โš™๏ธ **Event-Driven Backtest** | Accurate, realistic backtesting with event-driven architecture |
118
+ | โšก **Vectorized Backtest** | Lightning-fast signal research and prototyping |
119
+ | ๐Ÿ“Š **Advanced Metrics** | CAGR, Sharpe ratio, max drawdown, win rate, and 50+ more metrics |
120
+ | ๐Ÿ“ˆ **Backtest Reports** | Generate detailed, comparison-ready reports |
121
+ | ๐ŸŽฏ **Statistical Testing** | Permutation testing for strategy significance evaluation |
122
+ | ๐Ÿ’ฑ **Live Trading** | Real-time execution across multiple exchanges (via CCXT) |
123
+ | ๐Ÿ’ผ **Portfolio Management** | Full position and trade management with persistence |
124
+ | ๐Ÿ“‰ **Market Data** | OHLCV, tickers, custom data โ€” Polars & Pandas native |
125
+ | ๐Ÿ”— **Data Integrations** | PyIndicators, multiple data sources, custom providers |
126
+ | โ˜๏ธ **Cloud Deployment** | Azure Functions, AWS Lambda, and more |
127
+ | ๐ŸŒ **Web API** | REST API for bot interaction and monitoring |
128
+ | ๐Ÿงฉ **Fully Extensible** | Custom strategies, data providers, order executors |
129
+ | ๐Ÿ—๏ธ **Modular Design** | Build with reusable, composable components |
130
+
131
+
132
+
133
+ ## ๐Ÿš€ Quickstart
134
+
135
+ ### ๐Ÿ“ฆ Installation
136
+
137
+ Install the framework via [PyPI](https://pypi.org/project/investing-algorithm-framework/):
138
+
139
+ ```bash
140
+ pip install investing-algorithm-framework
141
+ ```
142
+
143
+ ### ๐ŸŽฏ Initialize Your Project
144
+
145
+ Run the following command to scaffold a new trading bot:
146
+
147
+ ```bash
148
+ investing-algorithm-framework init
149
+ ```
150
+
151
+ For an AWS Lambda-ready project:
152
+
153
+ ```bash
154
+ investing-algorithm-framework init --type aws_lambda
155
+ ```
156
+
157
+ This creates:
158
+ - **app.py** โ€” Your bot's entry point (keep as-is)
159
+ - **strategy.py** โ€” Your trading strategy (customize this!)
160
+
161
+ > ๐Ÿ’ก **Tip:** You can also create `default_web` or `azure_function` projects
162
+
163
+ ## ๐Ÿ“ˆ Example: A Simple Trading Bot
164
+ The following example trading bot implements a simple moving average strategy.
165
+ The strategy will use data from bitvavo exchange and will calculate
166
+ the 20, 50 and 100 period exponential moving averages (EMA) and the
167
+ 14 period relative strength index (RSI).
168
+
169
+ > This example uses [PyIndicators](https://github.com/coding-kitties/pyindicators) for technical analysis.
170
+ > This dependency is not part of the framework, but is used to perform technical analysis on the dataframes.
171
+ > You can install it using pip: pip install pyindicators.
172
+
173
+ ```python
174
+ from typing import Dict, Any
175
+ from datetime import datetime, timezone
176
+
177
+ import pandas as pd
178
+ from pyindicators import ema, rsi, crossover, crossunder
179
+
180
+ from investing_algorithm_framework import TradingStrategy, DataSource, \
181
+ TimeUnit, DataType, PositionSize, create_app, RESOURCE_DIRECTORY, \
182
+ BacktestDateRange, BacktestReport, TakeProfitRule, StopLossRule
183
+
184
+
185
+ class RSIEMACrossoverStrategy(TradingStrategy):
186
+ time_unit = TimeUnit.HOUR
187
+ interval = 2
188
+ symbols = ["BTC"]
189
+ position_sizes = [
190
+ PositionSize(
191
+ symbol="BTC", percentage_of_portfolio=20.0
192
+ ),
193
+ PositionSize(
194
+ symbol="ETH", percentage_of_portfolio=20.0
195
+ )
196
+ ]
197
+ take_profits = [
198
+ TakeProfitRule(
199
+ symbol="BTC",
200
+ percentage_threshold=10,
201
+ trailing=True,
202
+ sell_percentage=100
203
+ ),
204
+ TakeProfitRule(
205
+ symbol="ETH",
206
+ percentage_threshold=10,
207
+ trailing=True,
208
+ sell_percentage=100
209
+ )
210
+ ]
211
+ stop_losses = [
212
+ StopLossRule(
213
+ symbol="BTC",
214
+ percentage_threshold=5,
215
+ trailing=False,
216
+ sell_percentage=100
217
+ ),
218
+ StopLossRule(
219
+ symbol="ETH",
220
+ percentage_threshold=5,
221
+ trailing=False,
222
+ sell_percentage=100
223
+ )
224
+ ]
225
+
226
+ def __init__(
227
+ self,
228
+ time_unit: TimeUnit,
229
+ interval: int,
230
+ market: str,
231
+ rsi_time_frame: str,
232
+ rsi_period: int,
233
+ rsi_overbought_threshold,
234
+ rsi_oversold_threshold,
235
+ ema_time_frame,
236
+ ema_short_period,
237
+ ema_long_period,
238
+ ema_cross_lookback_window: int = 10
239
+ ):
240
+ self.rsi_time_frame = rsi_time_frame
241
+ self.rsi_period = rsi_period
242
+ self.rsi_result_column = f"rsi_{self.rsi_period}"
243
+ self.rsi_overbought_threshold = rsi_overbought_threshold
244
+ self.rsi_oversold_threshold = rsi_oversold_threshold
245
+ self.ema_time_frame = ema_time_frame
246
+ self.ema_short_result_column = f"ema_{ema_short_period}"
247
+ self.ema_long_result_column = f"ema_{ema_long_period}"
248
+ self.ema_crossunder_result_column = "ema_crossunder"
249
+ self.ema_crossover_result_column = "ema_crossover"
250
+ self.ema_short_period = ema_short_period
251
+ self.ema_long_period = ema_long_period
252
+ self.ema_cross_lookback_window = ema_cross_lookback_window
253
+ data_sources = []
254
+
255
+ for symbol in self.symbols:
256
+ full_symbol = f"{symbol}/EUR"
257
+ data_sources.append(
258
+ DataSource(
259
+ identifier=f"{symbol}_rsi_data",
260
+ data_type=DataType.OHLCV,
261
+ time_frame=self.rsi_time_frame,
262
+ market=market,
263
+ symbol=full_symbol,
264
+ pandas=True,
265
+ window_size=800
266
+ )
267
+ )
268
+ data_sources.append(
269
+ DataSource(
270
+ identifier=f"{symbol}_ema_data",
271
+ data_type=DataType.OHLCV,
272
+ time_frame=self.ema_time_frame,
273
+ market=market,
274
+ symbol=full_symbol,
275
+ pandas=True,
276
+ window_size=800
277
+ )
278
+ )
279
+
280
+ super().__init__(
281
+ data_sources=data_sources, time_unit=time_unit, interval=interval
282
+ )
283
+
284
+ def _prepare_indicators(
285
+ self,
286
+ rsi_data,
287
+ ema_data
288
+ ):
289
+ """
290
+ Helper function to prepare the indicators
291
+ for the strategy. The indicators are calculated
292
+ using the pyindicators library: https://github.com/coding-kitties/PyIndicators
293
+ """
294
+ ema_data = ema(
295
+ ema_data,
296
+ period=self.ema_short_period,
297
+ source_column="Close",
298
+ result_column=self.ema_short_result_column
299
+ )
300
+ ema_data = ema(
301
+ ema_data,
302
+ period=self.ema_long_period,
303
+ source_column="Close",
304
+ result_column=self.ema_long_result_column
305
+ )
306
+ # Detect crossover (short EMA crosses above long EMA)
307
+ ema_data = crossover(
308
+ ema_data,
309
+ first_column=self.ema_short_result_column,
310
+ second_column=self.ema_long_result_column,
311
+ result_column=self.ema_crossover_result_column
312
+ )
313
+ # Detect crossunder (short EMA crosses below long EMA)
314
+ ema_data = crossunder(
315
+ ema_data,
316
+ first_column=self.ema_short_result_column,
317
+ second_column=self.ema_long_result_column,
318
+ result_column=self.ema_crossunder_result_column
319
+ )
320
+ rsi_data = rsi(
321
+ rsi_data,
322
+ period=self.rsi_period,
323
+ source_column="Close",
324
+ result_column=self.rsi_result_column
325
+ )
326
+
327
+ return ema_data, rsi_data
328
+
329
+ def generate_buy_signals(self, data: Dict[str, Any]) -> Dict[str, pd.Series]:
330
+ """
331
+ Generate buy signals based on the moving average crossover.
332
+
333
+ data (Dict[str, Any]): Dictionary containing all the data for
334
+ the strategy data sources.
335
+
336
+ Returns:
337
+ Dict[str, pd.Series]: A dictionary where keys are symbols and values
338
+ are pandas Series indicating buy signals (True/False).
339
+ """
340
+
341
+ signals = {}
342
+
343
+ for symbol in self.symbols:
344
+ ema_data_identifier = f"{symbol}_ema_data"
345
+ rsi_data_identifier = f"{symbol}_rsi_data"
346
+ ema_data, rsi_data = self._prepare_indicators(
347
+ data[ema_data_identifier].copy(),
348
+ data[rsi_data_identifier].copy()
349
+ )
350
+
351
+ # crossover confirmed
352
+ ema_crossover_lookback = ema_data[
353
+ self.ema_crossover_result_column].rolling(
354
+ window=self.ema_cross_lookback_window
355
+ ).max().astype(bool)
356
+
357
+ # use only RSI column
358
+ rsi_oversold = rsi_data[self.rsi_result_column] \
359
+ < self.rsi_oversold_threshold
360
+
361
+ buy_signal = rsi_oversold & ema_crossover_lookback
362
+ buy_signals = buy_signal.fillna(False).astype(bool)
363
+ signals[symbol] = buy_signals
364
+ return signals
365
+
366
+ def generate_sell_signals(self, data: Dict[str, Any]) -> Dict[str, pd.Series]:
367
+ """
368
+ Generate sell signals based on the moving average crossover.
369
+
370
+ Args:
371
+ data (Dict[str, Any]): Dictionary containing all the data for
372
+ the strategy data sources.
373
+
374
+ Returns:
375
+ Dict[str, pd.Series]: A dictionary where keys are symbols and values
376
+ are pandas Series indicating sell signals (True/False).
377
+ """
378
+
379
+ signals = {}
380
+ for symbol in self.symbols:
381
+ ema_data_identifier = f"{symbol}_ema_data"
382
+ rsi_data_identifier = f"{symbol}_rsi_data"
383
+ ema_data, rsi_data = self._prepare_indicators(
384
+ data[ema_data_identifier].copy(),
385
+ data[rsi_data_identifier].copy()
386
+ )
387
+
388
+ # Confirmed by crossover between short-term EMA and long-term EMA
389
+ # within a given lookback window
390
+ ema_crossunder_lookback = ema_data[
391
+ self.ema_crossunder_result_column].rolling(
392
+ window=self.ema_cross_lookback_window
393
+ ).max().astype(bool)
394
+
395
+ # use only RSI column
396
+ rsi_overbought = rsi_data[self.rsi_result_column] \
397
+ >= self.rsi_overbought_threshold
398
+
399
+ # Combine both conditions
400
+ sell_signal = rsi_overbought & ema_crossunder_lookback
401
+ sell_signal = sell_signal.fillna(False).astype(bool)
402
+ signals[symbol] = sell_signal
403
+ return signals
404
+
405
+
406
+ if __name__ == "__main__":
407
+ app = create_app()
408
+ app.add_strategy(
409
+ RSIEMACrossoverStrategy(
410
+ time_unit=TimeUnit.HOUR,
411
+ interval=2,
412
+ market="bitvavo",
413
+ rsi_time_frame="2h",
414
+ rsi_period=14,
415
+ rsi_overbought_threshold=70,
416
+ rsi_oversold_threshold=30,
417
+ ema_time_frame="2h",
418
+ ema_short_period=12,
419
+ ema_long_period=26,
420
+ ema_cross_lookback_window=10
421
+ )
422
+ )
423
+
424
+ # Market credentials for coinbase for both the portfolio connection and data sources will
425
+ # be read from .env file, when not registering a market credential object in the app.
426
+ app.add_market(
427
+ market="bitvavo",
428
+ trading_symbol="EUR",
429
+ )
430
+ backtest_range = BacktestDateRange(
431
+ start_date=datetime(2023, 1, 1, tzinfo=timezone.utc),
432
+ end_date=datetime(2024, 6, 1, tzinfo=timezone.utc)
433
+ )
434
+ backtest = app.run_backtest(
435
+ backtest_date_range=backtest_range, initial_amount=1000
436
+ )
437
+ report = BacktestReport(backtest)
438
+ report.show(backtest_date_range=backtest_range, browser=True)
439
+ ```
440
+
441
+ > You can find more examples [here](./examples) folder.
442
+
443
+ ## ๐Ÿ“š Documentation
444
+ Comprehensive documentation is available at [github pages](https://coding-kitties.github.io/investing-algorithm-framework/).
445
+
446
+ ## ๐Ÿ› ๏ธ Development
447
+
448
+ ### Setup
449
+
450
+ Clone the repository and install dependencies using Poetry:
451
+
452
+ > Make sure you have [Poetry](https://python-poetry.org/docs/#installation) installed.
453
+
454
+ ```bash
455
+ git clone https://github.com/coding-kitties/investing-algorithm-framework.git
456
+ cd investing-algorithm-framework
457
+ poetry install
458
+ ```
459
+
460
+ ### Running Tests
461
+
462
+ ```bash
463
+ # Run all tests
464
+ python -m unittest discover -s tests
465
+
466
+ # Run specific test
467
+ python -m unittest tests.services.test_trade_service.TestTradeService
468
+ ```
469
+
470
+ ## โš ๏ธ Risk Disclaimer
471
+
472
+ ๐Ÿšจ **Use at Your Own Risk**
473
+
474
+ If you use this framework for your investments, **do not risk money which you are afraid to lose** until you have a clear understanding of how the framework works.
475
+
476
+ **BEFORE YOU START USING MONEY WITH THE FRAMEWORK:**
477
+ - โœ… Test your strategies thoroughly with backtesting
478
+ - โœ… Review the source code of any plugins you use
479
+ - โœ… Start with small amounts on paper trading first
480
+ - โœ… Understand the risks involved
481
+
482
+ **We assume no responsibility for your investment results. The authors and all affiliates disclaim any liability for losses.**
483
+
484
+ ---
485
+
486
+ ## ๐Ÿค Contributing
487
+
488
+ The investing algorithm framework is a **community-driven project**. We welcome contributions at all levels:
489
+
490
+ - ๐Ÿ› **Found a bug?** [Open an issue](https://github.com/coding-kitties/investing-algorithm-framework/issues/new)
491
+ - ๐Ÿ’ก **Have an idea?** [Share it with us](https://github.com/coding-kitties/investing-algorithm-framework/issues/new)
492
+ - ๐Ÿ”ง **Want to code?** Check the [project board](https://github.com/coding-kitties/investing-algorithm-framework/projects?query=is%3Aopen)
493
+
494
+ **Guidelines:**
495
+ - Read the [Contributing Guide](https://coding-kitties.github.io/investing-algorithm-framework/Contributing%20Guide/contributing)
496
+ - Always create PRs against the `develop` branch, not `main`
497
+ - Open an issue before starting major feature work
498
+
499
+ ---
500
+
501
+ ## ๐Ÿ“š Documentation
502
+
503
+ Comprehensive documentation is available at [GitHub Pages](https://coding-kitties.github.io/investing-algorithm-framework/)
504
+
505
+ ---
506
+
507
+ ## ๐Ÿ“ฌ Community
508
+
509
+ Join us and connect with other traders and developers:
510
+
511
+ * ๐Ÿ’ฌ [Discord Community](https://discord.gg/dQsRmGZP) โ€” Real-time chat and support
512
+ * ๐Ÿ”— [Reddit Community](https://www.reddit.com/r/InvestingBots/) โ€” Share strategies and discuss
513
+ * ๐Ÿ“– [Documentation](https://coding-kitties.github.io/investing-algorithm-framework/) โ€” Guides and API references
514
+
515
+ ---
516
+
517
+ ## ๐Ÿ† Acknowledgements
518
+
519
+ We want to thank all contributors to this project. A full list can be found in [AUTHORS.md](https://github.com/coding-kitties/investing-algorithm-framework/blob/master/AUTHORS.md)
520
+
521
+ ### Report Issues
522
+
523
+ If you discover a bug in the framework, please [search our issue tracker](https://github.com/coding-kitties/investing-algorithm-framework/issues?q=is%3Aissue) first. If it hasn't been reported, please [create a new issue](https://github.com/coding-kitties/investing-algorithm-framework/issues/new).
524
+
525
+ ---
526
+
527
+ <div align="center">
528
+ <p>
529
+ Made with โค๏ธ by the trading community
530
+ </p>
531
+ <p>
532
+ <a href="https://github.com/coding-kitties/investing-algorithm-framework/stargazers">โญ Star us on GitHub</a> ยท
533
+ <a href="https://discord.gg/dQsRmGZP">๐Ÿ’ฌ Join Discord</a> ยท
534
+ <a href="https://github.com/coding-kitties/investing-algorithm-framework/issues/new">๐Ÿ› Report Bug</a>
535
+ </p>
536
+ </div>
537
+