investing-algorithm-framework 7.16.11__py3-none-any.whl → 7.16.12__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.

@@ -14,7 +14,7 @@ from .domain import ApiException, combine_backtests, PositionSize, \
14
14
  Position, TimeFrame, INDEX_DATETIME, MarketCredential, \
15
15
  PortfolioConfiguration, RESOURCE_DIRECTORY, AWS_LAMBDA_LOGGING_CONFIG, \
16
16
  Trade, SYMBOLS, RESERVED_BALANCES, APP_MODE, AppMode, DATETIME_FORMAT, \
17
- BacktestDateRange, convert_polars_to_pandas, \
17
+ BacktestDateRange, convert_polars_to_pandas, BacktestRun, \
18
18
  DEFAULT_LOGGING_CONFIG, DataType, DataProvider, \
19
19
  TradeStatus, TradeRiskType, generate_backtest_summary_metrics, \
20
20
  APPLICATION_DIRECTORY, DataSource, OrderExecutor, PortfolioProvider, \
@@ -189,4 +189,5 @@ __all__ = [
189
189
  "get_negative_trades",
190
190
  "get_positive_trades",
191
191
  "get_number_of_trades",
192
+ "BacktestRun"
192
193
  ]
@@ -150,23 +150,24 @@ class PortfolioSnapshot(BaseModel):
150
150
  if datetime_format is not None:
151
151
  created_at = self.created_at.strftime(datetime_format) \
152
152
  if self.created_at else None
153
-
154
153
  else:
155
154
  created_at = self.created_at.strftime(DEFAULT_DATETIME_FORMAT)
156
155
 
157
156
  return {
158
- "metadata": self.metadata,
159
- "portfolio_id": self.portfolio_id,
160
- "trading_symbol": self.trading_symbol,
161
- "pending_value": self.pending_value,
162
- "unallocated": self.unallocated,
163
- "total_net_gain": self.total_net_gain,
164
- "total_revenue": self.total_revenue,
165
- "total_cost": self.total_cost,
166
- "cash_flow": self.cash_flow,
167
- "net_size": self.net_size,
168
- "created_at": created_at,
169
- "total_value": self.total_value,
157
+ "metadata": self.metadata if self.metadata else {},
158
+ "portfolio_id": self.portfolio_id if self.portfolio_id else "",
159
+ "trading_symbol": self.trading_symbol
160
+ if self.trading_symbol else "",
161
+ "pending_value": self.pending_value if self.pending_value else 0.0,
162
+ "unallocated": self.unallocated if self.unallocated else 0.0,
163
+ "total_net_gain": self.total_net_gain
164
+ if self.total_net_gain else 0.0,
165
+ "total_revenue": self.total_revenue if self.total_revenue else 0.0,
166
+ "total_cost": self.total_cost if self.total_cost else 0.0,
167
+ "cash_flow": self.cash_flow if self.cash_flow else 0.0,
168
+ "net_size": self.net_size if self.net_size else 0.0,
169
+ "created_at": created_at if created_at else "",
170
+ "total_value": self.total_value if self.total_value else 0.0,
170
171
  }
171
172
 
172
173
  @staticmethod
@@ -283,14 +283,14 @@ class Trade(BaseModel):
283
283
  "trading_symbol": self.trading_symbol,
284
284
  "status": self.status,
285
285
  "amount": self.amount,
286
- "remaining": self.remaining,
286
+ "remaining": self.remaining if self.remaining is not None else 0,
287
287
  "open_price": self.open_price,
288
288
  "last_reported_price": self.last_reported_price,
289
289
  "opened_at": opened_at,
290
290
  "closed_at": closed_at,
291
291
  "updated_at": updated_at,
