Commit 7477fbf4 authored by Dr.李's avatar Dr.李

update constraints settings

parent f1cfc9db
...@@ -74,7 +74,7 @@ def er_portfolio_analysis(er: np.ndarray, ...@@ -74,7 +74,7 @@ def er_portfolio_analysis(er: np.ndarray,
lbound = kwargs['lbound'].copy() lbound = kwargs['lbound'].copy()
del kwargs['lbound'] del kwargs['lbound']
else: else:
lbound = 0. lbound = np.maximum(0., benchmark - 0.01)
if 'ubound' in kwargs: if 'ubound' in kwargs:
ubound = kwargs['ubound'].copy() ubound = kwargs['ubound'].copy()
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%matplotlib inline\n", "%matplotlib inline\n",
...@@ -25,23 +27,26 @@ ...@@ -25,23 +27,26 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"#factors = ['RVOL', 'EPS', 'DROEAfterNonRecurring', 'DivP', 'CFinc1', 'BDTO']\n", "#factors = ['RVOL', 'EPS', 'DROEAfterNonRecurring', 'DivP', 'CFinc1', 'BDTO']\n",
"#factor_weights = np.array([0.05, 0.3, 0.35, 0.075, 0.15, 0.05])\n", "#factor_weights = np.array([0.05, 0.3, 0.35, 0.075, 0.15, 0.05])\n",
"\n", "\n",
"factors = ['VAL', 'RVOL', 'ROEDiluted', 'GREV', 'EPS', 'CHV', 'CFinc1', 'BDTO']\n", "factors = alpha_factors = {\n",
"factor_weights = np.array([0.034129344,\n", " 'eps': LAST('eps_q'),\n",
" 0.015881607,\n", " 'roe': LAST('roe_q'),\n",
" 0.048765746,\n", " 'bdto': LAST('BDTO'),\n",
" 0.042747382,\n", " 'cfinc1': LAST('CFinc1'),\n",
" -0.015900173,\n", " 'chv': LAST('CHV'),\n",
" 0.019044573,\n", " 'rvol': LAST('RVOL'),\n",
" -0.001792638,\n", " 'val': LAST('VAL'),\n",
" 0.014277867,\n", " 'grev': LAST('GREV'),\n",
" ])\n", " 'droeafternonorecurring': LAST('DROEAfterNonRecurring')\n",
"}\n",
"\n",
"factor_weights = np.array([])\n",
"\n", "\n",
"engine = SqlEngine()\n", "engine = SqlEngine()\n",
"universe = Universe('custom', ['zz500'])\n", "universe = Universe('custom', ['zz500'])\n",
...@@ -63,13 +68,15 @@ ...@@ -63,13 +68,15 @@
"else:\n", "else:\n",
" raise ValueError(\"Unrecognized freq: {0}\".format(freq))\n", " raise ValueError(\"Unrecognized freq: {0}\".format(freq))\n",
" \n", " \n",
"dates = makeSchedule('2012-01-01', '2017-09-19', tenor=freq, calendar='china.sse', dateGenerationRule=DateGeneration.Backward)" "dates = makeSchedule('2012-01-01', '2017-11-02', tenor=freq, calendar='china.sse', dateGenerationRule=DateGeneration.Backward)"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"all_data = engine.fetch_data_range(universe, factors, dates=dates, benchmark=905)\n", "all_data = engine.fetch_data_range(universe, factors, dates=dates, benchmark=905)\n",
...@@ -88,7 +95,9 @@ ...@@ -88,7 +95,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"rets = []\n", "rets = []\n",
...@@ -149,7 +158,9 @@ ...@@ -149,7 +158,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"ret_df = pd.DataFrame({'returns': rets, 'turn_over': turn_overs}, index=dates)\n", "ret_df = pd.DataFrame({'returns': rets, 'turn_over': turn_overs}, index=dates)\n",
...@@ -162,7 +173,9 @@ ...@@ -162,7 +173,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"ret_df[['returns', 'tc_cost']].cumsum().plot(figsize=(12, 6), title='Fixed frequency rebalanced: {0}'.format(freq), secondary_y='tc_cost')" "ret_df[['returns', 'tc_cost']].cumsum().plot(figsize=(12, 6), title='Fixed frequency rebalanced: {0}'.format(freq), secondary_y='tc_cost')"
...@@ -218,7 +231,9 @@ ...@@ -218,7 +231,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"rets = []\n", "rets = []\n",
...@@ -285,7 +300,9 @@ ...@@ -285,7 +300,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"ret_df = pd.DataFrame({'returns': rets, 'turn_over': turn_overs}, index=dates)\n", "ret_df = pd.DataFrame({'returns': rets, 'turn_over': turn_overs}, index=dates)\n",
...@@ -298,7 +315,9 @@ ...@@ -298,7 +315,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"ret_df[['returns', 'tc_cost']].cumsum().plot(figsize=(12, 6),\n", "ret_df[['returns', 'tc_cost']].cumsum().plot(figsize=(12, 6),\n",
...@@ -333,7 +352,7 @@ ...@@ -333,7 +352,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.2" "version": "3.6.3"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
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