wbportfolio 1.49.2__py2.py3-none-any.whl → 1.49.4__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/filters/transactions/claim.py +40 -22
- wbportfolio/filters/transactions/trades.py +9 -1
- wbportfolio/rebalancing/models/market_capitalization_weighted.py +20 -13
- wbportfolio/viewsets/transactions/claim.py +15 -1
- {wbportfolio-1.49.2.dist-info → wbportfolio-1.49.4.dist-info}/METADATA +1 -1
- {wbportfolio-1.49.2.dist-info → wbportfolio-1.49.4.dist-info}/RECORD +8 -8
- {wbportfolio-1.49.2.dist-info → wbportfolio-1.49.4.dist-info}/WHEEL +0 -0
- {wbportfolio-1.49.2.dist-info → wbportfolio-1.49.4.dist-info}/licenses/LICENSE +0 -0
|
@@ -9,7 +9,7 @@ from wbfdm.models import Classification, ClassificationGroup
|
|
|
9
9
|
from wbfdm.preferences import get_default_classification_group
|
|
10
10
|
|
|
11
11
|
from wbportfolio.filters.transactions.mixins import OppositeSharesFieldMethodMixin
|
|
12
|
-
from wbportfolio.models import Product, ProductGroup
|
|
12
|
+
from wbportfolio.models import Custodian, Product, ProductGroup, Register
|
|
13
13
|
from wbportfolio.models.transactions.claim import Claim, ClaimGroupbyChoice
|
|
14
14
|
from wbportfolio.preferences import get_monthly_nnm_target
|
|
15
15
|
|
|
@@ -61,15 +61,13 @@ class CommissionBaseFilterSet(wb_filters.FilterSet):
|
|
|
61
61
|
|
|
62
62
|
product = wb_filters.ModelMultipleChoiceFilter(
|
|
63
63
|
label="Product",
|
|
64
|
-
method="filter_product",
|
|
65
64
|
queryset=Product.objects.all(),
|
|
66
65
|
endpoint=Product.get_representation_endpoint(),
|
|
67
66
|
value_key=Product.get_representation_value_key(),
|
|
68
67
|
label_key=Product.get_representation_label_key(),
|
|
69
68
|
)
|
|
70
|
-
|
|
69
|
+
product__parent = wb_filters.ModelMultipleChoiceFilter(
|
|
71
70
|
label="Product Group",
|
|
72
|
-
method="filter_productgroup",
|
|
73
71
|
queryset=ProductGroup.objects.all(),
|
|
74
72
|
endpoint=ProductGroup.get_representation_endpoint(),
|
|
75
73
|
value_key=ProductGroup.get_representation_value_key(),
|
|
@@ -95,14 +93,13 @@ class CommissionBaseFilterSet(wb_filters.FilterSet):
|
|
|
95
93
|
method="filter_manager_role",
|
|
96
94
|
)
|
|
97
95
|
|
|
98
|
-
|
|
99
|
-
label="
|
|
96
|
+
product__classifications = wb_filters.ModelMultipleChoiceFilter(
|
|
97
|
+
label="Classifications",
|
|
100
98
|
queryset=Classification.objects.all(),
|
|
101
99
|
endpoint=Classification.get_representation_endpoint(),
|
|
102
100
|
value_key=Classification.get_representation_value_key(),
|
|
103
101
|
label_key=Classification.get_representation_label_key(),
|
|
104
102
|
filter_params={"instrument_type_key": "product"},
|
|
105
|
-
method="filter_classification",
|
|
106
103
|
)
|
|
107
104
|
|
|
108
105
|
def filter_account(self, queryset, name, value):
|
|
@@ -110,16 +107,6 @@ class CommissionBaseFilterSet(wb_filters.FilterSet):
|
|
|
110
107
|
return queryset.filter(account__in=value.get_descendants(include_self=True).values("id"))
|
|
111
108
|
return queryset
|
|
112
109
|
|
|
113
|
-
def filter_product(self, queryset, name, value):
|
|
114
|
-
if value:
|
|
115
|
-
return queryset.filter(product__in=value)
|
|
116
|
-
return queryset
|
|
117
|
-
|
|
118
|
-
def filter_productgroup(self, queryset, name, value):
|
|
119
|
-
if value:
|
|
120
|
-
return queryset.filter(product__parent=value)
|
|
121
|
-
return queryset
|
|
122
|
-
|
|
123
110
|
def filter_account_owner(self, queryset, name, value):
|
|
124
111
|
if value:
|
|
125
112
|
return queryset.filter(account__in=Account.get_accounts_for_customer(value))
|
|
@@ -135,11 +122,6 @@ class CommissionBaseFilterSet(wb_filters.FilterSet):
|
|
|
135
122
|
return queryset.filter(account__in=Account.get_managed_accounts_for_entry(value).values("id"))
|
|
136
123
|
return queryset
|
|
137
124
|
|
|
138
|
-
def filter_classification(self, queryset, name, value):
|
|
139
|
-
if value:
|
|
140
|
-
return queryset.filter(product__classifications=value)
|
|
141
|
-
return queryset
|
|
142
|
-
|
|
143
125
|
|
|
144
126
|
class ClaimFilter(OppositeSharesFieldMethodMixin, CommissionBaseFilterSet):
|
|
145
127
|
# we have to redefine the mixin fields because django_filters does not allow class extension with mixin
|
|
@@ -169,6 +151,42 @@ class ClaimFilter(OppositeSharesFieldMethodMixin, CommissionBaseFilterSet):
|
|
|
169
151
|
label_key=Person.get_representation_label_key(),
|
|
170
152
|
)
|
|
171
153
|
|
|
154
|
+
# Trade related filter fields
|
|
155
|
+
trade__custodian = wb_filters.ModelChoiceFilter(
|
|
156
|
+
label="Trade Custodian",
|
|
157
|
+
queryset=Custodian.objects.all(),
|
|
158
|
+
endpoint=Custodian.get_representation_endpoint(),
|
|
159
|
+
value_key=Custodian.get_representation_value_key(),
|
|
160
|
+
label_key=Custodian.get_representation_label_key(),
|
|
161
|
+
)
|
|
162
|
+
trade__register = wb_filters.ModelChoiceFilter(
|
|
163
|
+
label="Trade Register",
|
|
164
|
+
queryset=Register.objects.all(),
|
|
165
|
+
endpoint=Register.get_representation_endpoint(),
|
|
166
|
+
value_key=Register.get_representation_value_key(),
|
|
167
|
+
label_key=Register.get_representation_label_key(),
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
trade_comment = wb_filters.CharFilter(lookup_expr="icontains", label="Trade Comment")
|
|
171
|
+
|
|
172
|
+
last_nav = wb_filters.NumberFilter(field_name="last_nav", lookup_expr="exact", label="Last Nav")
|
|
173
|
+
last_nav__lte = wb_filters.NumberFilter(field_name="last_nav", lookup_expr="lte", label="Last Nav")
|
|
174
|
+
last_nav__gte = wb_filters.NumberFilter(field_name="last_nav", lookup_expr="gte", label="Last Nav")
|
|
175
|
+
|
|
176
|
+
total_value = wb_filters.NumberFilter(field_name="total_value", lookup_expr="exact", label="Total Value")
|
|
177
|
+
total_value__lte = wb_filters.NumberFilter(field_name="total_value", lookup_expr="lte", label="Total Value")
|
|
178
|
+
total_value__gte = wb_filters.NumberFilter(field_name="total_value", lookup_expr="gte", label="Total Value")
|
|
179
|
+
|
|
180
|
+
total_value_usd = wb_filters.NumberFilter(
|
|
181
|
+
field_name="total_value_usd", lookup_expr="exact", label="Total Value (USD)"
|
|
182
|
+
)
|
|
183
|
+
total_value_usd__lte = wb_filters.NumberFilter(
|
|
184
|
+
field_name="total_value_usd", lookup_expr="lte", label="Total Value (USD)"
|
|
185
|
+
)
|
|
186
|
+
total_value_usd__gte = wb_filters.NumberFilter(
|
|
187
|
+
field_name="total_value_usd", lookup_expr="gte", label="Total Value (USD)"
|
|
188
|
+
)
|
|
189
|
+
|
|
172
190
|
def filter_in_charge_of_customer(self, queryset, name, value):
|
|
173
191
|
if value:
|
|
174
192
|
return queryset.filter(
|
|
@@ -3,7 +3,7 @@ from datetime import timedelta
|
|
|
3
3
|
from django.db.models import Count, OuterRef, Subquery
|
|
4
4
|
from wbcore import filters as wb_filters
|
|
5
5
|
from wbcrm.models.accounts import Account
|
|
6
|
-
from wbfdm.models import Instrument
|
|
6
|
+
from wbfdm.models import Classification, Instrument
|
|
7
7
|
|
|
8
8
|
from wbportfolio.models import Product, Trade
|
|
9
9
|
from wbportfolio.models.transactions.claim import Claim
|
|
@@ -175,6 +175,14 @@ class SubscriptionRedemptionFilterSet(TradeFilter):
|
|
|
175
175
|
value_key=Product.get_representation_value_key(),
|
|
176
176
|
label_key=Product.get_representation_label_key(),
|
|
177
177
|
)
|
|
178
|
+
underlying_instrument__classifications = wb_filters.ModelMultipleChoiceFilter(
|
|
179
|
+
label="Classifications",
|
|
180
|
+
queryset=Classification.objects.all(),
|
|
181
|
+
endpoint=Classification.get_representation_endpoint(),
|
|
182
|
+
value_key=Classification.get_representation_value_key(),
|
|
183
|
+
label_key=Classification.get_representation_label_key(),
|
|
184
|
+
filter_params={"instrument_type_key": "product"},
|
|
185
|
+
)
|
|
178
186
|
|
|
179
187
|
class Meta:
|
|
180
188
|
model = Trade
|
|
@@ -3,6 +3,7 @@ from decimal import Decimal
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
import pandas as pd
|
|
5
5
|
from django.db.models import QuerySet
|
|
6
|
+
from pandas._libs.tslibs.offsets import BDay
|
|
6
7
|
from wbfdm.enums import MarketData
|
|
7
8
|
from wbfdm.models import (
|
|
8
9
|
Classification,
|
|
@@ -20,13 +21,15 @@ from wbportfolio.rebalancing.decorators import register
|
|
|
20
21
|
class MarketCapitalizationRebalancing(AbstractRebalancingModel):
|
|
21
22
|
TARGET_CURRENCY: str = "USD"
|
|
22
23
|
|
|
23
|
-
def __init__(self, *args, **kwargs):
|
|
24
|
+
def __init__(self, *args, bypass_exchange_check: bool = False, ffill_market_cap_limit: int = 5, **kwargs):
|
|
24
25
|
super().__init__(*args, **kwargs)
|
|
26
|
+
self.bypass_exchange_check = bypass_exchange_check
|
|
25
27
|
instruments = self._get_instruments(**kwargs)
|
|
26
28
|
self.market_cap_df = pd.DataFrame(
|
|
27
29
|
instruments.dl.market_data(
|
|
28
30
|
values=[MarketData.MARKET_CAPITALIZATION],
|
|
29
|
-
|
|
31
|
+
from_date=self.trade_date - BDay(ffill_market_cap_limit),
|
|
32
|
+
to_date=self.trade_date,
|
|
30
33
|
target_currency=self.TARGET_CURRENCY,
|
|
31
34
|
)
|
|
32
35
|
)
|
|
@@ -38,11 +41,11 @@ class MarketCapitalizationRebalancing(AbstractRebalancingModel):
|
|
|
38
41
|
instrument_ids = list(instruments.values_list("id", flat=True))
|
|
39
42
|
try:
|
|
40
43
|
self.market_cap_df = (
|
|
41
|
-
self.market_cap_df
|
|
42
|
-
.
|
|
43
|
-
.
|
|
44
|
+
self.market_cap_df.sort_values(by="valuation_date")
|
|
45
|
+
.groupby("instrument_id")
|
|
46
|
+
.last()["market_capitalization"]
|
|
44
47
|
)
|
|
45
|
-
self.market_cap_df = self.market_cap_df
|
|
48
|
+
self.market_cap_df = self.market_cap_df.reindex(instrument_ids)
|
|
46
49
|
except (IndexError, KeyError):
|
|
47
50
|
self.market_cap_df = pd.Series(dtype="float64", index=instrument_ids)
|
|
48
51
|
|
|
@@ -92,13 +95,17 @@ class MarketCapitalizationRebalancing(AbstractRebalancingModel):
|
|
|
92
95
|
) # if we are missing any market cap for not-delisted instrument, we consider the rebalancing not valid
|
|
93
96
|
df = df.groupby("exchange", dropna=False)["market_capitalization"].any()
|
|
94
97
|
missing_exchanges = Exchange.objects.filter(id__in=df[~df].index.to_list())
|
|
95
|
-
if
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
# if bypass exchange check is true, we do not care whether an exchange is closed we just care if there are at least one exchange open
|
|
99
|
+
if self.bypass_exchange_check:
|
|
100
|
+
return df.any()
|
|
101
|
+
else:
|
|
102
|
+
if missing_exchanges.exists():
|
|
103
|
+
setattr(
|
|
104
|
+
self,
|
|
105
|
+
"_validation_errors",
|
|
106
|
+
f"Couldn't find any market capitalization for exchanges {', '.join([str(e) for e in missing_exchanges])}",
|
|
107
|
+
)
|
|
108
|
+
return df.all()
|
|
102
109
|
return False
|
|
103
110
|
|
|
104
111
|
def get_target_portfolio(self) -> Portfolio:
|
|
@@ -150,8 +150,22 @@ class ClaimModelViewSet(ClaimPermissionMixin, wb_viewsets.ModelViewSet):
|
|
|
150
150
|
"product__isin",
|
|
151
151
|
"bank",
|
|
152
152
|
"account__title",
|
|
153
|
+
"trade_comment",
|
|
153
154
|
]
|
|
154
|
-
ordering_fields = (
|
|
155
|
+
ordering_fields = (
|
|
156
|
+
"date",
|
|
157
|
+
"product__name",
|
|
158
|
+
"claimant",
|
|
159
|
+
"account__title",
|
|
160
|
+
"trade_comment",
|
|
161
|
+
"shares",
|
|
162
|
+
"last_nav",
|
|
163
|
+
"total_value",
|
|
164
|
+
"total_value_usd",
|
|
165
|
+
"bank",
|
|
166
|
+
"creator",
|
|
167
|
+
"reference",
|
|
168
|
+
)
|
|
155
169
|
ordering = ["id", "-date"]
|
|
156
170
|
|
|
157
171
|
display_config_class = ClaimDisplayConfig
|
|
@@ -86,10 +86,10 @@ wbportfolio/filters/products.py,sha256=_QFL3I132q-3JUDji_Wh2Qkv45DKnQrR3N8_luGK0
|
|
|
86
86
|
wbportfolio/filters/roles.py,sha256=-0tOl-WJDqwXAfcJePpkjQfZB9o13I99euem5XGpMjk,920
|
|
87
87
|
wbportfolio/filters/signals.py,sha256=3GrsxPwZg-6bvvZ222VfF212yNTJYQP4n5hWIEnTtpA,3144
|
|
88
88
|
wbportfolio/filters/transactions/__init__.py,sha256=WHAwqZLRTAS46lLscGJYtKYWyEknsY5MqeSD0ue1r-o,662
|
|
89
|
-
wbportfolio/filters/transactions/claim.py,sha256=
|
|
89
|
+
wbportfolio/filters/transactions/claim.py,sha256=GqWSFNro_bmUwVOLhsQEjV1kGHzQ_1iJBvmSRoCWCU8,17913
|
|
90
90
|
wbportfolio/filters/transactions/fees.py,sha256=4EDmwgianx0iIIaIx7XgEjRDPI9nqBUq1zL1FpdtYAg,2134
|
|
91
91
|
wbportfolio/filters/transactions/mixins.py,sha256=TEV3MUsiQTeu4NdFYHMIIMonmC7CdFF80JTpWYIvfRQ,550
|
|
92
|
-
wbportfolio/filters/transactions/trades.py,sha256=
|
|
92
|
+
wbportfolio/filters/transactions/trades.py,sha256=wq39DQwKpSioNwcQkHQ8ydDklZRPonUiXUH7NzTJCEs,9778
|
|
93
93
|
wbportfolio/filters/transactions/transactions.py,sha256=TQNusdKIit_JKWFRVk3JERmHd4YvxLq-NiyEShJ_eDI,3538
|
|
94
94
|
wbportfolio/fixtures/product_factsheets.yaml,sha256=z5o-viDbgwWkssDJXZYayasFgw1nJ0uiOiYrJNDkRtg,5455
|
|
95
95
|
wbportfolio/fixtures/wbportfolio.yaml.gz,sha256=902nxQZM6VcVcc0wI9AYaSedcJIfsK5letLF31j1Jdg,1479453
|
|
@@ -292,7 +292,7 @@ wbportfolio/rebalancing/decorators.py,sha256=JhQ2vkcIuGBTGvNmpkQerdw2-vLq-RAb0KA
|
|
|
292
292
|
wbportfolio/rebalancing/models/__init__.py,sha256=AQjG7Tu5vlmhqncVoYOjpBKU2UIvgo9FuP2_jD2w-UI,232
|
|
293
293
|
wbportfolio/rebalancing/models/composite.py,sha256=uyF1n3NAFprnAZ3Gl5pNJl0GajelqJspC2NufZ7Tf0s,1636
|
|
294
294
|
wbportfolio/rebalancing/models/equally_weighted.py,sha256=U29MOHJMQMIg7Y7W_8t5K3nXjaznzt4ArIxQSiv0Xok,863
|
|
295
|
-
wbportfolio/rebalancing/models/market_capitalization_weighted.py,sha256=
|
|
295
|
+
wbportfolio/rebalancing/models/market_capitalization_weighted.py,sha256=6ZsR8iJg6l89CsxHqoxJSXlTaj8Pmb8_bFPrXhnxaRs,5295
|
|
296
296
|
wbportfolio/rebalancing/models/model_portfolio.py,sha256=XQdvs03-0M9YUnL4DidwZC4E6k-ANCNcZ--T_aaOXTQ,1233
|
|
297
297
|
wbportfolio/reports/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
298
298
|
wbportfolio/reports/monthly_position_report.py,sha256=e7BzjDd6eseUOwLwQJXKvWErQ58YnCsznHU2VtR6izM,2981
|
|
@@ -514,14 +514,14 @@ wbportfolio/viewsets/configs/titles/roles.py,sha256=9LoJa3jgenXJ5UWRlIErTzdbjpSW
|
|
|
514
514
|
wbportfolio/viewsets/configs/titles/trades.py,sha256=29XCLxvY0Xe3a2tjCno3tN2rRXCr9RWpbWnzurJfnYI,1986
|
|
515
515
|
wbportfolio/viewsets/configs/titles/transactions.py,sha256=Pq9yCbEkSwidXSNsqFzQIcBuofLCSxKQNhWYZJtQ-Tg,328
|
|
516
516
|
wbportfolio/viewsets/transactions/__init__.py,sha256=rJOaLqiVCzRW8zqxDC1ZIDQpfhSqT-OcVUPJeiqXATc,1294
|
|
517
|
-
wbportfolio/viewsets/transactions/claim.py,sha256=
|
|
517
|
+
wbportfolio/viewsets/transactions/claim.py,sha256=IzVvCwx2g2XoX8aXzpd7bv7wb1lxbUbmn5Vn9tJ_KXM,38974
|
|
518
518
|
wbportfolio/viewsets/transactions/fees.py,sha256=7VUXIogmRrXCz_D9tvDiiTae0t5j09W9zPUzxXzBGTE,7031
|
|
519
519
|
wbportfolio/viewsets/transactions/mixins.py,sha256=WipvJoi5hylkpD0y9VATe30WAcwIHUIroVkK10FYw7k,636
|
|
520
520
|
wbportfolio/viewsets/transactions/rebalancing.py,sha256=6rIrdK0rtKL1afJ-tYfAGdQVTN2MH1kG_yCeVkmyK8k,1263
|
|
521
521
|
wbportfolio/viewsets/transactions/trade_proposals.py,sha256=iQpC_Thbj56SmM05vPRsF1JZguGBDaTUH3I-_iCHCV0,5958
|
|
522
522
|
wbportfolio/viewsets/transactions/trades.py,sha256=xeEzx7GP34aBNPlDmiUmT86labsbb8_f1U2RCN1Jatg,21494
|
|
523
523
|
wbportfolio/viewsets/transactions/transactions.py,sha256=ixDp-nsNA8t_A06rBCT19hOMJHy0iRmdz1XKdV1OwAs,4450
|
|
524
|
-
wbportfolio-1.49.
|
|
525
|
-
wbportfolio-1.49.
|
|
526
|
-
wbportfolio-1.49.
|
|
527
|
-
wbportfolio-1.49.
|
|
524
|
+
wbportfolio-1.49.4.dist-info/METADATA,sha256=smy-QwtXQoL-BxaKxICXFKvRxjhBiYcuJ-zwR7b36AM,734
|
|
525
|
+
wbportfolio-1.49.4.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
|
|
526
|
+
wbportfolio-1.49.4.dist-info/licenses/LICENSE,sha256=jvfVH0SY8_YMHlsJHKe_OajiscQDz4lpTlqT6x24sVw,172
|
|
527
|
+
wbportfolio-1.49.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|