第一部分 新手入门
- 一 量化投资视频学习课程
- 二 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
第三部分 基金、利率互换、固定收益类
- 一 分级基金
- 二 基金分析
- 三 债券
- 四 利率互换
第四部分 衍生品相关
- 一 期权数据
- 二 期权系列
- 三 期权分析
- 四 期货分析
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
Simple Bollinger Bands
策略思路: 在一段时间内,股票价格可以认为是在一定水平上下波动。例如,可以简单认为股价在过去100天的平均值基础上,上下波动几个标准差。
策略实现: (1) 股价高于这个波动区间,说明股价虚高,故卖出 (2) 股价低于这个波动区间,说明股价虚低,故买入
PS:本策略适用于股市平稳波动时期,在大牛市或者大熊市不太适用
import quartz
import quartz.backtest as qb
import quartz.performance as qp
from quartz.api import *
import pandas as pd
import numpy as np
from datetime import datetime
from matplotlib import pylab
import talib
start = datetime(2011, 1, 1)
end = datetime(2014, 10, 1)
benchmark = 'HS300'
universe = ['601398.XSHG', '600028.XSHG', '601988.XSHG', '600036.XSHG', '600030.XSHG',
'601318.XSHG', '600000.XSHG', '600019.XSHG', '600519.XSHG', '601166.XSHG']
capital_base = 1000000
refresh_rate = 5
window = 200
def initialize(account):
account.amount = 10000
account.universe = universe
add_history('hist', window)
def handle_data(account):
for stk in account.universe:
prices = account.hist[stk]['closePrice']
if prices is None:
return
mu = prices.mean()
sd = prices.std()
upper = mu + 2*sd
middle = mu
lower = mu - 2*sd
cur_pos = account.position.stkpos.get(stk, 0)
cur_prc = prices[-1]
if cur_prc > upper and cur_pos >= 0:
order_to(stk, 0)
if cur_prc < lower and cur_pos <= 0:
order(stk, account.amount)
bt
tradeDate | cash | stock_position | portfolio_value | benchmark_return | blotter | |
---|---|---|---|---|---|---|
0 | 2011-11-01 | 1000000.00000 | {} | 1000000.00000 | 0.000000 | [] |
1 | 2011-11-02 | 1000000.00000 | {} | 1000000.00000 | 0.016629 | [] |
2 | 2011-11-03 | 1000000.00000 | {} | 1000000.00000 | 0.000697 | [] |
3 | 2011-11-04 | 1000000.00000 | {} | 1000000.00000 | 0.007086 | [] |
4 | 2011-11-07 | 1000000.00000 | {} | 1000000.00000 | -0.009950 | [] |
5 | 2011-11-08 | 1000000.00000 | {} | 1000000.00000 | -0.003120 | [] |
6 | 2011-11-09 | 1000000.00000 | {} | 1000000.00000 | 0.008778 | [] |
7 | 2011-11-10 | 1000000.00000 | {} | 1000000.00000 | -0.018922 | [] |
8 | 2011-11-11 | 1000000.00000 | {} | 1000000.00000 | -0.001699 | [] |
9 | 2011-11-14 | 1000000.00000 | {} | 1000000.00000 | 0.020480 | [] |
10 | 2011-11-15 | 1000000.00000 | {} | 1000000.00000 | -0.002005 | [] |
11 | 2011-11-16 | 1000000.00000 | {} | 1000000.00000 | -0.027167 | [] |
12 | 2011-11-17 | 1000000.00000 | {} | 1000000.00000 | -0.003033 | [] |
13 | 2011-11-18 | 1000000.00000 | {} | 1000000.00000 | -0.020857 | [] |
14 | 2011-11-21 | 1000000.00000 | {} | 1000000.00000 | 0.001225 | [] |
15 | 2011-11-22 | 1000000.00000 | {} | 1000000.00000 | -0.000081 | [] |
16 | 2011-11-23 | 1000000.00000 | {} | 1000000.00000 | -0.009758 | [] |
17 | 2011-11-24 | 1000000.00000 | {} | 1000000.00000 | 0.001898 | [] |
18 | 2011-11-25 | 1000000.00000 | {} | 1000000.00000 | -0.007317 | [] |
19 | 2011-11-28 | 1000000.00000 | {} | 1000000.00000 | 0.001303 | [] |
20 | 2011-11-29 | 1000000.00000 | {} | 1000000.00000 | 0.013697 | [] |
21 | 2011-11-30 | 1000000.00000 | {} | 1000000.00000 | -0.033370 | [] |
22 | 2011-12-01 | 1000000.00000 | {} | 1000000.00000 | 0.024625 | [] |
23 | 2011-12-02 | 1000000.00000 | {} | 1000000.00000 | -0.010180 | [] |
24 | 2011-12-05 | 1000000.00000 | {} | 1000000.00000 | -0.014048 | [] |
25 | 2011-12-06 | 1000000.00000 | {} | 1000000.00000 | -0.002000 | [] |
26 | 2011-12-07 | 1000000.00000 | {} | 1000000.00000 | 0.004724 | [] |
27 | 2011-12-08 | 1000000.00000 | {} | 1000000.00000 | -0.001276 | [] |
28 | 2011-12-09 | 1000000.00000 | {} | 1000000.00000 | -0.008531 | [] |
29 | 2011-12-12 | 1000000.00000 | {} | 1000000.00000 | -0.010293 | [] |
... | ... | ... | ... | ... | ... | ... |
679 | 2014-08-19 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1149017.27989 | 0.000087 | [] |
680 | 2014-08-20 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1168551.04989 | -0.003633 | [Order({'transact_price': 0.0, 'symbol': '6000... |
681 | 2014-08-21 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1155719.88989 | -0.005028 | [] |
682 | 2014-08-22 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1152026.33989 | 0.004723 | [] |
683 | 2014-08-25 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1148250.45989 | -0.009513 | [] |
684 | 2014-08-26 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1141866.53989 | -0.008012 | [] |
685 | 2014-08-27 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1133729.60989 | 0.001507 | [] |
686 | 2014-08-28 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1130309.43989 | -0.007010 | [] |
687 | 2014-08-29 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1144849.97989 | 0.011686 | [] |
688 | 2014-09-01 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1146127.24989 | 0.007283 | [] |
689 | 2014-09-02 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1171994.81989 | 0.013222 | [] |
690 | 2014-09-03 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1186363.06989 | 0.009377 | [Order({'transact_price': 0.0, 'symbol': '6000... |
691 | 2014-09-04 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1188453.82989 | 0.007218 | [] |
692 | 2014-09-05 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1203626.03989 | 0.009494 | [] |
693 | 2014-09-09 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1182303.76989 | -0.001647 | [] |
694 | 2014-09-10 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1180321.58989 | -0.005231 | [] |
695 | 2014-09-11 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1168537.55989 | -0.003691 | [Order({'transact_price': 0.0, 'symbol': '6000... |
696 | 2014-09-12 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1171787.86989 | 0.006150 | [] |
697 | 2014-09-15 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1153269.96989 | -0.000479 | [] |
698 | 2014-09-16 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1141194.90989 | -0.019869 | [] |
699 | 2014-09-17 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1145778.58989 | 0.005258 | [] |
700 | 2014-09-18 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1152235.30989 | 0.003056 | [] |
701 | 2014-09-19 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1162000.35989 | 0.006870 | [] |
702 | 2014-09-22 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1136441.48989 | -0.019087 | [] |
703 | 2014-09-23 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1139988.07989 | 0.008635 | [] |
704 | 2014-09-24 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1157613.46989 | 0.017671 | [] |
705 | 2014-09-25 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1169367.30989 | -0.002006 | [] |
706 | 2014-09-26 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1169791.29989 | 0.000094 | [] |
707 | 2014-09-29 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1170503.49989 | 0.004349 | [] |
708 | 2014-09-30 | 96907.47989 | {u'601166.XSHG': 3877.0, u'600036.XSHG': 0, u'... | 1168692.07989 | 0.001303 | [] |
709 rows × 6 columns
perf = qp.perf_parse(bt)
out_keys = ['annualized_return', 'volatility', 'information',
'sharpe', 'max_drawdown', 'alpha', 'beta']
for k in out_keys:
print '%s: %s' % (k, perf[k])
annualized_return: 0.0594823977045
volatility: 0.214571802928
information: 0.407163653335
sharpe: 0.102806600884
max_drawdown: 0.36585509048
alpha: 0.052294592526
beta: 0.434097117249
perf['cumulative_return'].plot()
perf['benchmark_cumulative_return'].plot()
pylab.legend(['current_strategy','HS300'])
<matplotlib.legend.Legend at 0x568fe90>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论