第一部分 新手入门
- 一 量化投资视频学习课程
- 二 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
第三部分 基金、利率互换、固定收益类
- 一 分级基金
- 二 基金分析
- 三 债券
- 四 利率互换
第四部分 衍生品相关
- 一 期权数据
- 二 期权系列
- 三 期权分析
- 四 期货分析
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
流通市值最小股票(新筛选器版)
策略思路
总是持有流通市值最小的10只股票
import numpy as np
from CAL.PyCAL import *
start = '2013-01-05'
end = '2015-12-07'
benchmark = 'HS300'
universe = StockScreener(Factor.LFLO.nsmall(20)) # LFLO 为流通市值对数,LCAP 为总市值对数
capital_base = 1000000
refresh_rate = 1
stk_num = 10 # 持仓股票数量
def initialize(account):
pass
def handle_data(account):
open_price = account.get_attribute_history('openPrice', 1) # 前一日开盘价
close_price = account.referencePrice # 前一日收盘价
# 获取回测当日的前一天日期
dt = Date.fromDateTime(account.current_date)
cal = Calendar('China.SSE')
last_day = cal.advanceDate(dt,'-1B',BizDayConvention.Preceding) #计算出倒数第一个交易日
last_day_str = last_day.strftime("%Y%m%d")
# 市值排序
mkt_value = DataAPI.MktEqudGet(secID=account.universe,tradeDate=last_day_str,field="secID,negMarketValue",pandas="1")
univ_sorted = mkt_value.sort('negMarketValue').secID
buylist = {}
for s in univ_sorted:
if not (np.isnan(close_price[s]) or close_price[s] == 0 or np.isnan(open_price[s]) or open_price[s] == 0):
buylist[s] = 0
if len(buylist) >= stk_num : # 只持有stk_num数目的股票
break
for s in account.valid_secpos:
if s not in buylist:
order_to(s, 0)
v = account.referencePortfolioValue / len(buylist)
for s in buylist:
buylist[s] = v / close_price[s] - account.valid_secpos.get(s, 0)
for s in sorted(buylist, key=buylist.get):
order(s, buylist[s])
回测详情或者bt
打印出来,都可以看到我们维护了一个总是持有10只最小流通市值股票的持仓;偶尔持仓股票数目会有11或者12只
bt
tradeDate | cash | security_position | portfolio_value | benchmark_return | blotter | |
---|---|---|---|---|---|---|
0 | 2013-01-08 | 3352.2479 | {u'300237.XSHE': {u'amount': 56400, u'cost': 1... | 1017415.8479 | -0.004200 | [Order(order_time: 2013-01-08 09:30, symbol: 0... |
1 | 2013-01-09 | 11778.5117 | {u'300237.XSHE': {u'amount': 56900, u'cost': 1... | 1028379.7117 | 0.000313 | [Order(order_time: 2013-01-09 09:30, symbol: 3... |
2 | 2013-01-10 | 3589.4794 | {u'300237.XSHE': {u'amount': 59000, u'cost': 1... | 1031625.0794 | 0.001758 | [Order(order_time: 2013-01-10 09:30, symbol: 3... |
3 | 2013-01-11 | 3536.7632 | {u'300237.XSHE': {u'amount': 59100, u'cost': 1... | 1033944.0632 | -0.018703 | [Order(order_time: 2013-01-11 09:30, symbol: 3... |
4 | 2013-01-14 | 220.7088 | {u'300280.XSHE': {u'amount': 12700, u'cost': 8... | 1071566.8088 | 0.038051 | [Order(order_time: 2013-01-14 09:30, symbol: 3... |
5 | 2013-01-15 | 2933.8669 | {u'300280.XSHE': {u'amount': 12800, u'cost': 8... | 1084159.1669 | 0.007033 | [Order(order_time: 2013-01-15 09:30, symbol: 3... |
6 | 2013-01-16 | 1784.7565 | {u'300280.XSHE': {u'amount': 12700, u'cost': 8... | 1072728.6565 | -0.007227 | [Order(order_time: 2013-01-16 09:30, symbol: 3... |
7 | 2013-01-17 | 66.0136 | {u'300280.XSHE': {u'amount': 12700, u'cost': 8... | 1058278.1136 | -0.009445 | [Order(order_time: 2013-01-17 09:30, symbol: 3... |
8 | 2013-01-18 | 80.2938 | {u'300237.XSHE': {u'amount': 58600, u'cost': 1... | 1068224.0938 | 0.016719 | [Order(order_time: 2013-01-18 09:30, symbol: 3... |
9 | 2013-01-21 | 3050.0950 | {u'300237.XSHE': {u'amount': 58600, u'cost': 1... | 1068048.8950 | 0.005957 | [Order(order_time: 2013-01-21 09:30, symbol: 3... |
10 | 2013-01-22 | 2609.2459 | {u'300237.XSHE': {u'amount': 61900, u'cost': 1... | 1036051.4459 | -0.005362 | [Order(order_time: 2013-01-22 09:30, symbol: 3... |
11 | 2013-01-23 | 2045.4473 | {u'300237.XSHE': {u'amount': 61000, u'cost': 1... | 1026266.2473 | 0.004066 | [Order(order_time: 2013-01-23 09:30, symbol: 3... |
12 | 2013-01-24 | 2926.7991 | {u'300237.XSHE': {u'amount': 60700, u'cost': 1... | 1000829.7991 | -0.009473 | [Order(order_time: 2013-01-24 09:30, symbol: 3... |
13 | 2013-01-25 | 328.4654 | {u'300237.XSHE': {u'amount': 60600, u'cost': 1... | 999702.1654 | -0.004290 | [Order(order_time: 2013-01-25 09:30, symbol: 3... |
14 | 2013-01-28 | 286.7192 | {u'300237.XSHE': {u'amount': 60500, u'cost': 1... | 1019742.9192 | 0.031182 | [Order(order_time: 2013-01-28 09:30, symbol: 3... |
15 | 2013-01-29 | 17.7471 | {u'300237.XSHE': {u'amount': 60700, u'cost': 1... | 1028465.7471 | 0.009050 | [Order(order_time: 2013-01-29 09:30, symbol: 3... |
16 | 2013-01-30 | 171.7371 | {u'300237.XSHE': {u'amount': 61100, u'cost': 1... | 1012637.1371 | 0.004802 | [Order(order_time: 2013-01-30 09:30, symbol: 3... |
17 | 2013-01-31 | 386.9216 | {u'300237.XSHE': {u'amount': 60700, u'cost': 1... | 996104.6216 | -0.000681 | [Order(order_time: 2013-01-31 09:30, symbol: 3... |
18 | 2013-02-01 | 668.2563 | {u'300237.XSHE': {u'amount': 60500, u'cost': 1... | 1016779.9563 | 0.021006 | [Order(order_time: 2013-02-01 09:30, symbol: 3... |
19 | 2013-02-04 | 2638.0595 | {u'300237.XSHE': {u'amount': 60500, u'cost': 1... | 1027883.2595 | 0.001713 | [Order(order_time: 2013-02-04 09:30, symbol: 3... |
20 | 2013-02-05 | 422.8302 | {u'300237.XSHE': {u'amount': 61100, u'cost': 1... | 1037631.5302 | 0.008606 | [Order(order_time: 2013-02-05 09:30, symbol: 3... |
21 | 2013-02-06 | 102645.2421 | {u'300237.XSHE': {u'amount': 61100, u'cost': 1... | 1036665.5421 | 0.001505 | [Order(order_time: 2013-02-06 09:30, symbol: 3... |
22 | 2013-02-07 | 350.1216 | {u'300237.XSHE': {u'amount': 61000, u'cost': 1... | 1040688.9216 | -0.005753 | [Order(order_time: 2013-02-07 09:30, symbol: 3... |
23 | 2013-02-08 | 66.3084 | {u'300237.XSHE': {u'amount': 61600, u'cost': 1... | 1052094.3084 | 0.004294 | [Order(order_time: 2013-02-08 09:30, symbol: 3... |
24 | 2013-02-18 | 356.0140 | {u'300237.XSHE': {u'amount': 60600, u'cost': 1... | 1059799.6140 | -0.012357 | [Order(order_time: 2013-02-18 09:30, symbol: 3... |
25 | 2013-02-19 | 347.5874 | {u'300237.XSHE': {u'amount': 60900, u'cost': 1... | 1043617.1874 | -0.018948 | [Order(order_time: 2013-02-19 09:30, symbol: 3... |
26 | 2013-02-20 | 1524.6353 | {u'300237.XSHE': {u'amount': 60900, u'cost': 1... | 1064335.0353 | 0.006341 | [Order(order_time: 2013-02-20 09:30, symbol: 3... |
27 | 2013-02-21 | 5.6970 | {u'300237.XSHE': {u'amount': 61100, u'cost': 1... | 1055551.1970 | -0.034074 | [Order(order_time: 2013-02-21 09:30, symbol: 3... |
28 | 2013-02-22 | 427.2956 | {u'300237.XSHE': {u'amount': 60600, u'cost': 1... | 1065969.2956 | -0.005340 | [Order(order_time: 2013-02-22 09:30, symbol: 3... |
29 | 2013-02-25 | 128.1500 | {u'300237.XSHE': {u'amount': 61100, u'cost': 1... | 1080711.1500 | 0.003220 | [Order(order_time: 2013-02-25 09:30, symbol: 3... |
... | ... | ... | ... | ... | ... | ... |
677 | 2015-10-27 | 2335.2216 | {u'300405.XSHE': {u'amount': 21700, u'cost': 3... | 9409754.2216 | 0.001008 | [Order(order_time: 2015-10-27 09:30, symbol: 3... |
678 | 2015-10-28 | 3639.3976 | {u'300405.XSHE': {u'amount': 21900, u'cost': 3... | 9225569.3976 | -0.018915 | [Order(order_time: 2015-10-28 09:30, symbol: 3... |
679 | 2015-10-29 | 2647.5406 | {u'300405.XSHE': {u'amount': 21900, u'cost': 3... | 9463491.5406 | 0.002379 | [Order(order_time: 2015-10-29 09:30, symbol: 3... |
680 | 2015-10-30 | 3303.6906 | {u'300405.XSHE': {u'amount': 21900, u'cost': 3... | 9688757.6906 | 0.000218 | [Order(order_time: 2015-10-30 09:30, symbol: 3... |
681 | 2015-11-02 | 11034.8026 | {u'300405.XSHE': {u'amount': 23100, u'cost': 3... | 9996076.8026 | -0.016445 | [Order(order_time: 2015-11-02 09:30, symbol: 3... |
682 | 2015-11-03 | 29889.7366 | {u'002735.XSHE': {u'amount': 26300, u'cost': 3... | 10474014.7366 | -0.003012 | [Order(order_time: 2015-11-03 09:30, symbol: 3... |
683 | 2015-11-04 | 3009.8936 | {u'002735.XSHE': {u'amount': 26700, u'cost': 3... | 10880432.8936 | 0.047048 | [Order(order_time: 2015-11-04 09:30, symbol: 3... |
684 | 2015-11-05 | 1079.4096 | {u'002735.XSHE': {u'amount': 26800, u'cost': 3... | 10870617.4096 | 0.021340 | [Order(order_time: 2015-11-05 09:30, symbol: 3... |
685 | 2015-11-06 | 104.6466 | {u'002735.XSHE': {u'amount': 27600, u'cost': 3... | 11390740.6466 | 0.023585 | [Order(order_time: 2015-11-06 09:30, symbol: 0... |
686 | 2015-11-09 | 8962.8616 | {u'002735.XSHE': {u'amount': 27500, u'cost': 3... | 12093281.8616 | 0.012385 | [Order(order_time: 2015-11-09 09:30, symbol: 3... |
687 | 2015-11-10 | 22992.6176 | {u'002735.XSHE': {u'amount': 27400, u'cost': 3... | 12110893.6176 | -0.001853 | [Order(order_time: 2015-11-10 09:30, symbol: 3... |
688 | 2015-11-11 | 1201562.4166 | {u'002735.XSHE': {u'amount': 28000, u'cost': 3... | 13030169.4166 | 0.000106 | [Order(order_time: 2015-11-11 09:30, symbol: 6... |
689 | 2015-11-12 | 113031.2706 | {u'002735.XSHE': {u'amount': 28200, u'cost': 3... | 14037309.2706 | -0.009996 | [Order(order_time: 2015-11-12 09:30, symbol: 3... |
690 | 2015-11-13 | 5102.3686 | {u'002735.XSHE': {u'amount': 29400, u'cost': 3... | 12922427.3686 | -0.012932 | [Order(order_time: 2015-11-13 09:30, symbol: 0... |
691 | 2015-11-16 | 21313.6426 | {u'002735.XSHE': {u'amount': 29100, u'cost': 3... | 13183437.6426 | 0.004774 | [Order(order_time: 2015-11-16 09:30, symbol: 0... |
692 | 2015-11-17 | 1401.0406 | {u'002735.XSHE': {u'amount': 29600, u'cost': 3... | 12937004.0406 | -0.001525 | [Order(order_time: 2015-11-17 09:30, symbol: 6... |
693 | 2015-11-18 | 173.1346 | {u'002735.XSHE': {u'amount': 29700, u'cost': 3... | 12168156.1346 | -0.011390 | [Order(order_time: 2015-11-18 09:30, symbol: 0... |
694 | 2015-11-19 | 2455.0746 | {u'002735.XSHE': {u'amount': 29400, u'cost': 3... | 12936911.0746 | 0.015984 | [Order(order_time: 2015-11-19 09:30, symbol: 0... |
695 | 2015-11-20 | 7478.6776 | {u'002735.XSHE': {u'amount': 29700, u'cost': 3... | 13013394.6776 | -0.000155 | [Order(order_time: 2015-11-20 09:30, symbol: 3... |
696 | 2015-11-23 | 3168.3376 | {u'002735.XSHE': {u'amount': 29700, u'cost': 3... | 12619590.3376 | -0.005577 | [Order(order_time: 2015-11-23 09:30, symbol: 3... |
697 | 2015-11-24 | 15418.3816 | {u'002735.XSHE': {u'amount': 29400, u'cost': 3... | 13665856.3816 | 0.000148 | [Order(order_time: 2015-11-24 09:30, symbol: 0... |
698 | 2015-11-25 | 70214.3646 | {u'002735.XSHE': {u'amount': 29400, u'cost': 3... | 13704250.3646 | 0.007384 | [Order(order_time: 2015-11-25 09:30, symbol: 6... |
699 | 2015-11-26 | 16885.0396 | {u'002735.XSHE': {u'amount': 29600, u'cost': 3... | 13902736.0396 | -0.005865 | [Order(order_time: 2015-11-26 09:30, symbol: 6... |
700 | 2015-11-27 | 47391.8976 | {u'002735.XSHE': {u'amount': 29100, u'cost': 3... | 13367121.8976 | -0.053848 | [Order(order_time: 2015-11-27 09:30, symbol: 0... |
701 | 2015-11-30 | 31493.4806 | {u'002735.XSHE': {u'amount': 30100, u'cost': 3... | 14149036.4806 | 0.002648 | [Order(order_time: 2015-11-30 09:30, symbol: 3... |
702 | 2015-12-01 | 2339.8786 | {u'002761.XSHE': {u'amount': 40700, u'cost': 3... | 13996263.8786 | 0.007089 | [Order(order_time: 2015-12-01 09:30, symbol: 6... |
703 | 2015-12-02 | 1396517.7026 | {u'002761.XSHE': {u'amount': 40200, u'cost': 3... | 13965267.7026 | 0.036267 | [Order(order_time: 2015-12-02 09:30, symbol: 0... |
704 | 2015-12-03 | 1439379.3926 | {u'002735.XSHE': {u'amount': 30900, u'cost': 3... | 14861814.3926 | 0.007347 | [Order(order_time: 2015-12-03 09:30, symbol: 0... |
705 | 2015-12-04 | 1479225.7226 | {u'002761.XSHE': {u'amount': 41600, u'cost': 3... | 15134121.7226 | -0.019125 | [Order(order_time: 2015-12-04 09:30, symbol: 3... |
706 | 2015-12-07 | 1552999.2546 | {u'002735.XSHE': {u'amount': 31600, u'cost': 3... | 15369296.2546 | 0.002723 | [Order(order_time: 2015-12-07 09:30, symbol: 0... |
707 rows × 6 columns
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论