vespa314 / chan.py Goto Github PK
View Code? Open in Web Editor NEW开放式的缠论python实现框架,支持形态学/动力学买卖点分析计算,多级别K线联立,区间套策略,可视化绘图,多种数据接入,策略开发,交易系统对接;
License: MIT License
开放式的缠论python实现框架,支持形态学/动力学买卖点分析计算,多级别K线联立,区间套策略,可视化绘图,多种数据接入,策略开发,交易系统对接;
License: MIT License
main.py 画图是对的,但是这个demo里面打印出来的信息是错的,比如浪潮信息,demo里面2022/9/22出了个买点,但是实际并不是,main.py画的图应该是在10月11号。
祝大佬元旦快乐。
Traceback (most recent call last):
File "", line 1, in
File "/Users/masonchen/Repos/chan.py/Common/cache.py", line 32, in call
result = self.func(*args, **kwargs)
File "/Users/masonchen/Repos/chan.py/Bi/Bi.py", line 212, in Cal_Rsi
rsi_lst.extend(klu.rsi for klu in klc.lst)
File "/Users/masonchen/Repos/chan.py/Bi/Bi.py", line 212, in
rsi_lst.extend(klu.rsi for klu in klc.lst)
AttributeError: 'CKLine_Unit' object has no attribute 'rsi'
draw_macd这个函数会把历史所有值都绘画一次,所以在回放时,会越来越卡
可否改进这个机制呢,只绘制近期的值
git下来跑README.md的demo示例代码
chan = CChan(
code="HK.00700",
begin_time="2012-01-01",
end_time=None,
data_src=DATA_SRC.FUTU, # 数据来源,
lv_list=[KL_TYPE.K_DAY], # 多级别可以从大到小传入
config=config,
autype=AUTYPE.QFQ,
extra_kl=None,
)
里的DATA_SRC.FUTU在Chan.py里没有定义
def GetStockAPI(src):
_dict = {}
if src == DATA_SRC.BAO_STOCK:
from DataAPI.BaoStockAPI import CBaoStock
_dict[DATA_SRC.BAO_STOCK] = CBaoStock
if src == DATA_SRC.CCXT:
from DataAPI.ccxt import CCXT
_dict[DATA_SRC.CCXT] = CCXT
只有如上两个
逐帧动画好像有问题,每帧都是新开一个窗口一闪而过,没有逐帧播放动画
No module named 'KLine'
No module named 'ChanConfig'
请问能更新下这两个包吗?
如题
该函数有一定几率可能触发该错误
File "/home/mjzs/.local/lib/python3.10/site-packages/cchan/ZS/ZS.py", line 211, in out_bi_is_peak
r = abs(bi.get_end_val()-self.bi_out.get_end_val())/self.bi_out.get_end_val()
ZeroDivisionError: float division by zero
猛一看功能很全啊,仔细一看……
can_be_end
函数的作用是判断特征序列分型是否结束,并考虑线段的两种情况:特征序列中第一和第二元素间存在特征序列的缺口。其中如果存在缺口时调用find_revert_fx
函数寻找反向分型。
break_thred
参数的含义是为了判断判断特征序列缺口是否笔合,那么当线段是向上时,break_thred
应该是self.ele[0].high
,反向特征序列的第二个元素的低点低于此值即表明闭合,这个逻辑可以从find_revert_fx
函数逻辑得到佐证。
因此break_thred = self.ele[0].low if self.is_up() else self.ele[0].high
应改为
break_thred = self.ele[0].high if self.is_up() else self.ele[0].low
def can_be_end(self, bi_lst: CBiList):
"""判断特征序列分型是否结束,并考虑线段的两种情况:特征序列中第一和第二元素间存在特征序列的缺口"""
assert self.ele[1] is not None
if self.ele[1].gap: # 第二特征序列相对第一个特征序列有缺口,线段的第二种情况
assert self.ele[0] is not None
end_bi_idx = self.GetPeakBiIdx()
thred_value = bi_lst[end_bi_idx].get_end_val() #线段的端点
break_thred = self.ele[0].low if self.is_up() else self.ele[0].high #TODO:此处写错了,break_thred值是为了判断特征序列缺口是否笔合,那么当线段是向上时,break_thred应该是self.ele[0].high
return self.find_revert_fx(bi_lst, end_bi_idx+2, thred_value, break_thred)
else:
return True
如果需要从snapshot获取原始K线序列进行一些计算(例如计算技术指标),似乎只能通过在KLine.KLine_List.CKLine_List中层层循环获取原始K线属性,效率很低。
您好,在chan.py\DataAPI\BaoStockAPI.py line 1:
import baostock as bs
会出现标题中的问题。这部分可以共享嘛?
tg?Discord?slack?不太清楚可以用科学上网的人的比例;
还是用我自建私用的mattermost?暂时不太想用微信或QQ。。
或者就用github的discussions吧?
能否让Seg也具有@make_cache缓存计算结果的能力呢?因为我在Seg内部写了一些特征计算。我这边加了,但是不确定什么时候clean_cache,只能怀疑是内部元素变动时候,不确定加的是否正确,应该是这些方法结束时需要clean:add_zs、update_bi_list,不确定set_seg_idx后是否需要clean
def clean_cache(self): self._memoize_cache = {}
1.x_tick_num 没生效
建议:
only_top_lv 改为需要展示的层级,比如我日线,60分钟,30分钟,我只想看30分钟.但是其实60分钟的特殊笔需要根据上一级别或者下一级别来判断.这样我list里面就有数据了.
我学习的缠论需要同时获取上一级别和下一级别的笔和线段线.应该如何改写更加合理
1.本级别和次级别同笔的处理方式 本级别 当笔,次级别 当段
2.本级别不够笔,次级别够线段 本级别 当笔
login success!
logout success!
Traceback (most recent call last):
File "D:\stock-chan\chan.py-main\Debug\strategy_demo.py", line 34, in
for chan_snapshot in chan.step_load(): # 每增加一根K线,返回当前静态精算结果
File "D:\stock-chan\chan.py-main\Chan.py", line 122, in step_load
for idx, snapshot in enumerate(self.load(self.conf.trigger_step)):
File "D:\stock-chan\chan.py-main\Chan.py", line 198, in load
yield from self.load_iterator(lv_idx=0, parent_klu=None, step=step) # 计算入口
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\stock-chan\chan.py-main\Chan.py", line 242, in load_iterator
kline_unit = self.get_next_lv_klu(lv_idx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\stock-chan\chan.py-main\Chan.py", line 110, in get_next_lv_klu
return self.g_kl_iter[lv_idx][0].next()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\stock-chan\chan.py-main\Chan.py", line 89, in load_stock_data
for KLU_IDX, klu in enumerate(stockapi_instance.get_kl_data()):
File "D:\stock-chan\chan.py-main\DataAPI\BaoStockAPI.py", line 81, in get_kl_data
raise Exception(rs.error_msg)
Exception: 请求数据类型不正确
rt
CChanException: kline time err, cur=2024/07/02 00:30, last=2024/07/02
Traceback:
File "C:\Users\apple.conda\envs\py311\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 589, in _run_script
exec(code, module.dict)
File "C:\Users\apple\AppData\Roaming\MetaQuotes\Terminal\BD115B570DAF19795DD0BA0C4463675D\MQL5\Experts\Vespa314\App.py", line 192, in
run_chanlun(code=code, begin_time=begin_time, end_time=end_time, market_type=market_type,
File "C:\Users\apple\AppData\Roaming\MetaQuotes\Terminal\BD115B570DAF19795DD0BA0C4463675D\MQL5\Experts\Vespa314\App.py", line 93, in run_chanlun
chan = CChan(
^^^^^^
File "C:\Users\apple\AppData\Roaming\MetaQuotes\Terminal\BD115B570DAF19795DD0BA0C4463675D\MQL5\Experts\Vespa314\Chan.py", line 50, in init
for _ in self.load():
"C:\Users\apple\AppData\Roaming\MetaQuotes\Terminal\BD115B570DAF19795DD0BA0C4463675D\MQL5\Experts\Vespa314\Chan.py", line 205, in load
yield from self.load_iterator(lv_idx=0, parent_klu=None, step=step) # 计算入口
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\apple\AppData\Roaming\MetaQuotes\Terminal\BD115B570DAF19795DD0BA0C4463675D\MQL5\Experts\Vespa314\Chan.py", line 252, in load_iterator
raise CChanException(f"kline time err, cur={kline_unit.time}, last={self.klu_last_t[lv_idx]}",
计算这个指标的时候,似乎没有必要除以 end_klu.high 或 begin_klu.high。而且这么做了之后该指标的值会可能变得非常小(可能小于0.0001)
def Cal_MACD_slope(self):
begin_klu = self.get_begin_klu()
end_klu = self.get_end_klu()
if self.is_up():
return (end_klu.high - begin_klu.low)/end_klu.high/(end_klu.idx - begin_klu.idx + 1)
else:
return (begin_klu.high - end_klu.low)/begin_klu.high/(end_klu.idx - begin_klu.idx + 1)
大佬,v3开发进度如何了,交易引擎与策略类这两个剥离出来了吗,有打算在v3版本开放交易引擎与策略类这两个模块吗
该Demo脚本中保存策略特征的方式是根据买卖点的idx进行键值对存储。但是,对于同一个idx,可能被不同时间多次出现。这种方式只能存储同idx一最后一次出现的BSP特征。是否应该使用time作为key保存?
# 跑策略,保存买卖点的特征
for chan_snapshot in chan.step_load():
last_klu = chan_snapshot[0][-1][-1]
bsp_list = chan_snapshot.get_bsp()
if not bsp_list:
continue
last_bsp = bsp_list[-1]
cur_lv_chan = chan_snapshot[0]
if last_bsp.klu.idx not in bsp_dict and cur_lv_chan[-2].idx == last_bsp.klu.klc.idx:
# 假如策略是:买卖点分形第三元素出现时交易
bsp_dict[last_bsp.klu.idx] = {
"feature": last_bsp.features,
"is_buy": last_bsp.is_buy,
"open_time": last_klu.time,
}
bsp_dict[last_bsp.klu.idx]['feature'].add_feat(stragety_feature(last_klu)) # 开仓K线特征
print(last_bsp.klu.time, last_bsp.is_buy)
看文档功能好全面,好想用起来,哈哈
from typing import Generic, Iterable, List, Optional, Self, TypeVar, Union, overload
ImportError: cannot import name 'Self' from 'typing'
为了方便体验和调试,不知道有没有前端大佬想一起来开发个页面工具?
后端功能基本是具备的。
如题,我想通过这个训练一下准确性
我看回测案例中 stragety_demo2.py 的模板只有一个区间.如果是多区间
lv_list = [KL_TYPE.K_60M, KL_TYPE.K_15M, KL_TYPE.K_3M]
data_src = stockapi_cls(code, k_type = lv_list, begin_date=begin_time, end_date=end_time, autype=AUTYPE.QFQ)
如果这样写 在进行循环是会报错的 data_src.get_kl_data()
能帮写个例子吗
根据反馈,当前画图是基于matplotlib的静态图,其实查看和调试都不方便;
调用后看起来可行的是再支持一个基于plotly的画图引擎,画可交互的图。
老板,看了你发布的东西,很感兴趣,怎么联系你呢
`Traceback (most recent call last):
File "D:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 2963, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
from Chan import CChan
File "D:\chan.py\Chan.py", line 12, in
from KLine.KLine_List import CKLine_List
File "D:\chan.py\KLine\KLine_List.py", line 5, in
from BuySellPoint.BSPointList import CBSPointList
File "D:\chan.py\BuySellPoint\BSPointList.py", line 8, in
from Seg.SegListComm import CSegListComm
File "D:\chan.py\Seg\SegListComm.py", line 92
if peak_bi := FindPeakBi(bi_lst[last_seg_end_bi.idx+3:], is_high=True):
^
SyntaxError: invalid syntax`
^_^语法错误是我没想到的,哈哈哈哈
在readme里的代码结构图,标明了有这个模块,但是代码里没有,方便补充一下吗
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.