请 [注册] 或 [登录]  | 返回主站

量化交易吧 /  数理科学 帖子:3364680 新帖:1

“行为金融学”预测结果分析1(更新: 2019/03/

美联储发表于:5 月 9 日 20:14回复(1)

2019/03/17: 观察了两周,没发现改数据 .  哪位大神会设计股指期货回测?

__biz=MzU2NDQ3NTI0OA==&mid=2247484082&idx=1&sn=c6dc788316ebc3ad7394bdc9415f8a47&chksm=f*b26adcb3cafbbf5*82bd341af8f9523f34b37caa88b1d8bce3c0232ca77d4700328a6610&token=1279847976?=zh_CN#rd

2019/02/28:

最近在读“行为金融学”方面的书, 对这方面比较感兴趣,也经常在网上和微信上查资料。 发现“行为金融学”方面的做法和量化界不同, 他们好像是通过互联网的问卷调查预测行情。 拿到问卷调查后怎么研究得出预测的就不太清楚了。就公布的预测结果来看,似乎挺有效。 在这篇文章里我把公布的预测结果拿到平台上来跑跑回测,分析一把:

1.预测结果获取
几个问卷调查预测网站里,找了下面这个预测中证500指数的。把网页下载下来存盘,上传聚宽的研究空间。

__biz=MzU2NDQ3NTI0OA==&mid=2247484048&idx=1&sn=d9cce02378d2fffbfa9069dd4b1fbb54&chksm=f*b268fcb3caf997d154171c06af4b7a822e45f5974421de036117a1916daa03da76e4aef3d&mpshare=1&scene=1&srcid=0228RGlUtu20VHHaBu2Ju9Mk&pass_ticket=GPnK4NUJ2KY/evQtBkBl9WzAjcv/XVNE0EcGOlagl2OgBVNmmWuLJT9keb5ktgja#rd

1.1写几行Python把HTML 文件内的Table读进来转成  dataframe

1.2还不知道怎么在回测空间内读文件。简单点,把dataframe 先转成JSON ,然后手工copy到回测代码里,如下:
Img
2.回测
以中证500指数000905.XSHG 为基准,按预测值每天开盘买卖000905.XSHG。 回测结果:

import pandas as pdwith open("../duyi.htm", "r") as f:s = f.read()df=pd.read_html(s)[0]df=df.set_index(df.columns[0]).sort_index()df['op']=0df.loc[df['操作']=='做多', 'op']=1df.loc[df['操作']=='做空', 'op']=-1df=df[['op']]s=df.to_json()print(s)
{"op":{"2016-11-01":0,"2016-11-02":0,"2016-11-03":0,"2016-11-04":1,"2016-11-07":-1,"2016-11-08":0,"2016-11-09":0,"2016-11-10":0,"2016-11-11":1,"2016-11-14":1,"2016-11-15":0,"2016-11-16":0,"2016-11-17":-1,"2016-11-18":0,"2016-11-21":0,"2016-11-22":0,"2016-11-23":0,"2016-11-24":0,"2016-11-25":0,"2016-11-28":1,"2016-11-29":-1,"2016-11-30":0,"2016-12-01":0,"2016-12-02":0,"2016-12-05":0,"2016-12-06":0,"2016-12-07":-1,"2016-12-08":0,"2016-12-09":-1,"2016-12-12":0,"2016-12-13":0,"2016-12-14":0,"2016-12-15":0,"2016-12-16":0,"2016-12-19":0,"2016-12-20":0,"2016-12-21":0,"2016-12-22":0,"2016-12-23":-1,"2016-12-26":-1,"2016-12-27":1,"2016-12-28":-1,"2016-12-29":0,"2016-12-30":1,"2017-01-03":1,"2017-01-04":1,"2017-01-05":0,"2017-01-06":-1,"2017-01-09":0,"2017-01-10":-1,"2017-01-11":-1,"2017-01-12":0,"2017-01-13":-1,"2017-01-16":-1,"2017-01-17":0,"2017-01-18":0,"2017-01-19":0,"2017-01-20":0,"2017-01-23":1,"2017-01-24":0,"2017-01-25":-1,"2017-01-26":0,"2017-02-03":-1,"2017-02-06":-1,"2017-02-07":0,"2017-02-08":-1,"2017-02-09":0,"2017-02-10":1,"2017-02-13":1,"2017-02-14":0,"2017-02-15":-1,"2017-02-16":1,"2017-02-17":0,"2017-02-20":1,"2017-02-21":1,"2017-02-22":0,"2017-02-23":0,"2017-02-24":0,"2017-02-27":-1,"2017-02-28":1,"2017-03-01":0,"2017-03-02":-1,"2017-03-03":0,"2017-03-06":0,"2017-03-07":0,"2017-03-08":0,"2017-03-09":0,"2017-03-10":0,"2017-03-13":-1,"2017-03-14":0,"2017-03-15":-1,"2017-03-16":-1,"2017-03-17":0,"2017-03-20":1,"2017-03-21":1,"2017-03-22":0,"2017-03-23":0,"2017-03-24":0,"2017-03-27":0,"2017-03-28":0,"2017-03-29":0,"2017-03-30":-1,"2017-03-31":0,"2017-04-05":1,"2017-04-06":0,"2017-04-07":0,"2017-04-10":-1,"2017-04-11":0,"2017-04-12":1,"2017-04-13":0,"2017-04-14":0,"2017-04-17":0,"2017-04-18":0,"2017-04-19":-1,"2017-04-20":0,"2017-04-21":0,"2017-04-24":-1,"2017-04-25":-1,"2017-04-26":1,"2017-04-27":-1,"2017-04-28":-1,"2017-05-02":-1,"2017-05-03":-1,"2017-05-04":-1,"2017-05-05":-1,"2017-05-08":-1,"2017-05-09":0,"2017-05-10":1,"2017-05-11":0,"2017-05-12":1,"2017-05-15":0,"2017-05-16":0,"2017-05-17":0,"2017-05-18":-1,"2017-05-19":-1,"2017-05-22":-1,"2017-05-23":-1,"2017-05-24":0,"2017-05-25":1,"2017-05-26":1,"2017-05-31":-1,"2017-06-01":-1,"2017-06-02":0,"2017-06-05":0,"2017-06-06":0,"2017-06-07":1,"2017-06-08":1,"2017-06-09":0,"2017-06-12":0,"2017-06-13":1,"2017-06-14":0,"2017-06-15":0,"2017-06-16":1,"2017-06-19":-1,"2017-06-20":0,"2017-06-21":0,"2017-06-22":0,"2017-06-23":1,"2017-06-26":1,"2017-06-27":1,"2017-06-28":-1,"2017-06-29":0,"2017-06-30":-1,"2017-07-03":-1,"2017-07-04":-1,"2017-07-05":-1,"2017-07-06":1,"2017-07-07":-1,"2017-07-10":0,"2017-07-11":0,"2017-07-12":0,"2017-07-13":-1,"2017-07-14":-1,"2017-07-17":-1,"2017-07-18":0,"2017-07-19":1,"2017-07-20":0,"2017-07-21":-1,"2017-07-24":-1,"2017-07-25":-1,"2017-07-26":0,"2017-07-27":-1,"2017-07-28":0,"2017-07-31":-1,"2017-08-01":0,"2017-08-02":0,"2017-08-03":1,"2017-08-04":0,"2017-08-07":0,"2017-08-08":0,"2017-08-09":-1,"2017-08-10":-1,"2017-08-11":0,"2017-08-14":0,"2017-08-15":1,"2017-08-16":0,"2017-08-17":0,"2017-08-18":0,"2017-08-21":-1,"2017-08-22":-1,"2017-08-23":-1,"2017-08-24":-1,"2017-08-25":-1,"2017-08-28":0,"2017-08-29":0,"2017-08-30":-1,"2017-08-31":-1,"2017-09-01":-1,"2017-09-04":-1,"2017-09-05":-1,"2017-09-06":-1,"2017-09-07":-1,"2017-09-08":1,"2017-09-11":0,"2017-09-12":0,"2017-09-13":0,"2017-09-14":0,"2017-09-15":0,"2017-09-18":0,"2017-09-19":0,"2017-09-20":0,"2017-09-21":0,"2017-09-22":0,"2017-09-25":0,"2017-09-26":0,"2017-09-27":0,"2017-09-28":0,"2017-09-29":0,"2017-10-09":1,"2017-10-10":1,"2017-10-11":1,"2017-10-12":0,"2017-10-13":0,"2017-10-16":-1,"2017-10-17":0,"2017-10-18":1,"2017-10-19":-1,"2017-10-20":-1,"2017-10-23":0,"2017-10-24":0,"2017-10-25":1,"2017-10-26":0,"2017-10-27":0,"2017-10-30":-1,"2017-10-31":0,"2017-11-01":0,"2017-11-02":-1,"2017-11-03":-1,"2017-11-06":-1,"2017-11-07":1,"2017-11-08":1,"2017-11-09":0,"2017-11-10":0,"2017-11-13":0,"2017-11-14":0,"2017-11-15":1,"2017-11-16":0,"2017-11-17":0,"2017-11-20":-1,"2017-11-21":1,"2017-11-22":0,"2017-11-23":0,"2017-11-24":0,"2017-11-27":0,"2017-11-28":-1,"2017-11-29":1,"2017-11-30":-1,"2017-12-01":-1,"2017-12-04":0,"2017-12-05":-1,"2017-12-06":0,"2017-12-07":0,"2017-12-08":-1,"2017-12-11":0,"2017-12-12":0,"2017-12-13":-1,"2017-12-14":0,"2017-12-15":-1,"2017-12-18":-1,"2017-12-19":0,"2017-12-20":1,"2017-12-21":-1,"2017-12-22":1,"2017-12-25":-1,"2017-12-26":-1,"2017-12-27":1,"2017-12-28":-1,"2017-12-29":1,"2018-01-02":0,"2018-01-03":1,"2018-01-04":1,"2018-01-05":0,"2018-01-08":0,"2018-01-09":-1,"2018-01-10":-1,"2018-01-11":0,"2018-01-12":0,"2018-01-15":-1,"2018-01-16":1,"2018-01-17":1,"2018-01-18":-1,"2018-01-19":0,"2018-01-22":-1,"2018-01-23":0,"2018-01-24":0,"2018-01-25":0,"2018-01-26":0,"2018-01-29":-1,"2018-01-30":0,"2018-01-31":0,"2018-02-01":-1,"2018-02-02":-1,"2018-02-05":-1,"2018-02-06":-1,"2018-02-07":0,"2018-02-08":0,"2018-02-09":-1,"2018-02-12":0,"2018-02-13":0,"2018-02-14":-1,"2018-02-22":0,"2018-02-23":-1,"2018-02-26":-1,"2018-02-27":-1,"2018-02-28":-1,"2018-03-01":-1,"2018-03-02":-1,"2018-03-05":0,"2018-03-06":-1,"2018-03-07":0,"2018-03-08":0,"2018-03-09":0,"2018-03-12":0,"2018-03-13":0,"2018-03-14":0,"2018-03-15":0,"2018-03-16":-1,"2018-03-19":0,"2018-03-20":0,"2018-03-21":0,"2018-03-22":-1,"2018-03-23":0,"2018-03-26":0,"2018-03-27":0,"2018-03-28":-1,"2018-03-29":-1,"2018-03-30":0,"2018-04-02":-1,"2018-04-03":-1,"2018-04-04":-1,"2018-04-09":-1,"2018-04-10":0,"2018-04-11":0,"2018-04-12":-1,"2018-04-13":-1,"2018-04-16":-1,"2018-04-17":-1,"2018-04-18":-1,"2018-04-19":0,"2018-04-20":0,"2018-04-23":-1,"2018-04-24":0,"2018-04-25":1,"2018-04-26":-1,"2018-04-27":-1,"2018-05-02":1,"2018-05-03":0,"2018-05-04":1,"2018-05-07":-1,"2018-05-08":1,"2018-05-09":0,"2018-05-10":-1,"2018-05-11":-1,"2018-05-14":0,"2018-05-15":0,"2018-05-16":0,"2018-05-17":0,"2018-05-18":1,"2018-05-21":1,"2018-05-22":1,"2018-05-23":0,"2018-05-24":1,"2018-05-25":0,"2018-05-28":-1,"2018-05-29":-1,"2018-05-30":-1,"2018-05-31":-1,"2018-06-01":-1,"2018-06-04":-1,"2018-06-05":0,"2018-06-06":-1,"2018-06-07":-1,"2018-06-08":-1,"2018-06-11":-1,"2018-06-12":-1,"2018-06-13":0,"2018-06-14":-1,"2018-06-15":-1,"2018-06-19":-1,"2018-06-20":0,"2018-06-21":-1,"2018-06-22":0,"2018-06-25":0,"2018-06-26":0,"2018-06-27":1,"2018-06-28":0,"2018-06-29":1,"2018-07-02":1,"2018-07-03":-1,"2018-07-04":1,"2018-07-05":0,"2018-07-06":1,"2018-07-09":1,"2018-07-10":1,"2018-07-11":0,"2018-07-12":1,"2018-07-13":1,"2018-07-16":-1,"2018-07-17":-1,"2018-07-18":-1,"2018-07-19":-1,"2018-07-20":0,"2018-07-23":1,"2018-07-24":1,"2018-07-25":1,"2018-07-26":-1,"2018-07-27":1,"2018-07-30":0,"2018-07-31":1,"2018-08-01":0,"2018-08-02":0,"2018-08-03":0,"2018-08-06":1,"2018-08-07":1,"2018-08-08":1,"2018-08-09":0,"2018-08-10":1,"2018-08-13":0,"2018-08-14":0,"2018-08-15":-1,"2018-08-16":-1,"2018-08-17":0,"2018-08-20":-1,"2018-08-21":1,"2018-08-22":1,"2018-08-23":-1,"2018-08-24":0,"2018-08-27":-1,"2018-08-28":1,"2018-08-29":-1,"2018-08-30":0,"2018-08-31":-1,"2018-09-03":-1,"2018-09-04":0,"2018-09-05":1,"2018-09-06":-1,"2018-09-07":0,"2018-09-10":1,"2018-09-11":0,"2018-09-12":1,"2018-09-13":1,"2018-09-14":1,"2018-09-17":0,"2018-09-18":0,"2018-09-19":1,"2018-09-20":1,"2018-09-21":0,"2018-09-25":1,"2018-09-26":0,"2018-09-27":-1,"2018-09-28":1,"2018-10-08":0,"2018-10-09":0,"2018-10-10":0,"2018-10-11":-1,"2018-10-12":0,"2018-10-15":-1,"2018-10-16":0,"2018-10-17":1,"2018-10-18":1,"2018-10-19":1,"2018-10-22":1,"2018-10-23":0,"2018-10-24":0,"2018-10-25":0,"2018-10-26":-1,"2018-10-29":-1,"2018-10-30":-1,"2018-10-31":1,"2018-11-01":1,"2018-11-02":0,"2018-11-05":0,"2018-11-06":0,"2018-11-07":0,"2018-11-08":0,"2018-11-09":0,"2018-11-12":0,"2018-11-13":1,"2018-11-14":1,"2018-11-15":1,"2018-11-16":0,"2018-11-19":0,"2018-11-20":0,"2018-11-21":1,"2018-11-22":0,"2018-11-23":0,"2018-11-26":1,"2018-11-27":0,"2018-11-28":0,"2018-11-29":1,"2018-11-30":0,"2018-12-03":1,"2018-12-04":1,"2018-12-05":1,"2018-12-06":0,"2018-12-07":0,"2018-12-10":-1,"2018-12-11":-1,"2018-12-12":0,"2018-12-13":-1,"2018-12-14":1,"2018-12-17":-1,"2018-12-18":0,"2018-12-19":-1,"2018-12-20":0,"2018-12-21":0,"2018-12-24":0,"2018-12-25":0,"2018-12-26":0,"2018-12-27":0,"2018-12-28":0,"2019-01-02":1,"2019-01-03":0,"2019-01-04":1,"2019-01-07":1,"2019-01-08":0,"2019-01-09":-1,"2019-01-10":-1,"2019-01-11":0,"2019-01-14":-1,"2019-01-15":1,"2019-01-16":1,"2019-01-17":0,"2019-01-18":1,"2019-01-21":1,"2019-01-22":1,"2019-01-23":1,"2019-01-24":0,"2019-01-25":0,"2019-01-28":0,"2019-01-29":0,"2019-01-30":1,"2019-01-31":0,"2019-02-01":0,"2019-02-11":1,"2019-02-12":1,"2019-02-13":1,"2019-02-14":1,"2019-02-15":0,"2019-02-18":1,"2019-02-19":1,"2019-02-20":0,"2019-02-21":0,"2019-02-22":1,"2019-02-25":1,"2019-02-26":1,"2019-02-27":1,"2019-02-28":1}}
            op
2016-11-01   0
2016-11-02   0
2016-11-03   0
2016-11-04   1
2016-11-07  -1
2016-11-08   0
2016-11-09   0
2016-11-10   0
2016-11-11   1
2016-11-14   1
2016-11-15   0
2016-11-16   0
2016-11-17  -1
2016-11-18   0
2016-11-21   0
2016-11-22   0
2016-11-23   0
2016-11-24   0
2016-11-25   0
2016-11-28   1
2016-11-29  -1
2016-11-30   0
2016-12-01   0
2016-12-02   0
2016-12-05   0
2016-12-06   0
2016-12-07  -1
2016-12-08   0
2016-12-09  -1
2016-12-12   0
...         ..
2019-01-11   0
2019-01-14  -1
2019-01-15   1
2019-01-16   1
2019-01-17   0
2019-01-18   1
2019-01-21   1
2019-01-22   1
2019-01-23   1
2019-01-24   0
2019-01-25   0
2019-01-28   0
2019-01-29   0
2019-01-30   1
2019-01-31   0
2019-02-01   0
2019-02-11   1
2019-02-12   1
2019-02-13   1
2019-02-14   1
2019-02-15   0
2019-02-18   1
2019-02-19   1
2019-02-20   0
2019-02-21   0
2019-02-22   1
2019-02-25   1
2019-02-26   1
2019-02-27   1
2019-02-28   1

[568 rows x 1 columns]
df.index
DatetimeIndex(['2016-11-01', '2016-11-02', '2016-11-03', '2016-11-04',
               '2016-11-07', '2016-11-08', '2016-11-09', '2016-11-10',
               '2016-11-11', '2016-11-14',
               ...
               '2019-02-15', '2019-02-18', '2019-02-19', '2019-02-20',
               '2019-02-21', '2019-02-22', '2019-02-25', '2019-02-26',
               '2019-02-27', '2019-02-28'],
              dtype='datetime64[ns]', length=568, freq=None)
with open("../duyi.htm", "r") as f:s = f.read()df=pd.read_html(s)[0]
df

.dataframe tbody tr th:only-of-type {        vertical-align: middle;    }    .dataframe tbody tr th {        vertical-align: top;    }    .dataframe thead th {        text-align: right;    }


Unnamed: 0收盘价价格变化基准净值操作
02019-02-285025.290.15%0.7723.295做多
12019-02-275017.88-0.41%0.7713.291做多
22019-02-265038.54-0.12%0.7743.304做多
32019-02-255044.355.59%0.7753.308做多
42019-02-224777.302.54%0.7343.133做多
52019-02-214659.14-0.18%0.7163.055平仓
62019-02-204667.620.01%0.7173.055平仓
72019-02-194667.280.13%0.7173.055做多
82019-02-184661.003.51%0.7163.051做多
92019-02-154502.73-0.65%0.6922.948平仓
102019-02-144532.170.44%0.6962.948做多
112019-02-134512.411.64%0.6932.935做多
122019-02-124439.480.83%0.6822.887做多
132019-02-114402.872.53%0.6772.863做多
142019-02-014294.272.82%0.6602.793平仓
152019-01-314176.47-0.83%0.6422.793平仓
162019-01-304211.62-1.00%0.6472.793做多
172019-01-294254.29-1.23%0.6542.821平仓
182019-01-284307.22-0.26%0.6622.821平仓
192019-01-254318.44-0.45%0.6642.821平仓
202019-01-244338.170.52%0.6672.821平仓
212019-01-234315.680.17%0.6632.821做多
222019-01-224308.25-1.49%0.6622.816做多
232019-01-214373.630.59%0.6722.859做多
242019-01-184347.811.02%0.6682.842做多
252019-01-174303.73-0.76%0.6612.813平仓
262019-01-164336.88-0.24%0.6662.813做多
272019-01-154347.361.42%0.6682.820做多
282019-01-144286.55-0.66%0.6592.781做空
292019-01-114314.880.77%0.6632.763平仓
.....................
5382016-12-126249.08-4.07%0.9601.011平仓
5392016-12-096513.92-0.21%1.0011.011做空
5402016-12-086527.43-0.47%1.0031.009平仓
5412016-12-076558.021.03%1.0081.009做空
5422016-12-066490.890.08%0.9971.019平仓
5432016-12-056486.02-0.54%0.9971.019平仓
5442016-12-026520.97-1.56%1.0021.019平仓
5452016-12-016624.470.59%1.0181.019平仓
5462016-11-306585.58-0.53%1.0121.019平仓
5472016-11-296620.79-0.75%1.0171.019做空
5482016-11-286670.800.27%1.0251.012做多
5492016-11-256652.820.45%1.0221.009平仓
5502016-11-246623.05-0.12%1.0181.009平仓
5512016-11-236631.17-0.45%1.0191.009平仓
5522016-11-226661.250.75%1.0241.009平仓
5532016-11-216611.540.14%1.0161.009平仓
5542016-11-186602.33-0.51%1.0151.009平仓
5552016-11-176636.47-0.12%1.0201.009做空
5562016-11-166644.190.06%1.0211.008平仓
5572016-11-156640.460.38%1.0201.008平仓
5582016-11-146615.010.47%1.0161.008做多
5592016-11-116583.890.72%1.0121.003做多
5602016-11-106536.971.29%1.0040.996平仓
5612016-11-096453.57-0.76%0.9920.996平仓
5622016-11-086503.180.53%0.9990.996平仓
5632016-11-076468.820.10%0.9940.996做空
5642016-11-046462.59-0.33%0.9930.997做多
5652016-11-036483.730.44%0.9961.000平仓
5662016-11-026455.13-0.81%0.9921.000平仓
5672016-11-016507.950.00%1.0001.000平仓

568 rows × 6 columns

 

全部回复

0/140

量化课程

    移动端课程