Skip to content

Commit

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

* 0.9.14 update action

* 0.9.14 update

* 0.9.14 update

* 0.9.14 更新一批信号函数

* 0.9.14 更新一批信号函数

* 0.9.14 更新一批信号函数

* Xuming (#134)

* 准备好czsc_qmt_checkpoint_xm.py,打算进行策略选择和开平仓显示开发

* 添加check.bat,调整height

* 添加了一个自己的指标,变成了4 row

* 实现了策略买卖点的显示

* sdt调整

* sdt调整

* 增加收益分析,修正bs_df为空的bug

* 增加收益分析,修正bs_df为空的bug

* 去掉了转parquet

* margin调整

* 支持了股票池和回测模式选择

* 支持了股票池和回测模式选择

* 支持了股票池和回测模式选择

* Delete check.bat

* Delete tcheck.bat

---------

Co-authored-by: zengbin93 <[email protected]>

* 0.9.14 fix bug

* 0.9.14 新增收益计算函数

* 0.9.14 优化绘图工具

* 0.9.14 update

* 0.9.14 新增信号解析模块

* 0.9.14 新增信号解析模块

* 0.9.14 新增截面IC计算函数

* 0.9.14 优化 Position 对象

* 0.9.14 优化策略模板

* 0.9.14 update

* 0.9.14 update

* 0.9.14 update

* 0.9.14 update

* 0.9.14 update

* 0.9.14 新增 RBreaker 信号

* 0.9.14 新增 unique signals 属性

* 0.9.14 新增 unique signals 属性

* 0.9.14 优化 freqs 验证方法

* 0.9.14 update

* 0.9.14 update

* 0.9.14 优化 Event

* 0.9.14 update

* 0.9.14 update

* 0.9.14 update

* 0.9.14 update

* 0.9.14 支持不写 get_signals 直接创建策略

* 0.9.14 支持不写 get_signals 直接创建策略

* 0.9.14 update

* 0.9.14 update

---------

Co-authored-by: ming-mingxu <[email protected]>
  • Loading branch information
zengbin93 and ming-mingxu authored Mar 31, 2023
1 parent 6d9d861 commit 86c6370
Show file tree
Hide file tree
Showing 40 changed files with 2,312 additions and 1,338 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.13 ]
branches: [ master, V0.9.14 ]
pull_request:
branches: [ master ]

Expand Down
14 changes: 9 additions & 5 deletions czsc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
from czsc.utils.cache import home_path, get_dir_size, empty_cache_path
from czsc.traders import CzscTrader, CzscSignals, generate_czsc_signals, check_signals_acc, get_unique_signals
from czsc.traders import PairsPerformance, combine_holds_and_pairs, combine_dates_and_pairs, stock_holds_performance
from czsc.traders import DummyBacktest
from czsc.traders import DummyBacktest, SignalsParser, get_signals_by_conf, get_signals_config, get_signals_freqs
from czsc.strategies import CzscStrategyBase
from czsc.utils import KlineChart, BarGenerator, resample_bars, dill_dump, dill_load, read_json, save_json
from czsc.utils import get_sub_elements, get_py_namespace, freqs_sorted, x_round, import_by_name, create_grid_params
from czsc.utils import cal_trade_price
from czsc.utils import cal_trade_price, cross_sectional_ic
from czsc.sensors import holds_concepts_effect, StocksDaySensor, ThsConceptsSensor, SignalsPerformance


__version__ = "0.9.13"
__version__ = "0.9.14"
__author__ = "zengbin93"
__email__ = "[email protected]"
__date__ = "20230314"
__date__ = "20230323"


if envs.get_welcome():
def welcome():
print(f"欢迎使用CZSC!当前版本标识为 {__version__}@{__date__}\n")
aphorism.print_one()

Expand All @@ -40,5 +40,9 @@
f"czsc_bi_change_th = {envs.get_bi_change_th()}")


if envs.get_welcome():
welcome()


if get_dir_size(home_path) > pow(1024, 3) and envs.get_verbose():
print(f"{home_path} 目录缓存超过1GB,请适当清理。调用 czsc.empty_cache_path 可以直接清空缓存")
72 changes: 64 additions & 8 deletions czsc/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ class Signal:
score: int = 0

# k1, k2, k3 是信号名称
k1: str = "任意"
k2: str = "任意"
k3: str = "任意"
k1: str = "任意" # k1 一般是指明信号计算的K线周期,如 60分钟,日线,周线等
k2: str = "任意" # k2 一般是记录信号计算的参数
k3: str = "任意" # k3 用于区分信号,必须具有唯一性,推荐使用信号分类和开发日期进行标记

# v1, v2, v3 是信号取值
v1: str = "任意"
Expand Down Expand Up @@ -441,6 +441,18 @@ class Factor:
# signals_not 不能满足其中任一信号,允许为空
signals_not: List[Signal] = None

@property
def unique_signals(self) -> List[str]:
"""获取 Factor 的唯一信号列表"""
signals = []
signals.extend(self.signals_all)
if self.signals_any:
signals.extend(self.signals_any)
if self.signals_not:
signals.extend(self.signals_not)
signals = {x.signal if isinstance(x, Signal) else x for x in signals}
return list(signals)

def is_match(self, s: dict) -> bool:
"""判断 factor 是否满足"""
if self.signals_not:
Expand Down Expand Up @@ -484,8 +496,8 @@ def load(cls, raw: dict):
"""
fa = Factor(name=raw['name'],
signals_all=[Signal(x) for x in raw['signals_all']],
signals_any=[Signal(x) for x in raw['signals_any']] if raw['signals_any'] else None,
signals_not=[Signal(x) for x in raw['signals_not']] if raw['signals_not'] else None
signals_any=[Signal(x) for x in raw['signals_any']] if raw.get('signals_any') else None,
signals_not=[Signal(x) for x in raw['signals_not']] if raw.get('signals_not') else None
)
return fa

Expand All @@ -508,6 +520,23 @@ class Event:
# signals_not 不能满足其中任一信号,允许为空
signals_not: List[Signal] = None

@property
def unique_signals(self) -> List[str]:
"""获取 Event 的唯一信号列表"""
signals = []
if self.signals_all:
signals.extend(self.signals_all)
if self.signals_any:
signals.extend(self.signals_any)
if self.signals_not:
signals.extend(self.signals_not)

for factor in self.factors:
signals.extend(factor.unique_signals)

signals = {x.signal if isinstance(x, Signal) else x for x in signals}
return list(signals)

def is_match(self, s: dict):
"""判断 event 是否满足"""
# 首先判断 event 层面的信号是否得到满足
Expand Down Expand Up @@ -569,11 +598,14 @@ def load(cls, raw: dict):
'signals_not': []}
:return:
"""
assert raw['operate'] in Operate.__dict__["_value2member_map_"], f"operate {raw['operate']} not in Operate"
assert raw['factors'], "factors can not be empty"

e = Event(name=raw['name'], operate=Operate.__dict__["_value2member_map_"][raw['operate']],
factors=[Factor.load(x) for x in raw['factors']],
signals_all=[Signal(x) for x in raw['signals_all']] if raw['signals_all'] else None,
signals_any=[Signal(x) for x in raw['signals_any']] if raw['signals_any'] else None,
signals_not=[Signal(x) for x in raw['signals_not']] if raw['signals_not'] else None
signals_all=[Signal(x) for x in raw['signals_all']] if raw.get('signals_all') else None,
signals_any=[Signal(x) for x in raw['signals_any']] if raw.get('signals_any') else None,
signals_not=[Signal(x) for x in raw['signals_not']] if raw.get('signals_not') else None
)
return e

Expand Down Expand Up @@ -642,6 +674,14 @@ def __repr__(self):
return f"Position(name={self.name}, symbol={self.symbol}, opens={[x.name for x in self.opens]}, " \
f"timeout={self.timeout}, stop_loss={self.stop_loss}BP, T0={self.T0}, interval={self.interval}s)"

@property
def unique_signals(self) -> List[str]:
"""获取所有事件的唯一信号列表"""
signals = []
for e in self.events:
signals.extend(e.unique_signals)
return list(set(signals))

def dump(self, with_data=False):
"""将对象转换为 dict"""
raw = {
Expand All @@ -658,6 +698,22 @@ def dump(self, with_data=False):
raw.update({"pairs": self.pairs, "holds": self.holds})
return raw

@classmethod
def load(cls, raw: dict):
"""从 dict 中创建 Position
:param raw: 样例如下
:return:
"""
pos = Position(name=raw['name'], symbol=raw['symbol'],
opens=[Event.load(x) for x in raw['opens'] if raw.get('opens')],
exits=[Event.load(x) for x in raw['exits'] if raw.get('exits')],
interval=raw['interval'],
timeout=raw['timeout'],
stop_loss=raw['stop_loss'],
T0=raw['T0'])
return pos

@property
def pairs(self):
"""开平交易列表
Expand Down
15 changes: 10 additions & 5 deletions czsc/signals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
cxt_fx_power_V221107,
cxt_first_buy_V221126,
cxt_first_sell_V221126,
cxt_bi_break_V221126,
cxt_sub_b3_V221212,
cxt_zhong_shu_gong_zhen_V221221,
cxt_bi_end_V230222,
cxt_bi_end_V230224,
Expand All @@ -28,6 +26,7 @@
cxt_bi_end_V230312,
cxt_bi_end_V230320,
cxt_bi_end_V230322,
cxt_bi_end_V230324,
cxt_bi_base_V230228,
cxt_third_buy_V230228,
cxt_double_zs_V230311,
Expand All @@ -43,6 +42,7 @@
byi_symmetry_zs_V221107,
byi_bi_end_V230106,
byi_bi_end_V230107,
byi_second_bs_V230324,
)

from czsc.signals.coo import (
Expand Down Expand Up @@ -77,12 +77,14 @@
bar_vol_bs1_V230224,
bar_reversal_V230227,
bar_bpm_V230227,
bar_time_V230327,
bar_weekday_V230328,
bar_r_breaker_V230326,
)

from czsc.signals.jcc import (
jcc_san_xing_xian_V221023,
jcc_ten_mo_V221028,
jcc_bai_san_bin_V221030,
jcc_san_fa_V20221115,
jcc_san_fa_V20221118,
jcc_wu_yun_gai_ding_V221101,
Expand All @@ -95,7 +97,6 @@
jcc_zhuo_yao_dai_xian_v221113,
jcc_two_crow_V221108,
jcc_three_crow_V221108,
jcc_three_soldiers_V221030,
jcc_szx_V221111,
jcc_ta_xing_V221124,
jcc_san_szx_V221122,
Expand All @@ -121,6 +122,9 @@
tas_macd_first_bs_V221201,
tas_macd_first_bs_V221216,
tas_macd_second_bs_V221201,
tas_macd_bs1_V230313,
tas_macd_bs1_V230312,
tas_macd_base_V230320,

tas_ma_base_V221101,
tas_ma_base_V221203,
Expand All @@ -130,7 +134,8 @@

tas_boll_power_V221112,
tas_boll_bc_V221118,
tas_boll_vt_V230312,
tas_boll_vt_V230212,
tas_boll_cc_V230312,

tas_kdj_base_V221101,
tas_kdj_evc_V221201,
Expand Down
Loading

0 comments on commit 86c6370

Please sign in to comment.