Git Product home page Git Product logo

convertible_bond's Introduction

convertible_bond

DEPRECATED! github访问不方便。感兴趣的可以移步https://gitee.com/paulhybryant/quant

可转债策略及量化回测

几个平台的粗略比较:

  • 聚宽
    • 转债数据行情从2018-09-13开始
    • 强赎信息好像没有
    • 用聚宽的数据,溢价率,双低什么的需要自己算
    • 可以试用半年,试用期数据量没有什么限制
    • 不支撑转债回测
    • 编程API友好,文档也不错
  • 米筐
    • 数据种类最全,强赎回售什么的都有
    • 只能试用一个月,而且每天只有50MB
    • 平台试用和sdk试用分开申请,在平台上跑好像流量限制不大
    • 编程API友好,和聚宽几乎一样,文档也不错
    • 有开源的rqalpha回测框架,rqalpha-plus也是基于rqalpha,可扩展,有代码可以hack
  • 掘金
    • 数据质量不足,缺少转债历史数据
    • 回测环境最友好,有本地IDE,编程方便,但是必须在windows下起客户端
    • 可转债数据不足,无法回测
  • 优矿
    • 数据比较全
    • 回测可转债的支持好像不太好,需要自己计算持仓,回撤等
    • 数据免费,质量也不错
    • 编程环境非常友好,方便上手和实验(基于jupyter notebook)
  • 集思录
    • 双低数据什么都算好了,但是没有历史转股价数据等
    • 每一个转债的历史数据有,需要爬
    • 适用于手动轮动,生成基于运行当日数据的标的和操作。

要使用聚宽/米筐的数据,需要申请使用,并将用户名密码放在'.auth.json'里。 要使用集思录的数据,需要将用户名和密码放在'.auth.json'里。否则集思录无法获得完整的转债数据。 集思录现在是直接用python的requests获取,比较麻烦。也可以考虑Selenium的方案。

付费的话,直接用米筐或者rqalpha-plus,交易用vnpy或者easytrader(都没试过) 免费的话,最好的组合是用米筐的数据(或者聚宽的可能也可以),用rqalpha + 自己扩展的数据源进行回测。至少对于可转债是可以work的。

.auth.json的格式如下: { "rqdata": { "username": "license", "password": "xxxxxxxxxx" }, "jisilu": { "username": "foo", "password": "bar" }, "jqdata": { "username": "foo", "password": "bar" }, }

持仓信息默认放在'.positions.json'里面 可以自己些计算策略的函数,也可以用library/里的现成的。 要安装library/中的库,在library/目录下运行 pip install -e .

Usage

./main.py --cache_dir=/tmp/cache --data_soruce=rqdata --txn_day=2021-08-01 --strategy_cfg=double_low.json

./main.py --cache_dir=/tmp/cache --data_source=jisilu

./main.py --help

./backtest.py --start_date='2018-01-01' --end_date='2021-08-31' --cache_dir="/tmp/cache" --strategy_cfg='[dlh]*.json'

Example

Results of multiple strategies

TODO

  • 增加更多的策略作比较
    • 盛唐风物的偏离策略
    • 强赎博弈
    • 回售博弈
    • ...
  • 优化现有策略,考虑其他的因子,比如规模,评级等
  • 在图上增加最大回撤日期等

Change Log

Old

  • 过滤已经公布强赎的转债: 案例:2019-09-23 127010.XSHE (Done)
  • 过滤可交换债(Done)
  • Handle call_info not available on some dates (Done)
  • 输出Order细节到csv,转换成掘金的格式(Done)

2021-09-23

  • 过滤停牌转债: 2021-09-08-11-39-20/issues.txt(Done)
  • 过滤Q债(只有机构或者合格投资者可以购买)(Done, 目前Q债都是EB债)

2021-09-26

  • 将rqalpha的输出转换成掘金的格式
  • 用run_rq.py来运行,方便传递参数
    • ./run_rq.py --file=multi_factors.py --start_date='2021-09-01' --end_date='2021-09-23' --cache_dir='cache'
  • 给回测传递参数,选择不同策略(Make conbond library strategy a mod) (Done)
  • 看能否利用起rqalpha的incremental mod (Done)

2021-09-27

  • 过滤低规模转债: 案例:128060(中装转债),2020-02-08公告,规模低于3000万,02-13开始停止交易 (Done)

