Skip to content

Commit

Permalink
V0.9.22 更新一批代码 (#154)
Browse files Browse the repository at this point in the history
* 0.9.22 start coding

* 0.9.22 更新信号函数

* 0.9.22 fix cci

* 0.9.22 新增几个信号函数

* 0.9.22 update

* 0.9.22 新增多维表格读取接口

* 0.9.22 新增信号函数

* 0.9.22 update

* 0.9.22 update

* 0.9.22 更新信号函数

* 0.9.22 更新信号函数

* 0.9.22 更新一批信号函数

* 0.9.22 update signals

* 0.9.22 新增EMV基础策略

* 0.9.22 新增固定止盈止损策略

* 0.9.22 fix bug: 识别笔的过程有个细节导致程序出错

* 0.9.22 update

* 0.9.22 update connectors

* 0.9.22 更新一批信号函数
  • Loading branch information
zengbin93 authored Jun 25, 2023
1 parent ce390fa commit 54b2e73
Show file tree
Hide file tree
Showing 63 changed files with 4,067 additions and 1,626 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Python package

on:
push:
branches: [ master, V0.9.21 ]
branches: [ master, V0.9.22 ]
pull_request:
branches: [ master ]

Expand Down
4 changes: 2 additions & 2 deletions czsc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
from czsc.utils.signal_analyzer import SignalAnalyzer, SignalPerformance


__version__ = "0.9.21"
__version__ = "0.9.22"
__author__ = "zengbin93"
__email__ = "zeng_bin8888@163.com"
__date__ = "20230601"
__date__ = "20230616"


def welcome():
Expand Down
17 changes: 5 additions & 12 deletions czsc/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,9 @@ def check_fxs(bars: List[NewBar]) -> List[FX]:
for i in range(1, len(bars)-1):
fx = check_fx(bars[i-1], bars[i], bars[i+1])
if isinstance(fx, FX):
# 这里可能隐含Bug,默认情况下,fxs本身是顶底交替的,但是对于一些特殊情况下不是这样,这是不对的。
# 临时处理方案,强制要求fxs序列顶底交替
# 默认情况下,fxs本身是顶底交替的,但是对于一些特殊情况下不是这样; 临时强制要求fxs序列顶底交替
if len(fxs) >= 2 and fx.mark == fxs[-1].mark:
if envs.get_verbose():
logger.info(f"\n\ncheck_fxs: 输入数据错误{'+' * 100}")
logger.info(f"当前:{fx.mark}, 上个:{fxs[-1].mark}")
for bar in fx.raw_bars:
logger.info(f"{bar}\n")

logger.info('last fx raw bars: \n')
for bar in fxs[-1].raw_bars:
logger.info(f"{bar}\n")
logger.error(f"check_fxs错误: {bars[i].dt}{fx.mark}{fxs[-1].mark}")
else:
fxs.append(fx)
return fxs
Expand Down Expand Up @@ -232,7 +223,9 @@ def __update_bi(self):
bars_ubi = self.bars_ubi
if (last_bi.direction == Direction.Up and bars_ubi[-1].high > last_bi.high) \
or (last_bi.direction == Direction.Down and bars_ubi[-1].low < last_bi.low):
self.bars_ubi = last_bi.bars[:-1] + [x for x in bars_ubi if x.dt >= last_bi.bars[-1].dt]
# 当前笔被破坏,将当前笔的bars与bars_ubi进行合并,并丢弃,这里容易出错,多一根K线就可能导致错误
# 必须是 -2,因为最后一根无包含K线有可能是未完成的
self.bars_ubi = last_bi.bars[:-2] + [x for x in bars_ubi if x.dt >= last_bi.bars[-2].dt]
self.bi_list.pop(-1)

def update(self, bar: RawBar):
Expand Down
34 changes: 34 additions & 0 deletions czsc/connectors/ts_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
"""
author: zengbin93
email: zeng_bin8888@163.com
create_dt: 2023/6/24 18:49
describe: Tushare数据源
"""
import os
from czsc import data

dc = data.TsDataCache(data_path=os.environ.get('ts_data_path', r'D:\ts_data'))


def get_symbols(step):
if step.upper() == 'ALL':
return data.get_symbols(dc, 'index') + data.get_symbols(dc, 'stock') + data.get_symbols(dc, 'etfs')
return data.get_symbols(dc, step)


def get_raw_bars(symbol, freq, sdt, edt, fq='后复权', raw_bar=True):
"""读取本地数据"""
ts_code, asset = symbol.split("#")
freq = str(freq)
adj = "qfq" if fq == "前复权" else "hfq"

if "分钟" in freq:
freq = freq.replace("分钟", "min")
bars = dc.pro_bar_minutes(ts_code, sdt=sdt, edt=edt, freq=freq, asset=asset, adj=adj, raw_bar=raw_bar)

else:
_map = {"日线": "D", "周线": "W", "月线": "M"}
freq = _map[freq]
bars = dc.pro_bar(ts_code, start_date=sdt, end_date=edt, freq=freq, asset=asset, adj=adj, raw_bar=raw_bar)
return bars
Loading

0 comments on commit 54b2e73

Please sign in to comment.