Giter VIP home page Giter VIP logo

czsc's People

Contributors

ibaihuo avatar liuts avatar noragithub avatar zengbin93 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

czsc's Issues

关于k线包含处理后成交量的处理

analyze.py中对包含k线的处理。
`if (k2.high <= k3.high and k2.low >= k3.low) or (k2.high >= k3.high and k2.low <= k3.low):
if direction == Direction.Up:
high = max(k2.high, k3.high)
low = max(k2.low, k3.low)
dt = k2.dt if k2.high >= k3.high else k3.dt
elif direction == Direction.Down:
high = min(k2.high, k3.high)
low = min(k2.low, k3.low)
dt = k2.dt if k2.low <= k3.low else k3.dt
else:
raise ValueError

    if k3.open > k3.close:
        open_ = high
        close = low
    else:
        open_ = low
        close = high
    vol = k2.vol + k3.vol`

原文虽然并未对成交量处理给出明确的说法,但是这种把两根k线成交量直接相加的做法非常不妥。会造成两个平庸的k线,成交量突然显著增加,这对后市的判断会造成疑惑的。个人建议:保守主义取均值,或者取最小值。乐观主义:取最大值。

你好,关于分型的设定

你好,我仔细看了一下你网址中的分型结果。发现很多分型部分有分型共用K线的问题。

按定义,顶底分型中间至少有一个K线。

请问这个地方你有留意吗?

记录下新手安装遇到的问题

  1. python 版本必须升级到 python 3.7+

sudo apt-get install python3.7
sudo apt-get install python3.7-dev

  1. ta-lib安装 注意使用代理 避免安装超时失败

export http_proxy=http://127.0.0.1:8000/
export https_proxy=http://127.0.0.1:8000/

8000是我的代理端口

  1. ta-lib 安装 参照 https://github.com/mrjbq7/ta-lib
  1. 先安装编译 ta-lib库
  2. 再安装ta-lib python wrapper python setup.py install
  1. czsc 依赖安装 pip install -r requirements.txt

补充 又遇到一个 llvm抛错解决:

ImportError: cannot import name '_gi' from 'gi' (/usr/lib/python3/dist-packages/gi/__init__.py)
sudo ln -s /usr/lib/python3/dist-packages/gi/_gi.cpython-{36m,37m}-x86_64-linux-gnu.so

RuntimeError: /usr/local/opt/llvm/bin/llvm-config failed executing, please point LLVM_CONFIG to the path for llvm-config

  1. sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
  2. export LLVM_CONFIG=/usr/bin/llvm-config-10

注意只能安装llvm 10版本 (需要修改 llvm.sh 中 LLVM_VERSION=10)

参考:
https://www.cnblogs.com/kele-dad/p/12955804.html
https://zhuanlan.zhihu.com/p/183169124

  1. 启动 czsc
    python examples/use_czsc_with_jq.py

供参考

预处理需要递归处理

严格按照缠论的话,预处理需要递归处理,还有点麻烦。

1,2,3,4根k线

假设向上,如果4包含3,处理后的新k线,取3,4的高点为高点,低点为高点,需要考虑继续包含2;就是说需要递归到没有包含k线为止。

遍历k线,每向前一步,如果有包含关系,严格来说都需要回溯。

刚看了一下你关于线段的划分,方法应该是有问题的

刚看了一下关于线段的划分,主要是去除前后顶/底的情况,按照笔划分后,就不应该再有这种笔存在了。缠论中,线段的划分主要是使用特征序列方法,对线段进行确认,涉及有缺口和没有缺口的不同工况,所以,感觉线段划分方法似乎有些问题

能否给出一些缠论中常见的判断规则?

例如 examples/third_buy.py line 25
# 在这里判断是否有五笔三买形态,也可以换成自己感兴趣的形态
if c.signals['倒1五笔'] in [Signals.X5LB0.value]:

文档中只写了 X5LA0 的举例,我想自己判断一下其他的形态但是不知道怎么改。
像是一买、二买、类二买这些常见的形态对应的代码可以给一下嘛?感激不尽~

ValueError Bugfix