2021-09-28

  • 用其他类似的量化平台结果添加测试
    • 是否过滤停牌转债导致的不同, 例如2018-01-08 113502
    • 是否过滤已公告强赎转债导致的不同, 例如2018-06-19 110039
    • 是否过滤规模小于一个亿的转债(避免停止交易), 例如2019-04-29 123013

2021-09-29

  • 用其他类似的量化平台结果添加测试(自动化比对流程)
    • 2019-09-23 113534: 数据源问题,2019-09-23时候的转股溢价率是6%,实际上应该是44+(集思录),2019-09-24转股价下修到底溢价率才下来了
    • 2020-08-10 128012: 2020-04-29之后再无成交,价格不变但是溢价率一直降低
    • 2021-01-18 113008: 临近到期赎回,需要过滤

2021-09-30

  • 用其他类似的量化平台结果添加测试(自动化比对流程)
  • 有的标的有的日成交量很低,下单数量超过当日Bar的25%只会部分成交
    • 2018-11-26 128033, 9.51万成交额,这种就放着吧,总体影响不大,之后还会被继续平仓
  • 根据2021-09-29 diff结果修正
    • 2019-09-23 113534: 数据源问题,不需要修正
    • 2020-08-10 128012: 2020-04-29之后再无成交,价格不变但是溢价率一直降低,用成交过滤
    • 2021-01-18 113008: 临近到期赎回,过滤(30days)

2021-10-29

  • 多策略回测
  • 回测配置放置在json中,可定义过滤条件
  • 增加几个回测策略
  • 过滤接近强赎触发的转债,强赎公告发布会马上导致溢价的收敛。

convertible_bond's People

Contributors

paulhybryant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

convertible_bond's Issues

报错,是和absl接不上嘛?

I0706 19:33:21.221671 4605296128 main.py:99] https://www.jisilu.cn/data/cbnew/cb_list/?___jsl=LST___t=1625571201221 Traceback (most recent call last): File "/Users/libsu/Downloads/convertible_bond-main/main.py", line 262, in <module> app.run(main) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/absl/app.py", line 312, in run _run_main(main, args) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/absl/app.py", line 258, in _run_main sys.exit(main(argv)) File "/Users/libsu/Downloads/convertible_bond-main/main.py", line 257, in main data = process(dat) File "/Users/libsu/Downloads/convertible_bond-main/main.py", line 214, in process cc_dict = get_cc() File "/Users/libsu/Downloads/convertible_bond-main/main.py", line 75, in get_cc with open(FLAGS.cc, 'r', encoding='utf-8') as cc_file: FileNotFoundError: [Errno 2] No such file or directory: 'cc.csv'

能提供个简单的使用手册吗

大神,您好,首先感谢你今天百忙之中更新代码,请问能提供个简单的使用手册吗?
更新前我配置了auth.json文件后能运行,但是更新后我不知道如何使用了,非常感谢!

执行策略报错

W1129 20:04:57.347531 32804 legend.py:1193] No handles with labels found to put in legend.
Traceback (most recent call last):
File "D:\Sites\convertible_bond\examples\backtest.py", line 196, in
app.run(main)
File "C:\Users\F\AppData\Local\Programs\Python\Python37\lib\site-packages\absl\app.py", line 312, in run
_run_main(main, args)
File "C:\Users\F\AppData\Local\Programs\Python\Python37\lib\site-packages\absl\app.py", line 258, in _run_main
sys.exit(main(argv))
File "D:\Sites\convertible_bond\examples\backtest.py", line 192, in main
strategy.plot_results(backtest_time, results, savefile=FLAGS.results)
File "d:\sites\convertible_bond\library\conbond\strategy.py", line 139, in plot_results
ax2.table(cellText=df.values, colLabels=df.columns, loc='center')
File "C:\Users\F\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib-3.3.3-py3.7-win-amd64.egg\matplotlib\table.py", line 741, in table
cols = len(cellText[0])
IndexError: index 0 is out of bounds for axis 0 with size 0

历史数据的获取

你好,谢谢你的分享,请问转债的历史数据的获取是从哪里获得的呢?我知道集思录上没有可导出的历史数据。你所说的量化回测平台上有详细完整的历史数据吗?比如聚宽与米筐之类的。谢谢

历史数据的获取方式

你好,谢谢你的分享,请问转债的历史数据的获取是从哪里获得的呢?我知道集思录上没有可导出的历史数据。你所说的量化回测平台上有详细完整的历史数据吗?比如聚宽与米筐之类的。谢谢

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.