292
- "net_gain": self.net_gain,
293
- "cost": self.cost,
292
+ "net_gain": self.net_gain if self.net_gain is not None else 0,
293
+ "cost": self.cost if self.cost is not None else 0,
294
294
  "stop_losses": [
295
295
  stop_loss.to_dict(datetime_format=datetime_format)
296
296
  for stop_loss in self.stop_losses
@@ -165,13 +165,19 @@ class BacktestService:
165
165
  portfolio_configurations = []
166
166
  portfolio_configurations.append(
167
167
  PortfolioConfiguration(
168
+ identifier="vector_backtest",
168
169
  market=market,
169
170
  trading_symbol=trading_symbol,
170
171
  initial_balance=initial_amount
171
172
  )
172
173
  )
173
174
 
175
+ portfolio_configuration = portfolio_configurations[0]
176
+
174
177
  trading_symbol = portfolio_configurations[0].trading_symbol
178
+ portfolio = Portfolio.from_portfolio_configuration(
179
+ portfolio_configuration
180
+ )
175
181
 
176
182
  # Load vectorized backtest data
177
183
  data = self._data_provider_service.get_vectorized_backtest_data(
@@ -188,7 +194,9 @@ class BacktestService:
188
194
  index = pd.Index([])
189
195
 
190
196
  most_granular_ohlcv_data_source = \
191
- self._get_most_granular_ohlcv_data_source(strategy.data_sources)
197
+ BacktestService.get_most_granular_ohlcv_data_source(
198
+ strategy.data_sources
199
+ )
192
200
  most_granular_ohlcv_data = self._data_provider_service.get_ohlcv_data(
193
201
  symbol=most_granular_ohlcv_data_source.symbol,
194
202
  start_date=backtest_date_range.start_date,
@@ -212,6 +220,8 @@ class BacktestService:
212
220
  granular_ohlcv_data_order_by_symbol = {}
213
221
  snapshots = [
214
222
  PortfolioSnapshot(
223
+ trading_symbol=trading_symbol,
224
+ portfolio_id=portfolio.identifier,
215
225
  created_at=backtest_date_range.start_date,
216
226
  unallocated=initial_amount,
217
227
  total_value=initial_amount,
@@ -346,7 +356,7 @@ class BacktestService:
346
356
  {
347
357
  "orders": trade_orders,
348
358
  "closed_at": current_date,
349
- "trade_status": TradeStatus.CLOSED,
359
+ "status": TradeStatus.CLOSED,
350
360
  "updated_at": current_date,
351
361
  "net_gain": net_gain_val
352
362
  }
@@ -392,6 +402,7 @@ class BacktestService:
392
402
  # total_net_gain = total_value - initial_amount
393
403
  snapshots.append(
394
404
  PortfolioSnapshot(
405
+ portfolio_id=portfolio.identifier,
395
406
  created_at=interval_datetime,
396
407
  unallocated=unallocated,
397
408
  total_value=unallocated + allocated,
@@ -580,7 +591,7 @@ class BacktestService:
580
591
  )
581
592
 
582
593
  @staticmethod
583
- def _get_most_granular_ohlcv_data_source(data_sources):
594
+ def get_most_granular_ohlcv_data_source(data_sources):
584
595
  """
585
596
  Get the most granular data source from a list of data sources.
586
597
 
@@ -55,6 +55,7 @@ def get_win_rate(trades: List[Trade]) -> float:
55
55
  trades = [
56
56
  trade for trade in trades if TradeStatus.CLOSED.equals(trade.status)
57
57
  ]
58
+ print(len(trades))
58
59
  positive_trades = sum(1 for trade in trades if trade.net_gain > 0)
59
60
  total_trades = len(trades)
60
61
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: investing-algorithm-framework
3
- Version: 7.16.11
3
+ Version: 7.16.12
4
4
  Summary: A framework for creating trading bots
5
5
  Author: MDUYN
6
6
  Requires-Python: >=3.10
@@ -1,4 +1,4 @@
1
- investing_algorithm_framework/__init__.py,sha256=UwHvSZuc4UnjRY7MD4LqaZQFhMl1uiTJXqI8kkvikug,6826
1
+ investing_algorithm_framework/__init__.py,sha256=rYv3eJDD0QbOPXCvK-Ye8oml63MYM_QLqXrt6vFpHk8,6857
2
2
  investing_algorithm_framework/app/__init__.py,sha256=x683g8hvp5yERywt0CFWLavMcTDnCwVVUW_g3o5kyOc,1539
3
3
  investing_algorithm_framework/app/algorithm/__init__.py,sha256=-a9o9bTfAhW9qSW-bKvlLQuMCf-YXxIztudo2TxMjCI,136
4
4
  investing_algorithm_framework/app/algorithm/algorithm.py,sha256=v8AZZ7hr5ZKJbavk242xCUpGHv3mKZ4sqfGV7BwPgdU,6854
@@ -115,7 +115,7 @@ investing_algorithm_framework/domain/models/order/order_type.py,sha256=d0TkR5hjZ
115
115
  investing_algorithm_framework/domain/models/portfolio/__init__.py,sha256=gMMZG6Owvbsq7jL9PhhRbqV8tM9oebGUY8Yc6zedHj4,230
116
116
  investing_algorithm_framework/domain/models/portfolio/portfolio.py,sha256=xUUk9mEwuJLhDPpA6nVmY6AZtFjA1bHrye0mTbAmgUs,5503
117
117
  investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py,sha256=EX3RXeAEGqwZj5oXVCsaYSP7TysRTqLL_9iu5ViW8gE,2737
118
- investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py,sha256=MubaXZrLvIBF82vStYe1VOs5E1Bmde3CzmvGmT1Tow0,6538
118
+ investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py,sha256=w8-nyhGC4ZZzvNv31MkuGGcRQhVsKD2uSknGxVpNSP0,6901
119
119
  investing_algorithm_framework/domain/models/position/__init__.py,sha256=Iv4-DUwgwf521P5qCu6R3WSVZxPeEtGoHP8WsS3qNUU,123
120
120
  investing_algorithm_framework/domain/models/position/position.py,sha256=MSE1hHowJEUF9ljjSeUnvMLU0eLy1gdL6P7cwExzwZM,1575
121
121
  investing_algorithm_framework/domain/models/position/position_snapshot.py,sha256=BpMhUTn--oUVXQHi62uOb4Ac7yuBwHW3iUCFpBPOtW0,1131
@@ -127,7 +127,7 @@ investing_algorithm_framework/domain/models/time_unit.py,sha256=dCi1lcVK-QGlOt6y
127
127
  investing_algorithm_framework/domain/models/tracing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
128
128
  investing_algorithm_framework/domain/models/tracing/trace.py,sha256=iAVEN102-y_7Wj9Qg7kdti8-2I63Y8UG0SF3V2pkHj8,699
129
129
  investing_algorithm_framework/domain/models/trade/__init__.py,sha256=2hX5zmAodsEuFeFghsQhinNobXVuc4oYcMeczY2sbsc,308
130
- investing_algorithm_framework/domain/models/trade/trade.py,sha256=lsiBYs_cJKrSCoprag6hhhL9uGmgi--hBycIPXMLGHM,12855
130
+ investing_algorithm_framework/domain/models/trade/trade.py,sha256=CAOhDEdX6Ot3PlpFWm8kJP47G4t1ceY9hNWhZK-s1D0,12960
131
131
  investing_algorithm_framework/domain/models/trade/trade_risk_type.py,sha256=f-1bOc2GkdphPL3ewPzgsZ5OLX2_fc2e1DVARDl1RRc,839
132
132
  investing_algorithm_framework/domain/models/trade/trade_status.py,sha256=9b5QDwg8vsu_iRtGWatJ1rJFubjIWslKHTG3cK0zVQ4,1004
133
133
  investing_algorithm_framework/domain/models/trade/trade_stop_loss.py,sha256=B9mBALaqOu2VI9v_PTv6C2ZrP6afTEi7seBD8kZi7bw,10366
@@ -202,7 +202,7 @@ investing_algorithm_framework/infrastructure/services/azure/__init__.py,sha256=P
202
202
  investing_algorithm_framework/infrastructure/services/azure/state_handler.py,sha256=EUk4PdVl6RQ19DuWdrC4DzgOhGcL3qiZKWgWh_obT4E,5240
203
203
  investing_algorithm_framework/services/__init__.py,sha256=9p0Y2enp6UMOlU4qJgVoojHBRARLGefNzbPxgSCN0wI,4999
204
204
  investing_algorithm_framework/services/backtesting/__init__.py,sha256=sD6JMQVuUT8NRKV77VC9jyGnHcGox0W2n9eA-4ydeHY,84
205
- investing_algorithm_framework/services/backtesting/backtest_service.py,sha256=jNd3s0qc9_PGMZAKnW0PB8kQ8Mub05n7UMcq2eB1s-8,23707
205
+ investing_algorithm_framework/services/backtesting/backtest_service.py,sha256=cH_LOvDxkPI9rp8ic1eqGqtWYo7EW60nZEfBYwJ50jI,24112
206
206
  investing_algorithm_framework/services/configuration_service.py,sha256=BCgiBlrLjMjfU4afmjYaHu9gOWNmgaxhf6RBN2XJkw0,2853
207
207
  investing_algorithm_framework/services/data_providers/__init__.py,sha256=OHVccpIYGc-1B2AkCI_2Nhsb9KMaAUrng4DHhIbFD8Y,96
208
208
  investing_algorithm_framework/services/data_providers/data_provider_service.py,sha256=Tv5W38rshK7sG7XEhp7L-McdiNWAAlvU_1ScSdt1NCE,28420
@@ -230,7 +230,7 @@ investing_algorithm_framework/services/metrics/treynor_ratio.py,sha256=47DEQpj8H
230
230
  investing_algorithm_framework/services/metrics/ulcer.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
231
231
  investing_algorithm_framework/services/metrics/value_at_risk.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
232
232
  investing_algorithm_framework/services/metrics/volatility.py,sha256=LzeNEkjXrUzzYSWlO8MffJKgFAXY3aaxIH9w4QQKYsc,3275
233
- investing_algorithm_framework/services/metrics/win_rate.py,sha256=9SXI6E7JS7XQY3qVwARhr-Wti2ZKfd1n3yNXxGL1hIY,5794
233
+ investing_algorithm_framework/services/metrics/win_rate.py,sha256=38QK0fFPKs_93PBpdXy48W03Z6eidh_FqTiW9WmAH8g,5817
234
234
  investing_algorithm_framework/services/order_service/__init__.py,sha256=B-9kb7AWnMHCYkT3C7lvUADPWC8uP8cg6ymj3Ngabf0,242
235
235
  investing_algorithm_framework/services/order_service/order_backtest_service.py,sha256=20rVRGSX1IRVRrjCgnM3H7gg4MGZdQconJ9tEE_pZzg,6534
236
236
  investing_algorithm_framework/services/order_service/order_executor_lookup.py,sha256=QNZr-EiKofPGgYHHBESfxdMXGuLOAT8BlufHx92LkoM,3601
@@ -252,8 +252,8 @@ investing_algorithm_framework/services/trade_order_evaluator/default_trade_order
252
252
  investing_algorithm_framework/services/trade_order_evaluator/trade_order_evaluator.py,sha256=pNnmgaKMR9RY6Kxq7xS0nURKoaQDe2ehrP5GfElkkcI,1328
253
253
  investing_algorithm_framework/services/trade_service/__init__.py,sha256=AcwPyJjDRdiREnl_MWMkDSc-V-ZjXtvpHD6eQT9mc1o,68
254
254
  investing_algorithm_framework/services/trade_service/trade_service.py,sha256=OtzIS5EebByGcqDvV2AFeBjXSarvrgubMXDaVKg6Rbw,41193
255
- investing_algorithm_framework-7.16.11.dist-info/LICENSE,sha256=wbVEDvoZiMPHufRY3sLEffvAr7GH5hOIngHF8y4HFQg,11343
256
- investing_algorithm_framework-7.16.11.dist-info/METADATA,sha256=2zYYO7C5y7OYuUwcIVSOdmJVGIanjNbIohwd7c9cl4M,19636
257
- investing_algorithm_framework-7.16.11.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
258
- investing_algorithm_framework-7.16.11.dist-info/entry_points.txt,sha256=jrPF0YksDs27vYzEvj3tXLe3OGWU24EJA05z5xHqmq8,91
259
- investing_algorithm_framework-7.16.11.dist-info/RECORD,,
255
+ investing_algorithm_framework-7.16.12.dist-info/LICENSE,sha256=wbVEDvoZiMPHufRY3sLEffvAr7GH5hOIngHF8y4HFQg,11343
256
+ investing_algorithm_framework-7.16.12.dist-info/METADATA,sha256=eV3a_dZKKHOgbjHf3JY8Mz-qEP14NvvqBY3Fio5eO6c,19636
257
+ investing_algorithm_framework-7.16.12.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
258
+ investing_algorithm_framework-7.16.12.dist-info/entry_points.txt,sha256=jrPF0YksDs27vYzEvj3tXLe3OGWU24EJA05z5xHqmq8,91
259
+ investing_algorithm_framework-7.16.12.dist-info/RECORD,,