diff --git a/czsc/cobra/backtest.py b/czsc/cobra/backtest.py
index bc9a032..bc15a3d 100644
--- a/czsc/cobra/backtest.py
+++ b/czsc/cobra/backtest.py
@@ -67,8 +67,8 @@ def long_trade_estimator(pairs: List[dict]):
     """
     if not pairs:
         return {
-            '标的代码': pairs[0]['标的代码'],
-            '交易次数': len(pairs),
+            '标的代码': '', #pairs[0]['标的代码'],
+            '交易次数': 0, #len(pairs),
             '累计收益(%)': 0,
             '单笔收益(%)': 0,
             '平均持仓分钟': 0,
@@ -86,11 +86,11 @@ def long_trade_estimator(pairs: List[dict]):
         '平均持仓分钟': int(df['持仓分钟'].mean()),
         '累计收益(%)': x_round(df['盈亏(%)'].sum()),
         '单笔收益(%)': x_round(df['盈亏(%)'].mean()),
-        '胜率(%)': int(len(df[df['盈亏(%)'] > 0]) / len(df) * 10000) / 100,
-        '累计盈亏比': int(df[df['盈亏(%)'] > 0]['盈亏(%)'].sum() /
-                     abs(df[df['盈亏(%)'] < 0]['盈亏(%)'].sum()) * 100) / 100,
-        '单笔盈亏比': int(df[df['盈亏(%)'] > 0]['盈亏(%)'].mean() /
-                     abs(df[df['盈亏(%)'] < 0]['盈亏(%)'].mean()) * 100) / 100,
+        '胜率(%)': None if len(df)==0 else int(len(df[df['盈亏(%)'] > 0]) / len(df) * 10000) / 100,
+        '累计盈亏比': None if pd.isna(df[df['盈亏(%)'] > 0]['盈亏(%)'].sum()) or abs(df[df['盈亏(%)'] < 0]['盈亏(%)'].sum())==0 else int(df[df['盈亏(%)'] > 0]['盈亏(%)'].sum() /
+                                                                                                             abs(df[df['盈亏(%)'] < 0]['盈亏(%)'].sum()) * 100) / 100,
+        '单笔盈亏比': None if pd.isna(df[df['盈亏(%)'] > 0]['盈亏(%)'].mean()) or pd.isna(abs(df[df['盈亏(%)'] < 0]['盈亏(%)'].mean())) else int(df[df['盈亏(%)'] > 0]['盈亏(%)'].mean() /
+                                                                                                                   abs(df[df['盈亏(%)'] < 0]['盈亏(%)'].mean()) * 100) / 100 ,
     }
 
     res['持仓每分钟BP'] = round(res['累计收益(%)'] * 100 / df['持仓分钟'].sum(), 4)

版本202003 线段 划分 错误

上海A股603982,日线数据(20190522-20200306),基于全部日K线进行划分,使用KlineAnalyze函数,输出如下:

print("线段:", ka.xd, "\n")
print("中枢:", ka.zs, "\n")

线段: [{'dt': '2019-06-12', 'fx_mark': 'g', 'xd': 35.65}, {'dt': '2019-11-29', 'fx_mark': 'd', 'xd': 15.4}]
中枢: []

由图知2019年11月29日之后,又出现低点(20200204),所以线段结束位置要发生变化。与线段输出不符。
特告知。感谢分享。

关于笔的确认问题

假设有一个顶分型 ,后面接一个底分型,但是 两个分型之间的不足7跟,会触发一个问题,
如果第二个底分型的最低点比前面那个底分型的低点高,第二个底分型是选不中的,因为前面的代码要求选出最低的底分型
后面就可能触发破坏两笔

如下图是做了包含处理之后,按逻辑可能选出来的是 蓝色线,期望是 红色线
fxb 可不可以选出一个备用的,如果 两个分型之间的不足7跟,就用这个备用的来
image

jq_check_acc使用传入rawbars的疑问,用日线收盘价作为触发信号

1.生成的信号如下 我的基础bars 是60分钟的,生成日线的数据,我信号时想用日线的收盘价作为触发信号。
#生成信号的函数
def get_signals(c: CZSC) -> OrderedDict:
#c就是那基础bars 生成的高一级别的bars
s = OrderedDict({"symbol": c.symbol, "dt": c.bars_raw[-1].dt, "close": c.bars_raw[-1].close})
#print(s)
if c.freq == Freq.D:

    s.update(get_s_shunxu(c, di=1))
return s

2.ta.py里写的信号如下
def get_s_shunxu(c: analyze.CZSC, di: int = 1) -> OrderedDict:
"""倒数第i根K线的三K形态信号

