attrix 0.1.2__tar.gz → 0.1.3__tar.gz
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 attrix might be problematic. Click here for more details.
- {attrix-0.1.2 → attrix-0.1.3}/PKG-INFO +2 -2
- {attrix-0.1.2 → attrix-0.1.3}/README.md +2 -2
- {attrix-0.1.2 → attrix-0.1.3}/setup.cfg +1 -1
- {attrix-0.1.2 → attrix-0.1.3}/src/attrix/AttributionTools.py +20 -6
- {attrix-0.1.2 → attrix-0.1.3}/src/attrix/PortfolioTools.py +17 -10
- {attrix-0.1.2 → attrix-0.1.3}/src/attrix.egg-info/PKG-INFO +2 -2
- {attrix-0.1.2 → attrix-0.1.3}/pyproject.toml +0 -0
- {attrix-0.1.2 → attrix-0.1.3}/src/attrix/DAO.py +0 -0
- {attrix-0.1.2 → attrix-0.1.3}/src/attrix/TSCollector.py +0 -0
- {attrix-0.1.2 → attrix-0.1.3}/src/attrix/__init__.py +0 -0
- {attrix-0.1.2 → attrix-0.1.3}/src/attrix/configs.py +0 -0
- {attrix-0.1.2 → attrix-0.1.3}/src/attrix.egg-info/SOURCES.txt +0 -0
- {attrix-0.1.2 → attrix-0.1.3}/src/attrix.egg-info/dependency_links.txt +0 -0
- {attrix-0.1.2 → attrix-0.1.3}/src/attrix.egg-info/requires.txt +0 -0
- {attrix-0.1.2 → attrix-0.1.3}/src/attrix.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: attrix
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: A tool for portfolio attribution
|
|
5
5
|
Home-page: https://github.com/papasaidfine/attribution
|
|
6
6
|
Author: Larry Chen
|
|
@@ -34,7 +34,7 @@ To access the Wolfe QES risk model and explore a trial, please reach out to [the
|
|
|
34
34
|
|
|
35
35
|
## Installation
|
|
36
36
|
|
|
37
|
-
Install `
|
|
37
|
+
Install `attrix` using `pip`:
|
|
38
38
|
|
|
39
39
|
``` {.sourceCode .bash}
|
|
40
40
|
$ pip install attrix
|
|
@@ -18,7 +18,7 @@ To access the Wolfe QES risk model and explore a trial, please reach out to [the
|
|
|
18
18
|
|
|
19
19
|
## Installation
|
|
20
20
|
|
|
21
|
-
Install `
|
|
21
|
+
Install `attrix` using `pip`:
|
|
22
22
|
|
|
23
23
|
``` {.sourceCode .bash}
|
|
24
24
|
$ pip install attrix
|
|
@@ -115,4 +115,4 @@ p1 = portfolio_ts.load_one(dated)
|
|
|
115
115
|
p1.set_basket_to_keep('ALL')
|
|
116
116
|
a1.change_portfolio_tree(p1)
|
|
117
117
|
a1.get_stock_risk_contri()
|
|
118
|
-
```
|
|
118
|
+
```
|
|
@@ -255,6 +255,7 @@ class AttributionData:
|
|
|
255
255
|
self.H, self.index_H = portfolio.H, portfolio.index_H
|
|
256
256
|
self.h, self.index_h = portfolio.h, portfolio.index_h
|
|
257
257
|
self.etf_ids = portfolio.get_etf_ids()
|
|
258
|
+
self.user_basket_ids = portfolio.get_user_basket_ids()
|
|
258
259
|
self._init_data(rmd)
|
|
259
260
|
|
|
260
261
|
def _init_data(self, rmd):
|
|
@@ -316,19 +317,25 @@ class AttributionData:
|
|
|
316
317
|
|
|
317
318
|
def _init_idm(self, rmd):
|
|
318
319
|
index_H = self.index_H
|
|
319
|
-
|
|
320
|
+
etf_ids = self.etf_ids
|
|
321
|
+
user_basket_ids = self.user_basket_ids
|
|
320
322
|
|
|
323
|
+
logging.debug('Reserve meta data for stocks')
|
|
321
324
|
idm = rmd.get('idm')
|
|
322
325
|
meta = idm.columns # TODO: meta columns customization
|
|
323
326
|
idm = idm.loc[index_H, meta]
|
|
324
327
|
|
|
325
|
-
|
|
328
|
+
logging.debug('Reserve meta data for ETFs')
|
|
329
|
+
etf_idm = pd.DataFrame(index=etf_ids, columns=meta)
|
|
326
330
|
if 'comp_idm' in rmd.keys():
|
|
327
331
|
comp_idm = rmd.get('comp_idm')
|
|
328
|
-
comp_ids = list(set(
|
|
329
|
-
|
|
332
|
+
comp_ids = list(set(etf_ids) & set(comp_idm.index))
|
|
333
|
+
etf_idm.loc[comp_ids, :] = comp_idm.loc[comp_ids, :].values
|
|
334
|
+
|
|
335
|
+
logging.debug('Reserve meta data for user baskets')
|
|
336
|
+
user_basket_idm = pd.DataFrame(index=user_basket_ids, columns=meta)
|
|
330
337
|
|
|
331
|
-
idm = pd.concat([idm,
|
|
338
|
+
idm = pd.concat([idm, etf_idm, user_basket_idm], axis=0)
|
|
332
339
|
self.idm = idm
|
|
333
340
|
|
|
334
341
|
def _init_r(self):
|
|
@@ -415,7 +422,11 @@ class AttributionOne:
|
|
|
415
422
|
@property
|
|
416
423
|
def group_names(self):
|
|
417
424
|
return self.data.group_names
|
|
418
|
-
|
|
425
|
+
|
|
426
|
+
@property
|
|
427
|
+
def idm(self):
|
|
428
|
+
return self.data.idm
|
|
429
|
+
|
|
419
430
|
def _get_full_headers(self):
|
|
420
431
|
factor_alias, group_names = self.factor_alias, self.group_names
|
|
421
432
|
return factor_alias + group_names + ["Systematic", "Residual", "Total"]
|
|
@@ -423,6 +434,9 @@ class AttributionOne:
|
|
|
423
434
|
def _init_core(self):
|
|
424
435
|
self.core = AttributionCore(
|
|
425
436
|
self.h, self.E, self.Gamma, self.Lambda, self.f, self.r, self.G)
|
|
437
|
+
|
|
438
|
+
def get_stock_master(self):
|
|
439
|
+
return self.idm.loc[self.index_h,:]
|
|
426
440
|
|
|
427
441
|
def get_stock_exposure_contri(self):
|
|
428
442
|
return pd.DataFrame(self.core.stock_exposure_contri.todense(), index=self.index_h, columns=self.factor_alias)
|
|
@@ -94,15 +94,14 @@ class PortfolioOne:
|
|
|
94
94
|
if config is not None:
|
|
95
95
|
config_.update(config)
|
|
96
96
|
self.config = config_
|
|
97
|
-
# SecurityDAO(self.config.get('security_dao_config'))
|
|
98
97
|
self.security_dao = security_dao
|
|
99
|
-
self.etf_dao = etf_dao
|
|
98
|
+
self.etf_dao = etf_dao
|
|
100
99
|
self.data = self.security_dao.map(data)
|
|
101
100
|
self._init_weight()
|
|
102
101
|
|
|
103
102
|
def _get_weight_one(self, df):
|
|
104
103
|
"""
|
|
105
|
-
Get a weight
|
|
104
|
+
Get a weight pd.Series for one user portfolio/basket.
|
|
106
105
|
"""
|
|
107
106
|
config = self.security_dao.config
|
|
108
107
|
id_col, weight_col = config.get('id_col'), config.get('weight_col')
|
|
@@ -110,21 +109,30 @@ class PortfolioOne:
|
|
|
110
109
|
|
|
111
110
|
def _get_weight_list(self):
|
|
112
111
|
"""
|
|
113
|
-
Get the weight dict for
|
|
112
|
+
Get the weight dict for all user portfolios/baskets.
|
|
114
113
|
"""
|
|
115
114
|
data = self.data
|
|
116
115
|
config = self.security_dao.config
|
|
117
|
-
|
|
118
|
-
'id_col'), config.get('portfolio_col')
|
|
116
|
+
portfolio_col = config.get('portfolio_col')
|
|
119
117
|
portfolios = list(data[portfolio_col].unique())
|
|
120
118
|
return {p: self._get_weight_one(data[data[portfolio_col] == p]) for p in portfolios}
|
|
121
119
|
|
|
122
120
|
def get_portfolio_weight_list(self):
|
|
121
|
+
"""Get the weight dict for all user portfolios/baskets (cached).
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
dict: Dictionary of weight pd.Series
|
|
125
|
+
"""
|
|
123
126
|
if self.portfolio_weight_list is None:
|
|
124
127
|
self.portfolio_weight_list = self._get_weight_list()
|
|
125
128
|
return self.portfolio_weight_list
|
|
126
129
|
|
|
127
130
|
def get_etf_weight_list(self):
|
|
131
|
+
"""Get the weight dict for ETFs (cached).
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
dict: Dictionary of weight pd.Series
|
|
135
|
+
"""
|
|
128
136
|
if self.etf_weight_list is None:
|
|
129
137
|
config = self.security_dao.config
|
|
130
138
|
time_col, id_col = config.get("time_col"), config.get("id_col")
|
|
@@ -136,7 +144,7 @@ class PortfolioOne:
|
|
|
136
144
|
return self.etf_weight_list
|
|
137
145
|
|
|
138
146
|
def get_weight_list(self):
|
|
139
|
-
weight_list = self.get_portfolio_weight_list()
|
|
147
|
+
weight_list = self.get_portfolio_weight_list().copy()
|
|
140
148
|
weight_list.update(self.get_etf_weight_list())
|
|
141
149
|
return weight_list
|
|
142
150
|
|
|
@@ -149,8 +157,7 @@ class PortfolioOne:
|
|
|
149
157
|
return self.get_portfolio_weight_list().get(root)
|
|
150
158
|
|
|
151
159
|
def get_user_basket_ids(self):
|
|
152
|
-
"""
|
|
153
|
-
Get user basket ids excluding root portfolio
|
|
160
|
+
"""Get user basket ids excluding root portfolio
|
|
154
161
|
|
|
155
162
|
Returns:
|
|
156
163
|
list: user basket ids
|
|
@@ -236,7 +243,7 @@ class PortfolioTS(TSCollector):
|
|
|
236
243
|
"path": "portfolio_data",
|
|
237
244
|
"meta_file": None,
|
|
238
245
|
"root_portfolio": "Main",
|
|
239
|
-
"basket_to_keep": ["
|
|
246
|
+
"basket_to_keep": ["ETF"],
|
|
240
247
|
"security_dao_config": {},
|
|
241
248
|
"etf_dao_config": {}
|
|
242
249
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: attrix
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: A tool for portfolio attribution
|
|
5
5
|
Home-page: https://github.com/papasaidfine/attribution
|
|
6
6
|
Author: Larry Chen
|
|
@@ -34,7 +34,7 @@ To access the Wolfe QES risk model and explore a trial, please reach out to [the
|
|
|
34
34
|
|
|
35
35
|
## Installation
|
|
36
36
|
|
|
37
|
-
Install `
|
|
37
|
+
Install `attrix` using `pip`:
|
|
38
38
|
|
|
39
39
|
``` {.sourceCode .bash}
|
|
40
40
|
$ pip install attrix
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|