1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-11 14:56:55 +08:00

fix analysis bug

This commit is contained in:
Young
2020-09-25 02:47:29 +00:00
parent b2749d2e08
commit 9556d1ce38
11 changed files with 157 additions and 219 deletions

View File

@@ -80,25 +80,6 @@
"positions = pickle.load(estimator_dir.joinpath('positions.pkl').open('rb'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# get label data from qlib"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from qlib.data import D\n",
"pred_df_dates = pred_df.index.get_level_values(level='datetime')\n",
"features_df = D.features(D.instruments(MARKET), ['Ref($close, -1)/$close - 1'], pred_df_dates.min(), pred_df_dates.max())\n",
"features_df.columns = ['label']"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -112,7 +93,9 @@
"metadata": {},
"outputs": [],
"source": [
"from qlib.contrib.report import analysis_model, analysis_position"
"from qlib.data import D\n",
"from qlib.contrib.report import analysis_model, analysis_position\n",
"pred_df_dates = pred_df.index.get_level_values(level='datetime')"
]
},
{
@@ -122,6 +105,16 @@
"## analysis position"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"stock_ret = D.features(D.instruments(MARKET), ['Ref($close, -1)/$close - 1'], pred_df_dates.min(), pred_df_dates.max())\n",
"stock_ret.columns = ['label']"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -138,41 +131,6 @@
"analysis_position.report_graph(report_normal_df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### score IC"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pred_label = pd.concat([features_df, pred_df], axis=1, sort=True).reindex(features_df.index)\n",
"analysis_position.score_ic_graph(pred_label)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### cumulative return"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"analysis_position.cumulative_return_graph(positions, report_normal_df, features_df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -183,9 +141,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"analysis_position.risk_analysis_graph(analysis_df, report_normal_df)"
@@ -195,7 +151,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### rank label"
"## analysis model"
]
},
{
@@ -204,14 +160,25 @@
"metadata": {},
"outputs": [],
"source": [
"analysis_position.rank_label_graph(positions, features_df, pred_df_dates.min(), pred_df_dates.max())"
"label_df = D.features(D.instruments(MARKET), ['Ref($close, -2)/Ref($close, -1) - 1'], pred_df_dates.min(), pred_df_dates.max())\n",
"label_df.columns = ['label']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## analysis model"
"### score IC"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pred_label = pd.concat([label_df, pred_df], axis=1, sort=True).reindex(label_df.index)\n",
"analysis_position.score_ic_graph(pred_label)"
]
},
{
@@ -224,9 +191,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"analysis_model.model_performance_graph(pred_label)"

View File

@@ -62,7 +62,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
@@ -195,7 +194,19 @@
"metadata": {},
"outputs": [],
"source": [
"from qlib.contrib.report import analysis_model, analysis_position"
"from qlib.contrib.report import analysis_model, analysis_position\n",
"from qlib.data import D\n",
"pred_df_dates = pred_score.index.get_level_values(level='datetime')\n",
"report_normal_df = report_normal\n",
"positions = positions_normal\n",
"pred_df = pred_score"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## analysis position"
]
},
{
@@ -204,18 +215,8 @@
"metadata": {},
"outputs": [],
"source": [
"# get label data\n",
"from qlib.data import D\n",
"pred_df_dates = pred_score.index.get_level_values(level='datetime')\n",
"features_df = D.features(D.instruments(MARKET), ['Ref($close, -1)/$close - 1'], pred_df_dates.min(), pred_df_dates.max())\n",
"features_df.columns = ['label']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## analysis position"
"stock_ret = D.features(D.instruments(MARKET), ['Ref($close, -1)/$close - 1'], pred_df_dates.min(), pred_df_dates.max())\n",
"stock_ret.columns = ['label']"
]
},
{
@@ -231,7 +232,40 @@
"metadata": {},
"outputs": [],
"source": [
"analysis_position.report_graph(report_normal)"
"analysis_position.report_graph(report_normal_df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### risk analysis"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"analysis_position.risk_analysis_graph(analysis_df, report_normal_df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## analysis model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"label_df = D.features(D.instruments(MARKET), ['Ref($close, -2)/Ref($close, -1) - 1'], pred_df_dates.min(), pred_df_dates.max())\n",
"label_df.columns = ['label']"
]
},
{
@@ -247,69 +281,10 @@
"metadata": {},
"outputs": [],
"source": [
"pred_label = pd.concat([features_df, pred_score], axis=1, sort=True).reindex(features_df.index)\n",
"pred_label = pd.concat([label_df, pred_df], axis=1, sort=True).reindex(label_df.index)\n",
"analysis_position.score_ic_graph(pred_label)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### cumulative return"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"analysis_position.cumulative_return_graph(positions_normal, report_normal, features_df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### risk analysis"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"analysis_position.risk_analysis_graph(analysis_df, report_normal)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### rank label"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"analysis_position.rank_label_graph(positions_normal, features_df, pred_df_dates.min(), pred_df_dates.max())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## analysis model"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -320,9 +295,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"analysis_model.model_performance_graph(pred_label)"
@@ -344,8 +317,7 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"pygments_lexer": "ipython3"
},
"toc": {
"base_numbering": 1,