:param c: CZSC 对象
:param di: 最近一根K线为倒数第i根
:return: 信号字典
"""

global guancha
global shaixq
assert di >= 1
freq: Freq = c.freq
k1 = str(freq.value)
k2 = f"倒{di}K"
s = OrderedDict()
v = Signal(k1=k1, k2=k2, k3="shunxu", v1="其他", v2='其他', v3='其他')
s[v.key] = v.value  #i['日线_倒1K_结束']=='是_任意_任意_0'
#tri1=c.bars_raw[-len(c.bars_raw):-1]  #因为最后一根是未完成的,由4根60分钟走完后,才形成一根完整的日线,不能要这句代码,因为这样生产的信号,实际生产的信号是11.16日,但是系统记录的时间是最新那一根,也就是最后一根的日期,11.17日
tri1 = c.bars_raw
print('传入数量%s' % (len(tri1)))
print('传入数据1%s' % (tri1[-1]))
if len(tri1) < 20:
    return s

3.但是打印的出来传入数量,发生了疑问。
3-1.102、103 最后一根都是日线一根一根传入,这个符合我日线收盘价触发信号的数据,但是到了105,最后一根就变成了60分钟,60分钟,60分钟,60分钟,其中最后一根的60分钟就是合成的日线数据。
传入数量102
传入数据1RawBar(symbol='sz.002771', id=123, dt=Timestamp('2015-12-28 00:00:00'), freq=<Freq.D: '日线'>, open=50.63, close=51.75, high=53.21, low=50.18, vol=3992600, amount=None, pctChg=None)
传入数量103
传入数据1RawBar(symbol='sz.002771', id=124, dt=Timestamp('2015-12-29 00:00:00'), freq=<Freq.D: '日线'>, open=49.75, close=47.23, high=51.01, low=46.58, vol=3154500, amount=None, pctChg=None)
传入数量104
传入数据1RawBar(symbol='sz.002771', id=125, dt=Timestamp('2015-12-30 00:00:00'), freq=<Freq.D: '日线'>, open=47.26, close=47.85, high=48.19, low=45.47, vol=1508000, amount=None, pctChg=None)
generate snapshots of sz.002771: 0%| | 0/5642 [00:00<?, ?it/s]传入数量104
传入数据1RawBar(symbol='sz.002771', id=125, dt=Timestamp('2015-12-30 00:00:00'), freq=<Freq.D: '日线'>, open=47.26, close=46.97, high=48.19, low=45.47, vol=1809800, amount=None, pctChg=None)
传入数量105
传入数据1RawBar(symbol='sz.002771', id=126, dt=Timestamp('2015-12-31 00:00:00'), freq=<Freq.D: '日线'>, open=46.62, close=46.49, high=46.97, low=45.27, vol=643100, amount=None, pctChg=None)
传入数量105
传入数据1RawBar(symbol='sz.002771', id=126, dt=Timestamp('2015-12-31 00:00:00'), freq=<Freq.D: '日线'>, open=46.62, close=45.32, high=46.97, low=45.27, vol=975400, amount=None, pctChg=None)
传入数量105
传入数据1RawBar(symbol='sz.002771', id=126, dt=Timestamp('2015-12-31 00:00:00'), freq=<Freq.D: '日线'>, open=46.62, close=45.04, high=46.97, low=44.18, vol=1319500, amount=None, pctChg=None)
传入数量105
3-2 像109这时候才传入2根60分钟
传入数量108
传入数据1RawBar(symbol='sz.002771', id=129, dt=Timestamp('2016-01-06 00:00:00'), freq=<Freq.D: '日线'>, open=41.67, close=43.73, high=45.76, low=41.21, vol=1432200, amount=None, pctChg=None)
传入数量108
传入数据1RawBar(symbol='sz.002771', id=129, dt=Timestamp('2016-01-06 00:00:00'), freq=<Freq.D: '日线'>, open=41.67, close=44.02, high=45.76, low=41.21, vol=1833700, amount=None, pctChg=None)
传入数量108
传入数据1RawBar(symbol='sz.002771', id=129, dt=Timestamp('2016-01-06 00:00:00'), freq=<Freq.D: '日线'>, open=41.67, close=44.09, high=45.76, low=41.21, vol=2005700, amount=None, pctChg=None)
传入数量108
传入数据1RawBar(symbol='sz.002771', id=129, dt=Timestamp('2016-01-06 00:00:00'), freq=<Freq.D: '日线'>, open=41.67, close=44.73, high=45.76, low=41.21, vol=2331700, amount=None, pctChg=None)
传入数量109
传入数据1RawBar(symbol='sz.002771', id=130, dt=Timestamp('2016-01-07 00:00:00'), freq=<Freq.D: '日线'>, open=43.19, close=40.26, high=43.36, low=40.26, vol=446000, amount=None, pctChg=None)
传入数量109
传入数据1RawBar(symbol='sz.002771', id=130, dt=Timestamp('2016-01-07 00:00:00'), freq=<Freq.D: '日线'>, open=43.19, close=40.28, high=43.36, low=40.26, vol=461300, amount=None, pctChg=None)
传入数量110
传入数据1RawBar(symbol='sz.002771', id=131, dt=Timestamp('2016-01-08 00:00:00'), freq=<Freq.D: '日线'>, open=40.85, close=41.8, high=42.19, low=37.5, vol=807100, amount=None, pctChg=None)
传入数量110
传入数据1RawBar(symbol='sz.002771', id=131, dt=Timestamp('2016-01-08 00:00:00'), freq=<Freq.D: '日线'>, open=40.85, close=40.54, high=42.19, low=36.38, vol=1344100, amount=None, pctChg=None)
传入数量110
传入数据1RawBar(symbol='sz.002771', id=131, dt=Timestamp('2016-01-08 00:00:00'), freq=<Freq.D: '日线'>, open=40.85, close=41.18, high=42.19, low=36.38, vol=1504100, amount=None, pctChg=None)
传入数量110
传入数据1RawBar(symbol='sz.002771', id=131, dt=Timestamp('2016-01-08 00:00:00'), freq=<Freq.D: '日线'>, open=40.85, close=39.69, high=42.19, low=36.38, vol=1775300, amount=None, pctChg=None)
传入数量111

求老大解疑答惑

tushare用分钟数据,date格式有误

ts.py
分钟数据格式
dt_fmt = "%Y-%m-%d %H:%M:%S"

这个格式是参考了tushare的接口文档。实际使用中,发现这个格式是错误的,即tushare文档错误,应该还是用"%Y%m%d"

这个问题我也跟tushare的Jimmy说了

关于缠论多种分解的一些想法

感谢zengin93,后生可畏。

缠师说炒股是艺术而不是技术,而软件只能实现技术的部分。我在想有没有一种连接艺术和技术的东西。

对于缠论来说,不确定性来源于走势的灵活组合和分解,能不能在页面上,给出多种可能的分解。就像在地图上导航从A到B,会有4条路线,都会在地图上显示出来。类似,我们能不能展示出多种可能的组合,用户可以选择自己最合适的组合来操作。

支持从csv里面直接读取股票信息

现在的get_kline是从Tushare上获取的,对于一些不方便访问服务器的(比如:离线研究),可以支持get_kline_from_csv会好一些,我试着添加了一下,但是比较死板:(,如果你的代码也可以支持就更好了,谢谢

回测过程中的止损止盈?

回测的时候,当日线三买出现后买入,买入后跌5%卖出,涨10%也卖出。这个止损止盈的因子该怎么写?有没有可以参考的例子?谢谢。

代码错误

感谢开源的代码,factors.py文件check_triple_level函数中,出现如下错误:

c2_h9 = max([x.high for x in c2.bi_list[-9:]])
c2_l9 = max([x.high for x in c2.bi_list[-9:]])

应改为

c2_l9 = max([x.low for x in c2.bi_list[-9:]])

另外关于因为跳空出现超长笔的问题解决了吗?

:sparkles: **Welcome to GitHub Projects** :sparkles:

We're so excited that you've decided to create a new project! Now that you're here, let's make sure you know how to get the most out of GitHub Projects.

  • Create a new project
  • Give your project a name
  • Press the ? key to see available keyboard shortcuts
  • Add a new column
  • Drag and drop this card to the new column
  • Search for and add issues or PRs to your project
  • Manage automation on columns
  • Archive a card or archive all cards in a column

因特殊分型导致笔识别失败

SHFE.hc2201 期货热轧
数据周期:1分钟
时间: 2021-11-25 13:00 ——2021-11-26 10:00
出现问题:因为一个特殊巨型分型,导致笔识别错误,已生成笔回撤,无法生成新的笔,具体如下
image

出错位置
image

使用0.71版本中 check_fx 替换之后可以正常
image

程序识别结果与原文线段划分图的对比

利用业余时间用 python 实现了缠论的主要逻辑,代码已开源至 github:https://github.com/zengbin93/czsc

说明: 在没有正式介绍分型、笔、线段的划分标准之前,博客原文线段划分并没有严格按照定义来。所以,前面的识别结果重合率较低。

2007-05-31 22:35 教你炒股票57:当下图解分析再示范


http://blog.sina.com.cn/s/blog_486e105c01000ax3.html
原文划分

程序识别

2007-06-04 22:34 教你炒股票58:图解分析示范三


http://blog.sina.com.cn/s/blog_486e105c01000az8.html

原文划分

程序识别

2007-06-14 08:23 教你炒股票59:图解分析示范四


http://blog.sina.com.cn/s/blog_486e105c01000b52.html

原文划分1

程序识别1

原文划分2

程序识别2

原文划分3

程序识别3

2007-06-19 08:04 教你炒股票60:图解分析示范五


http://blog.sina.com.cn/s/blog_486e105c01000b83.html

原文划分

程序识别

2007-06-21 08:13 教你炒股票61:区间套定位标准图解(分析示范六)


http://blog.sina.com.cn/s/blog_486e105c01000b9n.html

原文划分

程序识别

2007-06-28 15:53 一根筋是不适合玩震荡行情的


http://blog.sina.com.cn/s/blog_486e105c01000bdx.html

原文划分

程序识别

2007-06-29 15:45 解盘并说说中短线走势


http://blog.sina.com.cn/s/blog_486e105c01000beh.html

原文划分

程序识别

0.8.X 版本开发

交易就像开车,你可以追求快,可以追求稳,也可以追求又快又稳。你能否实现你的追求,首先取决于你是否有一个不错的感应系统,然后是要有一个牛逼的应对策略。

“信号 - 因子 - 事件” 仅仅是一种表达语言,0.8开始引入 “感应系统(sensors)”。

兼容高版本Pandas

运行时报错,能不能兼容高版本Pandas?

0.5.7
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-6-7f795f6d0af7> in <module>
     16 
     17 # 导入 tushare 数据
---> 18 from czsc.data.ts import *
     19 
     20 from plot import *

~/.local/lib/python3.6/site-packages/czsc/data/ts.py in <module>
      1 # coding: utf-8
      2 import pandas as pd
----> 3 import tushare as ts
      4 from datetime import datetime, timedelta
      5 

/opt/conda/lib/python3.6/site-packages/tushare/__init__.py in <module>
      9 for trading data
     10 """
---> 11 from tushare.stock.trading import (get_hist_data, get_tick_data,
     12                                    get_today_all, get_realtime_quotes,
     13                                    get_h_data, get_today_ticks,

/opt/conda/lib/python3.6/site-packages/tushare/stock/trading.py in <module>
     18 from tushare.stock import cons as ct
     19 import re
---> 20 from pandas.compat import StringIO
     21 from tushare.util import dateu as du
     22 from tushare.util.formula import MA

ImportError: cannot import name 'StringIO'

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.