|
|
@@ -6,6 +6,7 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
+ "# 安装第三方库\n",
|
|
|
"!pip install hmmlearn mplfinance"
|
|
|
]
|
|
|
},
|
|
|
@@ -476,6 +477,7 @@
|
|
|
}
|
|
|
],
|
|
|
"source": [
|
|
|
+ "# 进行特征提取,得到5日和20日增长率\n",
|
|
|
"data['a_5'] = np.log(data['amount']).diff(-5)\n",
|
|
|
"data['a_20'] = np.log(data['amount']).diff(-20)\n",
|
|
|
"data['r_5'] = np.log(data['close_price']).diff(-5)\n",
|
|
|
@@ -491,6 +493,7 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
+ "# 使用隐马尔可夫模型对数据建模\n",
|
|
|
"cols = ['r_5', 'r_20', 'a_5', 'a_20']\n",
|
|
|
"model = GaussianHMM(n_components=3, covariance_type='full',\n",
|
|
|
" n_iter=1000, random_state=1024)\n",
|
|
|
@@ -535,7 +538,7 @@
|
|
|
}
|
|
|
],
|
|
|
"source": [
|
|
|
- "# 创建一个图形框\n",
|
|
|
+ "# 展示模型结果\n",
|
|
|
"fig = plt.figure(figsize=(12, 8), dpi=80)\n",
|
|
|
"ax0 = fig.add_subplot(4, 1, 1)\n",
|
|
|
"draw_data(ax0, data)\n",
|