{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import xalpha as xa\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 多基金或指数的综合分析"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"sz50, hs300, zz500, cyb = (\n",
" xa.indexinfo(\"0000016\"),\n",
" xa.indexinfo(\"0000300\"),\n",
" xa.indexinfo(\"0000905\"),\n",
" xa.indexinfo(\"1399006\"),\n",
")\n",
"# 四个基本指数的数据获取"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"comparison = xa.evaluate(sz50, hs300, zz500, cyb)\n",
"# 综合分析,未指定 start 参数的化,比较的开始时间默认为最新的指数的开始时间"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" date | \n",
" 0000016 | \n",
" 0000300 | \n",
" 0000905 | \n",
" 1399006 | \n",
"
\n",
" \n",
" \n",
" \n",
" 1987 | \n",
" 2018-08-02 | \n",
" 1.276693 | \n",
" 1.228411 | \n",
" 1.241002 | \n",
" 1.551620 | \n",
"
\n",
" \n",
" 1988 | \n",
" 2018-08-03 | \n",
" 1.262668 | \n",
" 1.208123 | \n",
" 1.224543 | \n",
" 1.522355 | \n",
"
\n",
" \n",
" 1989 | \n",
" 2018-08-06 | \n",
" 1.259023 | \n",
" 1.192813 | \n",
" 1.198585 | \n",
" 1.480422 | \n",
"
\n",
" \n",
" 1990 | \n",
" 2018-08-07 | \n",
" 1.297341 | \n",
" 1.227650 | \n",
" 1.231280 | \n",
" 1.520130 | \n",
"
\n",
" \n",
" 1991 | \n",
" 2018-08-08 | \n",
" 1.280191 | \n",
" 1.207840 | \n",
" 1.212326 | \n",
" 1.487575 | \n",
"
\n",
" \n",
" 1992 | \n",
" 2018-08-09 | \n",
" 1.310335 | \n",
" 1.238094 | \n",
" 1.243178 | \n",
" 1.538795 | \n",
"
\n",
" \n",
" 1993 | \n",
" 2018-08-10 | \n",
" 1.309597 | \n",
" 1.240823 | \n",
" 1.249572 | \n",
" 1.553284 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" date 0000016 0000300 0000905 1399006\n",
"1987 2018-08-02 1.276693 1.228411 1.241002 1.551620\n",
"1988 2018-08-03 1.262668 1.208123 1.224543 1.522355\n",
"1989 2018-08-06 1.259023 1.192813 1.198585 1.480422\n",
"1990 2018-08-07 1.297341 1.227650 1.231280 1.520130\n",
"1991 2018-08-08 1.280191 1.207840 1.212326 1.487575\n",
"1992 2018-08-09 1.310335 1.238094 1.243178 1.538795\n",
"1993 2018-08-10 1.309597 1.240823 1.249572 1.553284"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"comparison.totprice[comparison.totprice[\"date\"] > \"2018-08-01\"] # 这一类的核心数据,是归一化过的净值表"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"comparison.v_netvalue() # 指数起点归一化净值的变动情况,神创威武"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"comparison.v_correlation() # 指数之间的相关系数,创业板比较独立"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 0000016 | \n",
" 0000300 | \n",
" 0000905 | \n",
" 1399006 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0000016 | \n",
" 1.000000 | \n",
" 0.943797 | \n",
" 0.656125 | \n",
" 0.466339 | \n",
"
\n",
" \n",
" 0000300 | \n",
" 0.943797 | \n",
" 1.000000 | \n",
" 0.849873 | \n",
" 0.670656 | \n",
"
\n",
" \n",
" 0000905 | \n",
" 0.656125 | \n",
" 0.849873 | \n",
" 1.000000 | \n",
" 0.881827 | \n",
"
\n",
" \n",
" 1399006 | \n",
" 0.466339 | \n",
" 0.670656 | \n",
" 0.881827 | \n",
" 1.000000 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 0000016 0000300 0000905 1399006\n",
"0000016 1.000000 0.943797 0.656125 0.466339\n",
"0000300 0.943797 1.000000 0.849873 0.670656\n",
"0000905 0.656125 0.849873 1.000000 0.881827\n",
"1399006 0.466339 0.670656 0.881827 1.000000"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"comparison.correlation_table() # 嫌图花哨可以直接看相关系数的数据"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}