wbportfolio 1.46.6__py2.py3-none-any.whl → 1.46.7__py2.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 wbportfolio might be problematic. Click here for more details.
- wbportfolio/rebalancing/models/market_capitalization_weighted.py +11 -14
- wbportfolio/tests/rebalancing/test_models.py +7 -8
- {wbportfolio-1.46.6.dist-info → wbportfolio-1.46.7.dist-info}/METADATA +1 -1
- {wbportfolio-1.46.6.dist-info → wbportfolio-1.46.7.dist-info}/RECORD +6 -6
- {wbportfolio-1.46.6.dist-info → wbportfolio-1.46.7.dist-info}/WHEEL +0 -0
- {wbportfolio-1.46.6.dist-info → wbportfolio-1.46.7.dist-info}/licenses/LICENSE +0 -0
|
@@ -26,21 +26,22 @@ class MarketCapitalizationRebalancing(AbstractRebalancingModel):
|
|
|
26
26
|
self.market_cap_df = pd.DataFrame(
|
|
27
27
|
instruments.dl.market_data(
|
|
28
28
|
values=[MarketData.MARKET_CAPITALIZATION],
|
|
29
|
-
|
|
30
|
-
to_date=self.trade_date,
|
|
29
|
+
exact_date=self.last_effective_date,
|
|
31
30
|
target_currency=self.TARGET_CURRENCY,
|
|
32
31
|
)
|
|
33
32
|
)
|
|
34
33
|
self.exchange_df = pd.DataFrame(
|
|
35
34
|
instruments.values_list("id", "exchange"), columns=["id", "exchange"]
|
|
36
35
|
).set_index("id")
|
|
36
|
+
instrument_ids = list(instruments.values_list("id", flat=True))
|
|
37
37
|
try:
|
|
38
|
-
self.market_cap_df =
|
|
39
|
-
["
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
self.market_cap_df = (
|
|
39
|
+
self.market_cap_df[["market_capitalization", "instrument_id"]]
|
|
40
|
+
.set_index("instrument_id")["market_capitalization"]
|
|
41
|
+
.reindex(instrument_ids)
|
|
42
|
+
)
|
|
42
43
|
except (IndexError, KeyError):
|
|
43
|
-
self.market_cap_df = pd.
|
|
44
|
+
self.market_cap_df = pd.Series(dtype="float64", index=instrument_ids)
|
|
44
45
|
|
|
45
46
|
def _get_instruments(
|
|
46
47
|
self,
|
|
@@ -90,11 +91,8 @@ class MarketCapitalizationRebalancing(AbstractRebalancingModel):
|
|
|
90
91
|
|
|
91
92
|
def is_valid(self) -> bool:
|
|
92
93
|
if not self.market_cap_df.empty:
|
|
93
|
-
trade_date_mktp_cap = (
|
|
94
|
-
self.market_cap_df.loc[self.trade_date, :].transpose().rename("market_capitalization")
|
|
95
|
-
)
|
|
96
94
|
df = pd.concat(
|
|
97
|
-
[
|
|
95
|
+
[self.market_cap_df, self.exchange_df], axis=1
|
|
98
96
|
) # if we are missing any market cap for not-delisted instrument, we consider the rebalancing not valid
|
|
99
97
|
df = df.groupby("exchange", dropna=False)["market_capitalization"].any()
|
|
100
98
|
missing_exchanges = Exchange.objects.filter(id__in=df[~df].index.to_list())
|
|
@@ -109,10 +107,9 @@ class MarketCapitalizationRebalancing(AbstractRebalancingModel):
|
|
|
109
107
|
|
|
110
108
|
def get_target_portfolio(self) -> Portfolio:
|
|
111
109
|
positions = []
|
|
112
|
-
|
|
113
|
-
total_market_cap = market_cap_df.sum()
|
|
110
|
+
total_market_cap = self.market_cap_df.sum()
|
|
114
111
|
|
|
115
|
-
for underlying_instrument, market_cap in market_cap_df.to_dict().items():
|
|
112
|
+
for underlying_instrument, market_cap in self.market_cap_df.to_dict().items():
|
|
116
113
|
positions.append(
|
|
117
114
|
Position(
|
|
118
115
|
underlying_instrument=underlying_instrument,
|
|
@@ -139,20 +139,19 @@ class TestMarketCapitalizationRebalancing:
|
|
|
139
139
|
i1 = instrument_factory()
|
|
140
140
|
i2 = instrument_factory()
|
|
141
141
|
instrument_price_factory.create(instrument=i1, date=last_effective_date)
|
|
142
|
-
instrument_price_factory.create(instrument=
|
|
143
|
-
instrument_price_factory.create(instrument=i2, date=last_effective_date) # weekday is ffill
|
|
142
|
+
instrument_price_factory.create(instrument=i2, date=last_effective_date)
|
|
144
143
|
return MarketCapitalizationRebalancing(portfolio, weekday, last_effective_date, instrument_ids=[i1.id, i2.id])
|
|
145
144
|
|
|
146
145
|
def test_is_valid(self, portfolio, weekday, model, instrument_factory, instrument_price_factory):
|
|
147
|
-
assert not model.is_valid()
|
|
148
|
-
i2 = model.market_cap_df.columns[1]
|
|
149
|
-
model.market_cap_df.loc[weekday, i2] = 1000 # some value
|
|
150
146
|
assert model.is_valid()
|
|
147
|
+
i2 = model.market_cap_df.index[1]
|
|
148
|
+
model.market_cap_df.loc[i2] = None # some value
|
|
149
|
+
assert not model.is_valid()
|
|
151
150
|
|
|
152
151
|
def test_get_target_portfolio(self, portfolio, weekday, model, asset_position_factory):
|
|
153
|
-
i1 = model.market_cap_df.
|
|
154
|
-
i2 = model.market_cap_df.
|
|
155
|
-
mkt12 = InstrumentPrice.objects.get(instrument_id=i1, date=model.
|
|
152
|
+
i1 = model.market_cap_df.index[0]
|
|
153
|
+
i2 = model.market_cap_df.index[1]
|
|
154
|
+
mkt12 = InstrumentPrice.objects.get(instrument_id=i1, date=model.last_effective_date).market_capitalization
|
|
156
155
|
mkt21 = InstrumentPrice.objects.get(instrument_id=i2, date=model.last_effective_date).market_capitalization
|
|
157
156
|
|
|
158
157
|
target_portfolio = model.get_target_portfolio()
|
|
@@ -289,7 +289,7 @@ wbportfolio/rebalancing/decorators.py,sha256=JhQ2vkcIuGBTGvNmpkQerdw2-vLq-RAb0KA
|
|
|
289
289
|
wbportfolio/rebalancing/models/__init__.py,sha256=AQjG7Tu5vlmhqncVoYOjpBKU2UIvgo9FuP2_jD2w-UI,232
|
|
290
290
|
wbportfolio/rebalancing/models/composite.py,sha256=XAjJqLRNsV-MuBKrat3THEfAWs6PXQNSO0g8k8MtBXo,1157
|
|
291
291
|
wbportfolio/rebalancing/models/equally_weighted.py,sha256=U29MOHJMQMIg7Y7W_8t5K3nXjaznzt4ArIxQSiv0Xok,863
|
|
292
|
-
wbportfolio/rebalancing/models/market_capitalization_weighted.py,sha256=
|
|
292
|
+
wbportfolio/rebalancing/models/market_capitalization_weighted.py,sha256=RTEVAwOh7ec5MqCFYd-9lSNv4eNhchD1aAyEnJeyZwQ,4825
|
|
293
293
|
wbportfolio/rebalancing/models/model_portfolio.py,sha256=XQdvs03-0M9YUnL4DidwZC4E6k-ANCNcZ--T_aaOXTQ,1233
|
|
294
294
|
wbportfolio/reports/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
295
295
|
wbportfolio/reports/monthly_position_report.py,sha256=e7BzjDd6eseUOwLwQJXKvWErQ58YnCsznHU2VtR6izM,2981
|
|
@@ -385,7 +385,7 @@ wbportfolio/tests/models/transactions/test_trades.py,sha256=z0CCZjB648ECDSEdwmzq
|
|
|
385
385
|
wbportfolio/tests/pms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
386
386
|
wbportfolio/tests/pms/test_analytics.py,sha256=FrvVsV_uUiTgmRUfsaB-_sGzY30CqknbOY2DvmwR_70,1141
|
|
387
387
|
wbportfolio/tests/rebalancing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
388
|
-
wbportfolio/tests/rebalancing/test_models.py,sha256=
|
|
388
|
+
wbportfolio/tests/rebalancing/test_models.py,sha256=wdlCfc6YxVT0oLxr45Q-LPKy4LjGbylkdxcfZozS0Fk,7565
|
|
389
389
|
wbportfolio/tests/serializers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
390
390
|
wbportfolio/tests/serializers/test_claims.py,sha256=vQrg73xQXRFEgvx3KI9ivFre_wpBFzdO0p0J13PkvdY,582
|
|
391
391
|
wbportfolio/tests/viewsets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -517,7 +517,7 @@ wbportfolio/viewsets/transactions/rebalancing.py,sha256=6rIrdK0rtKL1afJ-tYfAGdQV
|
|
|
517
517
|
wbportfolio/viewsets/transactions/trade_proposals.py,sha256=gXdJJ00D6UavZfBczvZQb5cYPQlU6-xOg_-TnMBzEO0,4742
|
|
518
518
|
wbportfolio/viewsets/transactions/trades.py,sha256=mo5b1wFm0twvGVp-CYnzpGLYMqPcHN8GjH4G_WwFFwc,16237
|
|
519
519
|
wbportfolio/viewsets/transactions/transactions.py,sha256=ixDp-nsNA8t_A06rBCT19hOMJHy0iRmdz1XKdV1OwAs,4450
|
|
520
|
-
wbportfolio-1.46.
|
|
521
|
-
wbportfolio-1.46.
|
|
522
|
-
wbportfolio-1.46.
|
|
523
|
-
wbportfolio-1.46.
|
|
520
|
+
wbportfolio-1.46.7.dist-info/METADATA,sha256=nAZz3VADXG2Z3fYmWJ3oqXrVIQa1HAaUtMQpX3e-V68,734
|
|
521
|
+
wbportfolio-1.46.7.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
|
|
522
|
+
wbportfolio-1.46.7.dist-info/licenses/LICENSE,sha256=jvfVH0SY8_YMHlsJHKe_OajiscQDz4lpTlqT6x24sVw,172
|
|
523
|
+
wbportfolio-1.46.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|