Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
F
fof
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dr.李
fof
Commits
6eee2118
Commit
6eee2118
authored
Feb 04, 2022
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added first version of brinson
parent
e41f62d2
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
791 additions
and
234 deletions
+791
-234
010 style attribution.ipynb
attribution/010 style attribution.ipynb
+55
-12
020 brison attribution.ipynb
attribution/020 brison attribution.ipynb
+590
-133
brinson.py
fof/brinson.py
+20
-0
utility.py
fof/utility.py
+126
-89
No files found.
attribution/010 style attribution.ipynb
View file @
6eee2118
...
...
@@ -245,7 +245,7 @@
},
{
"cell_type": "code",
"execution_count":
6
,
"execution_count":
5
,
"id": "c75c33b2-c69e-412c-9151-8f6671c00cec",
"metadata": {},
"outputs": [
...
...
@@ -339,7 +339,7 @@
"[1 rows x 39 columns]"
]
},
"execution_count":
6
,
"execution_count":
5
,
"metadata": {},
"output_type": "execute_result"
}
...
...
@@ -351,7 +351,7 @@
},
{
"cell_type": "code",
"execution_count":
8
,
"execution_count":
6
,
"id": "e06d5836-1e39-47e7-9e1e-3ba77433aa05",
"metadata": {},
"outputs": [
...
...
@@ -384,17 +384,60 @@
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000045</td>\n",
" <td>海信视像</td>\n",
" <td>600060.XSHG</td>\n",
" <td>-1.983</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000121</td>\n",
" <td>中青旅</td>\n",
" <td>600138.XSHG</td>\n",
" <td>-0.743</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000171</td>\n",
" <td>复星医药</td>\n",
" <td>600196.XSHG</td>\n",
" <td>-0.642</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000377</td>\n",
" <td>片仔癀</td>\n",
" <td>600436.XSHG</td>\n",
" <td>-1.400</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000438</td>\n",
" <td>贵州茅台</td>\n",
" <td>600519.XSHG</td>\n",
" <td>-0.835</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
"Empty DataFrame\n",
"Columns: [trade_date, security_code, secShortName, symbol, spret]\n",
"Index: []"
" trade_date security_code secShortName symbol spret\n",
"0 2021-06-30 2010000045 海信视像 600060.XSHG -1.983\n",
"1 2021-06-30 2010000121 中青旅 600138.XSHG -0.743\n",
"2 2021-06-30 2010000171 复星医药 600196.XSHG -0.642\n",
"3 2021-06-30 2010000377 片仔癀 600436.XSHG -1.400\n",
"4 2021-06-30 2010000438 贵州茅台 600519.XSHG -0.835"
]
},
"execution_count":
8
,
"execution_count":
6
,
"metadata": {},
"output_type": "execute_result"
}
...
...
@@ -406,7 +449,7 @@
},
{
"cell_type": "code",
"execution_count":
11
,
"execution_count":
7
,
"id": "48d5bd0f-d33b-4b5e-bc91-b622cba7c0be",
"metadata": {},
"outputs": [
...
...
@@ -612,7 +655,7 @@
"[5 rows x 40 columns]"
]
},
"execution_count":
11
,
"execution_count":
7
,
"metadata": {},
"output_type": "execute_result"
}
...
...
@@ -624,7 +667,7 @@
},
{
"cell_type": "code",
"execution_count":
15
,
"execution_count":
8
,
"id": "88854e5b-ad2e-4629-bb8c-9e58a851a298",
"metadata": {},
"outputs": [
...
...
@@ -710,7 +753,7 @@
"4 2021-06-30 2010000438 贵州茅台 600519.XSHG 24.513"
]
},
"execution_count":
15
,
"execution_count":
8
,
"metadata": {},
"output_type": "execute_result"
}
...
...
@@ -723,7 +766,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "
6102c448-5515-4f1d-ab82-91c0ce98a7ee
",
"id": "
017644bc-3053-4170-89fb-3e87d7ee9339
",
"metadata": {},
"outputs": [],
"source": []
...
...
attribution/020 brison attribution.ipynb
View file @
6eee2118
This diff is collapsed.
Click to expand it.
fof/brinson.py
0 → 100644
View file @
6eee2118
import
pandas
as
pd
def
single_brinson
(
portfolio
,
index_component
,
industry
,
stk_rtns
):
total_df
=
pd
.
merge
(
industry
[[
"security_code"
,
"industry_name"
]],
portfolio
[[
"security_code"
,
"weight"
]],
on
=
[
"security_code"
],
how
=
"left"
)
.
fillna
(
0.0
)
total_df
=
pd
.
merge
(
total_df
,
index_component
[[
"security_code"
,
"weight"
]],
on
=
[
"security_code"
],
how
=
"left"
)
.
fillna
(
0.0
)
total_df
=
pd
.
merge
(
total_df
,
stk_rtns
[[
"security_code"
,
"chg_pct"
]],
on
=
[
"security_code"
],
how
=
"inner"
)
total_df
.
columns
=
[
"security_code"
,
"industry"
,
"portfolio"
,
"benchmark"
,
"chg_pct"
]
total_df
[
"p_ret"
]
=
total_df
[
"portfolio"
]
*
total_df
[
"chg_pct"
]
total_df
[
"b_ret"
]
=
total_df
[
"benchmark"
]
*
total_df
[
"chg_pct"
]
total_df
=
total_df
.
groupby
(
"industry"
)[[
"portfolio"
,
"benchmark"
,
"p_ret"
,
"b_ret"
]]
.
agg
(
"sum"
)
total_df
[
"p_ret"
]
=
total_df
[
"p_ret"
]
/
(
total_df
[
"portfolio"
]
+
1e-16
)
total_df
[
"b_ret"
]
=
total_df
[
"b_ret"
]
/
(
total_df
[
"benchmark"
]
+
1e-16
)
total_df
[
"TR"
]
=
total_df
[
"p_ret"
]
*
total_df
[
"portfolio"
]
-
total_df
[
"b_ret"
]
*
total_df
[
"benchmark"
]
total_df
[
"SR"
]
=
(
total_df
[
"p_ret"
]
-
total_df
[
"b_ret"
])
*
total_df
[
"benchmark"
]
total_df
[
"AR"
]
=
total_df
[
"b_ret"
]
*
(
total_df
[
"portfolio"
]
-
total_df
[
"benchmark"
])
total_df
[
"IR"
]
=
(
total_df
[
"p_ret"
]
-
total_df
[
"b_ret"
])
*
(
total_df
[
"portfolio"
]
-
total_df
[
"benchmark"
])
return
total_df
fof/utility.py
View file @
6eee2118
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment