Skip to content

Commit

Permalink
0.9.5 更新一批信号 (waditu#112)
Browse files Browse the repository at this point in the history
* 0.9.5 start coding

* 0.9.5 新增飞书API封装函数

* 0.9.5 新增飞书API封装函数

* 0.9.5 更新一批信号

* 0.9.5 update

* 更新Python支持版本

* 0.9.5 update time span

* 0.9.5 更新一批信号
  • Loading branch information
zengbin93 authored Dec 18, 2022
1 parent 80537f5 commit 9c95f24
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 6 deletions.
2 changes: 1 addition & 1 deletion czsc/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def dummy(file_strategy):
dfs = pd.read_pickle(file_dfs)
else:
ts_code, asset = symbol.split('#')
dfs = generate_symbol_signals(dc, ts_code, asset, "20150101", "20220101", strategy, 'hfq')
dfs = generate_symbol_signals(dc, ts_code, asset, "20170101", "20221001", strategy, 'hfq')
dfs.to_pickle(file_dfs)

cdt = CzscDummyTrader(dfs, strategy)
Expand Down
1 change: 1 addition & 0 deletions czsc/signals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
bar_zdf_V221203,
bar_accelerate_V221110,
bar_accelerate_V221118,
bar_fang_liang_break_V221216,
)

from czsc.signals.jcc import (
Expand Down
64 changes: 61 additions & 3 deletions czsc/signals/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
create_dt: 2022/11/11 20:18
describe: bar 作为前缀,代表信号属于基础 K 线信号
"""
import numpy as np
from datetime import datetime
from typing import List
from collections import OrderedDict
Expand Down Expand Up @@ -58,7 +59,9 @@ def bar_zdt_V221110(c: CZSC, di=1) -> OrderedDict:
对于A股,任何K线,只要收盘价是最高价,那就不能买,只要收盘价是最低价,就不能卖。
**信号逻辑:** close等于high大于前close,近似认为是涨停;反之,跌停。
**信号逻辑:**
close等于high大于前close,近似认为是涨停;反之,跌停。
**信号列表:**
Expand Down Expand Up @@ -145,7 +148,9 @@ def bar_zdt_V221111(cat: CzscAdvancedTrader, freq: str, di: int = 1) -> OrderedD
def bar_vol_grow_V221112(c: CZSC, di: int = 2, n: int = 5) -> OrderedDict:
"""倒数第 i 根 K 线的成交量相比于前 N 根 K 线放量
**信号逻辑: ** 放量的定义为,倒数第i根K线的量能 / 过去N根的平均量能,在2-4倍之间。
**信号逻辑: **
放量的定义为,倒数第i根K线的量能 / 过去N根的平均量能,在2-4倍之间。
**信号列表:**
Expand Down Expand Up @@ -174,10 +179,63 @@ def bar_vol_grow_V221112(c: CZSC, di: int = 2, n: int = 5) -> OrderedDict:
return s


def bar_fang_liang_break_V221216(c: CZSC, di: int = 1, th=300, ma1="SMA233") -> OrderedDict:
"""放量向上突破并回踩指定均线,贡献者:琅盎
**信号逻辑:**
1. 放量突破
2. 缩量回踩,最近一根K线的成交量小于前面一段时间的均量
**信号列表:**
- Signal('日线_D1TH300_突破SMA233_放量突破_缩量回踩_任意_0')
:param c: CZSC对象
:param di: 信号计算截止倒数第i根K线
:param ma1: 指定均线,这里固定为年线
:param th: 当前最低价同指定均线的距离阈值,单位 BP
:return: 信号识别结果
"""

def _vol_fang_liang_break(bars: List[RawBar]):
if len(bars) <= 4:
return "其他", "其他"

# 条件1:放量突破
ma1v = bars[-1].cache[ma1]
c1 = "放量突破" if bars[-1].vol >= bars[-2].vol and bars[-1].close > ma1v else "其他"

# 条件2:缩量回踩
vol_min = np.mean([x.vol for x in bars[:-1]])
distance = all(abs(x.close / ma1v - 1) * 10000 <= th for x in bars[:-1])

if bars[-1].close >= ma1v and bars[-1].vol < vol_min and distance:
c2 = "缩量回踩"
else:
c2 = "其他"

return c1, c2

for n in (5, 6, 7, 8, 9):
_bars = get_sub_elements(c.bars_raw[300:], di=di, n=n)
v1, v2 = _vol_fang_liang_break(_bars)
if v1 != "其他":
break

k1, k2, k3 = f"{c.freq.value}_D{di}TH{th}_突破{ma1.upper()}".split('_')
s = OrderedDict()
signal = Signal(k1=k1, k2=k2, k3=k3, v1=v1, v2=v2)
s[signal.key] = signal.value
return s


def bar_mean_amount_V221112(c: CZSC, di: int = 1, n: int = 10, th1: int = 1, th2: int = 4) -> OrderedDict:
"""截取一段时间内的平均成交金额分类信号
**信号逻辑: ** 倒数第i根K线向前n根K线的成交金额均值在 th1 和 th2 之间
**信号逻辑: **
倒数第i根K线向前n根K线的成交金额均值在 th1 和 th2 之间
**信号列表:**
Expand Down
49 changes: 47 additions & 2 deletions czsc/signals/cxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import numpy as np
from loguru import logger
from typing import List
from czsc import CZSC, Signal
from czsc.objects import FX, BI, Direction
from czsc import CZSC, Signal, CzscAdvancedTrader
from czsc.objects import FX, BI, Direction, ZS
from czsc.utils import get_sub_elements
from collections import OrderedDict

Expand Down Expand Up @@ -252,3 +252,48 @@ def __check(bis: List[BI]):
s[signal.key] = signal.value
return s


def cxt_sub_b3_V221212(cat: CzscAdvancedTrader, freq='60分钟', sub_freq='15分钟', th=10) -> OrderedDict:
"""小级别突破大级别中枢形成三买,贡献者:魏永超
**信号逻辑:**
1. freq级别中产生笔中枢,最后一笔向上时,中枢由之前3笔构成;最后一笔向下时,中枢由最后3笔构成。
2. sub_freq级别中出现向上笔超越大级别中枢最高点,且随后的回落,不回到大级别中枢区间的th%以内。
**信号列表:**
- Signal('60分钟_15分钟_3买回踩10_确认_任意_任意_0')
:param cat:
:param freq: 中枢所在的大级别
:param sub_freq: 突破大级别中枢,回踩形成小级别类3买的小级别
:param th: 小级别回落对大级别中枢区间的回踩程度,0表示回踩不进大级别中枢,10表示回踩不超过中枢区间的10%
:return: 信号识别结果
"""
k1, k2, k3 = f"{freq}_{sub_freq}_三买回踩{th}".split('_')

c: CZSC = cat.kas[freq]
sub_c: CZSC = cat.kas[sub_freq]

v1 = "其他"
if len(c.bi_list) > 13 and len(sub_c.bi_list) > 10:
last_bi = c.bi_list[-1]
if last_bi.direction == Direction.Down:
zs = ZS(symbol=cat.symbol, bis=c.bi_list[-3:])
else:
zs = ZS(symbol=cat.symbol, bis=c.bi_list[-4:-1])

min7 = min([x.low for x in c.bi_list[-7:]])
# 中枢成立,且中枢最低点不是最后7笔的最低点,且最后7笔最低点同时也是最后13笔最低点(保证低点起来第一个中枢)
if zs.zd < zs.zg and zs.dd > min7 == min([x.low for x in c.bi_list[-13:]]):
last_sub_bi = sub_c.bi_list[-1]

if last_sub_bi.direction == Direction.Down and last_sub_bi.high > zs.gg \
and last_sub_bi.low > zs.zg - (th / 100) * (zs.zg - zs.zd):
v1 = "确认"

s = OrderedDict()
signal = Signal(k1=k1, k2=k2, k3=k3, v1=v1)
s[signal.key] = signal.value
return s

0 comments on commit 9c95f24

Please sign in to comment.