Commit 058b7552 authored by Dr.李's avatar Dr.李

update example

parent 070d867a
...@@ -118,13 +118,6 @@ ...@@ -118,13 +118,6 @@
"df[['factor', 'abs t.']].groupby('factor').mean().sort_values('abs t.', ascending=False).head()" "df[['factor', 'abs t.']].groupby('factor').mean().sort_values('abs t.', ascending=False).head()"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -68,17 +68,6 @@ ...@@ -68,17 +68,6 @@
"special_risk = factor['srisk'].values" "special_risk = factor['srisk'].values"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sec_cov = risk_exposure @ risk_cov @ risk_exposure.T / 10000 + np.diag(special_risk ** 2) / 10000\n",
"sec_cov_df = pd.DataFrame(sec_cov, index=codes, columns=codes)\n",
"sec_cov_df.iloc[:5, :5]"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
...@@ -92,7 +81,7 @@ ...@@ -92,7 +81,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -103,16 +92,29 @@ ...@@ -103,16 +92,29 @@
"cons_mat = np.ones((len(er), 1))\n", "cons_mat = np.ones((len(er), 1))\n",
"risk_targets = (bm.sum(), bm.sum())\n", "risk_targets = (bm.sum(), bm.sum())\n",
"target_vol = 0.025\n", "target_vol = 0.025\n",
"risk_model = dict(cov=None, factor_cov=risk_cov/10000, factor_loading=risk_exposure, idsync=special_risk ** 2 / 10000.)\n",
"\n", "\n",
"status, p_er, p_weight = \\\n", "status, p_er, p_weight = \\\n",
" target_vol_builder(er, sec_cov, bm, lbound, ubound, cons_mat, risk_targets, target_vol, target_vol)" " target_vol_builder(er, risk_model, bm, lbound, ubound, cons_mat, risk_targets, target_vol)\n",
" \n",
"sec_cov = risk_exposure @ risk_cov @ risk_exposure.T / 10000. + np.diag(special_risk ** 2) / 10000"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"total weight is 1.0000\n",
"portfolio activate weight forecasting vol is 0.0250\n",
"portfolio er: 2.2232 comparing with benchmark er: 1.2359\n"
]
}
],
"source": [ "source": [
"# check the result\n", "# check the result\n",
"print(f\"total weight is {p_weight.sum(): .4f}\")\n", "print(f\"total weight is {p_weight.sum(): .4f}\")\n",
...@@ -130,7 +132,7 @@ ...@@ -130,7 +132,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -157,7 +159,7 @@ ...@@ -157,7 +159,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -182,7 +184,7 @@ ...@@ -182,7 +184,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -217,7 +219,7 @@ ...@@ -217,7 +219,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment