第一部分 新手入门
- 一 量化投资视频学习课程
- 二 Python 手把手教学
- 量化分析师的Python日记【第1天:谁来给我讲讲Python?】
- 量化分析师的Python日记【第2天:再接着介绍一下Python呗】
- 量化分析师的Python日记【第3天:一大波金融Library来袭之numpy篇】
- 量化分析师的Python日记【第4天:一大波金融Library来袭之scipy篇】
- 量化分析师的Python日记【第5天:数据处理的瑞士军刀pandas】
- 量化分析师的Python日记【第6天:数据处理的瑞士军刀pandas下篇
- 量化分析师的Python日记【第7天:Q Quant 之初出江湖】
- 量化分析师的Python日记【第8天 Q Quant兵器谱之函数插值】
- 量化分析师的Python日记【第9天 Q Quant兵器谱之二叉树】
- 量化分析师的Python日记【第10天 Q Quant兵器谱 -之偏微分方程1】
- 量化分析师的Python日记【第11天 Q Quant兵器谱之偏微分方程2】
- 量化分析师的Python日记【第12天:量化入门进阶之葵花宝典:因子如何产生和回测】
- 量化分析师的Python日记【第13天 Q Quant兵器谱之偏微分方程3】
- 量化分析师的Python日记【第14天:如何在优矿上做Alpha对冲模型】
- 量化分析师的Python日记【第15天:如何在优矿上搞一个wealthfront出来】
第二部分 股票量化相关
- 一 基本面分析
- 1.1 alpha 多因子模型
- 1.2 基本面因子选股
- 1.3 财报阅读 • [米缸量化读财报] 资产负债表-投资相关资产
- 1.4 股东分析
- 1.5 宏观研究
- 二 套利
- 三 事件驱动
- 四 技术分析
- 4.1 布林带
- 4.2 均线系统
- 4.3 MACD
- 4.4 阿隆指标 • 技术指标阿隆( Aroon )全解析
- 4.5 CCI • CCI 顺势指标探索
- 4.6 RSI
- 4.7 DMI • DMI 指标体系的构建及简单应用
- 4.8 EMV • EMV 技术指标的构建及应用
- 4.9 KDJ • KDJ 策略
- 4.10 CMO
- 4.11 FPC • FPC 指标选股
- 4.12 Chaikin Volatility
- 4.13 委比 • 实时计算委比
- 4.14 封单量
- 4.15 成交量 • 决战之地, IF1507 !
- 4.16 K 线分析 • 寻找夜空中最亮的星
- 五 量化模型
- 5.1 动量模型
- 5.2 Joseph Piotroski 9 F-Score Value Investing Model
- 5.3 SVR
- 5.4 决策树、随机树
- 5.5 钟摆理论
- 5.6 海龟模型
- 5.7 5217 策略
- 5.8 SMIA
- 5.9 神经网络
- 5.10 PAMR
- 5.11 Fisher Transform
- 5.12 分型假说, Hurst 指数
- 5.13 变点理论
- 5.14 Z-score Model
- 5.15 机器学习
- 5.16 DualTrust 策略和布林强盗策略
- 5.17 卡尔曼滤波
- 5.18 LPPL anti-bubble model
- 六 大数据模型
- 6.1 市场情绪分析
- 6.2 新闻热点
- 七 排名选股系统
- 八 轮动模型
- 九 组合投资
- 十 波动率
- 十一 算法交易
- 十二 中高频交易
- 十三 Alternative Strategy
第三部分 基金、利率互换、固定收益类
- 一 分级基金
- 二 基金分析
- 三 债券
- 四 利率互换
第四部分 衍生品相关
- 一 期权数据
- 二 期权系列
- 三 期权分析
- 四 期货分析
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
动量策略(momentum driven)
import pandas as pd
start = '2011-11-01'
end = '2015-03-01'
benchmark = 'HS300'
universe = set_universe('HS300') # 股票池为沪深300
capital_base = 10000000
refresh_rate = 10
def initialize(account):
pass
def handle_data(account):
history = account.get_attribute_history('closePrice', 20)
momentum = {'symbol':[], 'c_ret':[]}
for stk in account.universe:
momentum['symbol'].append(stk)
momentum['c_ret'].append(history[stk][-1]/history[stk][0])
# 按照过去20日收益率排序,并且选择前20%的股票作为买入候选
momentum = pd.DataFrame(momentum).sort(columns='c_ret').reset_index()
momentum = momentum[len(momentum)*4/5:len(momentum)] # 选择
buylist = momentum['symbol'].tolist()
for stk in account.valid_secpos:
if stk not in buylist:
order_to(stk, 0)
# 等权重买入所选股票
portfolio_value = account.referencePortfolioValue
for stk in buylist:
if stk not in account.valid_secpos:
order_to(stk, int(portfolio_value / account.referencePrice[stk] / 100.0 / len(buylist))*100)
bt
tradeDate | cash | security_position | portfolio_value | benchmark_return | blotter | |
---|---|---|---|---|---|---|
0 | 2011-11-29 | 1.627636 | {u'600809.XSHG': 5700, u'600597.XSHG': 21100, ... | 10057034.029636 | 0.013697 | [Order(order time: datetime.datetime(2011, 11,... |
1 | 2011-11-30 | 1.627636 | {u'600809.XSHG': 5700, u'600597.XSHG': 21100, ... | 9744501.409636 | -0.033370 | [] |
2 | 2011-12-01 | 1.627636 | {u'600809.XSHG': 5700, u'600597.XSHG': 21100, ... | 9865655.500636 | 0.024625 | [] |
3 | 2011-12-02 | 1.627636 | {u'600809.XSHG': 5700, u'600597.XSHG': 21100, ... | 9708455.312636 | -0.010180 | [] |
4 | 2011-12-05 | 1.627636 | {u'600809.XSHG': 5700, u'600597.XSHG': 21100, ... | 9406180.945636 | -0.014048 | [] |
5 | 2011-12-06 | 1.627636 | {u'600809.XSHG': 5700, u'600597.XSHG': 21100, ... | 9415313.949636 | -0.002000 | [] |
6 | 2011-12-07 | 1.627636 | {u'600809.XSHG': 5700, u'600597.XSHG': 21100, ... | 9454383.554636 | 0.004724 | [] |
7 | 2011-12-08 | 1.627636 | {u'600809.XSHG': 5700, u'600597.XSHG': 21100, ... | 9492264.755636 | -0.001276 | [] |
8 | 2011-12-09 | 1.627636 | {u'600809.XSHG': 5700, u'600597.XSHG': 21100, ... | 9410892.851636 | -0.008531 | [] |
9 | 2011-12-12 | 1.627636 | {u'600809.XSHG': 5700, u'600597.XSHG': 21100, ... | 9280515.559636 | -0.010293 | [] |
10 | 2011-12-13 | 6.144010 | {u'000423.XSHE': 4200, u'600036.XSHG': 16300, ... | 9116051.541010 | -0.022506 | [Order(order time: datetime.datetime(2011, 12,... |
11 | 2011-12-14 | 6.144010 | {u'000423.XSHE': 4200, u'600036.XSHG': 16300, ... | 9042660.489010 | -0.010094 | [] |
12 | 2011-12-15 | 6.144010 | {u'000423.XSHE': 4200, u'600036.XSHG': 16300, ... | 8973191.009010 | -0.023646 | [] |
13 | 2011-12-16 | 6.144010 | {u'000423.XSHE': 4200, u'600036.XSHG': 16300, ... | 9203671.207010 | 0.021079 | [] |
14 | 2011-12-19 | 6.144010 | {u'000423.XSHE': 4200, u'600036.XSHG': 16300, ... | 9272914.609010 | -0.002394 | [] |
15 | 2011-12-20 | 6.144010 | {u'000423.XSHE': 4200, u'600036.XSHG': 16300, ... | 9245375.546010 | -0.003076 | [] |
16 | 2011-12-21 | 6.144010 | {u'000423.XSHE': 4200, u'600036.XSHG': 16300, ... | 9134328.126010 | -0.015971 | [] |
17 | 2011-12-22 | 6.144010 | {u'000423.XSHE': 4200, u'600036.XSHG': 16300, ... | 9174823.752010 | 0.000952 | [] |
18 | 2011-12-23 | 6.144010 | {u'000423.XSHE': 4200, u'600036.XSHG': 16300, ... | 9185929.702010 | 0.007613 | [] |
19 | 2011-12-26 | 6.144010 | {u'000423.XSHE': 4200, u'600036.XSHG': 16300, ... | 9054507.546010 | -0.009943 | [] |
20 | 2011-12-27 | 9.172263 | {u'601328.XSHG': 41600, u'600036.XSHG': 16300,... | 8855733.701263 | -0.013130 | [Order(order time: datetime.datetime(2011, 12,... |
21 | 2011-12-28 | 9.172263 | {u'601328.XSHG': 41600, u'600036.XSHG': 16300,... | 8820469.780263 | 0.001255 | [] |
22 | 2011-12-29 | 9.172263 | {u'601328.XSHG': 41600, u'600036.XSHG': 16300,... | 8836530.533263 | 0.001487 | [] |
23 | 2011-12-30 | 9.172263 | {u'601328.XSHG': 41600, u'600036.XSHG': 16300,... | 8976704.526263 | 0.014875 | [] |
24 | 2012-01-04 | 9.172263 | {u'601328.XSHG': 41600, u'600036.XSHG': 16300,... | 8858664.267263 | -0.020032 | [] |
25 | 2012-01-05 | 9.172263 | {u'601328.XSHG': 41600, u'600036.XSHG': 16300,... | 8785873.316263 | -0.009730 | [] |
26 | 2012-01-06 | 9.172263 | {u'601328.XSHG': 41600, u'600036.XSHG': 16300,... | 8790219.626263 | 0.006245 | [] |
27 | 2012-01-09 | 9.172263 | {u'601328.XSHG': 41600, u'600036.XSHG': 16300,... | 9032347.125263 | 0.034039 | [] |
28 | 2012-01-10 | 9.172263 | {u'601328.XSHG': 41600, u'600036.XSHG': 16300,... | 9247829.118263 | 0.033260 | [] |
29 | 2012-01-11 | 9.172263 | {u'601328.XSHG': 41600, u'600036.XSHG': 16300,... | 9186427.159263 | -0.004797 | [] |
... | ... | ... | ... | ... | ... | ... |
755 | 2015-01-12 | 1.942737 | {u'600036.XSHG': 23600, u'000776.XSHE': 22100,... | 20280828.092737 | -0.009344 | [] |
756 | 2015-01-13 | 1.942737 | {u'600036.XSHG': 23600, u'000776.XSHE': 22100,... | 20204218.432737 | 0.000131 | [] |
757 | 2015-01-14 | 1.942737 | {u'600036.XSHG': 23600, u'000776.XSHE': 22100,... | 20223885.602737 | -0.003307 | [] |
758 | 2015-01-15 | 1.942737 | {u'600036.XSHG': 23600, u'000776.XSHE': 22100,... | 20962393.212737 | 0.029036 | [] |
759 | 2015-01-16 | 1.942737 | {u'600036.XSHG': 23600, u'000776.XSHE': 22100,... | 21076614.722737 | 0.008608 | [] |
760 | 2015-01-19 | 3.731317 | {u'601328.XSHG': 49500, u'600066.XSHG': 21600,... | 19298994.131317 | -0.077023 | [Order(order time: datetime.datetime(2015, 1, ... |
761 | 2015-01-20 | 3.731317 | {u'601328.XSHG': 49500, u'600066.XSHG': 21600,... | 19641436.921317 | 0.012240 | [] |
762 | 2015-01-21 | 3.731317 | {u'601328.XSHG': 49500, u'600066.XSHG': 21600,... | 20548813.131317 | 0.044951 | [] |
763 | 2015-01-22 | 3.731317 | {u'601328.XSHG': 49500, u'600066.XSHG': 21600,... | 20654164.321317 | 0.005277 | [] |
764 | 2015-01-23 | 3.731317 | {u'601328.XSHG': 49500, u'600066.XSHG': 21600,... | 20704527.401317 | 0.001155 | [] |
765 | 2015-01-26 | 3.731317 | {u'601328.XSHG': 49500, u'600066.XSHG': 21600,... | 20741863.411317 | 0.010150 | [] |
766 | 2015-01-27 | 3.731317 | {u'601328.XSHG': 49500, u'600066.XSHG': 21600,... | 20501439.751317 | -0.009161 | [] |
767 | 2015-01-28 | 3.731317 | {u'601328.XSHG': 49500, u'600066.XSHG': 21600,... | 20072450.291317 | -0.013877 | [] |
768 | 2015-01-29 | 3.731317 | {u'601328.XSHG': 49500, u'600066.XSHG': 21600,... | 19879912.781317 | -0.012346 | [] |
769 | 2015-01-30 | 3.731317 | {u'601328.XSHG': 49500, u'600066.XSHG': 21600,... | 19612742.771317 | -0.013616 | [] |
770 | 2015-02-02 | 6.734377 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 19457712.474377 | -0.023419 | [Order(order time: datetime.datetime(2015, 2, ... |
771 | 2015-02-03 | 6.734377 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 19862476.714377 | 0.024891 | [] |
772 | 2015-02-04 | 6.734377 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 19714886.724377 | -0.010379 | [] |
773 | 2015-02-05 | 6.734377 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 19679598.144377 | -0.010236 | [] |
774 | 2015-02-06 | 6.734377 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 19297569.294377 | -0.016194 | [] |
775 | 2015-02-09 | 6.734377 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 19131675.244377 | 0.010114 | [] |
776 | 2015-02-10 | 6.734377 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 19621103.094377 | 0.018238 | [] |
777 | 2015-02-11 | 6.734377 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 20007845.234377 | 0.007978 | [] |
778 | 2015-02-12 | 6.734377 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 20139049.804377 | 0.002548 | [] |
779 | 2015-02-13 | 6.734377 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 20416511.184377 | 0.007829 | [] |
780 | 2015-02-16 | 5.417277 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 21015638.057277 | 0.008547 | [Order(order time: datetime.datetime(2015, 2, ... |
781 | 2015-02-17 | 5.417277 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 20991534.387277 | 0.006526 | [] |
782 | 2015-02-25 | 5.417277 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 20681973.077277 | -0.012376 | [] |
783 | 2015-02-26 | 5.417277 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 20936634.347277 | 0.025172 | [] |
784 | 2015-02-27 | 5.417277 | {u'002153.XSHE': 4400, u'600498.XSHG': 19400, ... | 21204596.757277 | 0.001836 | [] |
785 rows × 6 columns
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论