Skip to content

Commit

Permalink
0.8.29 fix bug (waditu#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Jul 27, 2022
1 parent 3cee4c5 commit d256dc8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
16 changes: 13 additions & 3 deletions czsc/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def check_fxs(bars: List[NewBar]) -> List[FX]:
# 临时处理方案,强制要求fxs序列顶底交替
if len(fxs) >= 2 and fx.mark == fxs[-1].mark:
fxs.pop()
if envs.get_verbose():
print("\n\n", "check_fxs: 输入数据错误", "=" * 100)
for bar in bars:
print(bar, "\n")
fxs.append(fx)
return fxs

Expand Down Expand Up @@ -292,10 +296,16 @@ def update(self, bar: RawBar):
self.bars_raw.append(bar)
last_bars = [bar]
else:
# 当前 bar 是上一根 bar 的时间延伸
self.bars_raw[-1] = bar
last_bars = self.bars_ubi[-1].elements
last_bars[-1] = bar
self.bars_ubi.pop(-1)
if len(self.bars_ubi) >= 3:
edt = self.bars_ubi[1].dt
self.bars_ubi = [x for x in self.bars_ubi if x.dt <= edt]
last_bars = [x for x in self.bars_raw[-50:] if x.dt > edt]
else:
last_bars = self.bars_ubi[-1].elements
last_bars[-1] = bar
self.bars_ubi.pop(-1)

# 去除包含关系
bars_ubi = self.bars_ubi
Expand Down
42 changes: 22 additions & 20 deletions examples/gm_check_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,32 @@
create_dt: 2021/11/17 22:26
describe: 使用掘金数据验证买卖点
"""
# from czsc.gm_utils import trader_tactic_snapshot
# from czsc.strategies import trader_strategy_a as strategy
#
# if __name__ == '__main__':
# _symbol = "SZSE.300669"
# ct = trader_tactic_snapshot(_symbol, end_dt="2022-03-18 13:15", strategy=strategy)

import numpy as np
from czsc.gm_utils import trader_tactic_snapshot
from czsc.strategies import trader_strategy_a as strategy
from czsc.signals.utils import check_cross_info
try:
import talib as ta
except:
from czsc.utils import ta


if __name__ == '__main__':
_symbol = "SHSE.000001"
ct = trader_tactic_snapshot(_symbol, end_dt="2022-07-03 15:15", strategy=strategy)
close = np.array([x.close for x in ct.kas['60分钟'].bars_raw])
fast = ta.SMA(close, timeperiod=5)
slow = ta.SMA(close, timeperiod=13)
cross = check_cross_info(fast.round(2), slow.round(2))
# _symbol = "SZSE.300669"
# ct = trader_tactic_snapshot(_symbol, end_dt="2022-03-18 13:15", strategy=strategy)
_symbol = "SHSE.000016"
ct = trader_tactic_snapshot(_symbol, end_dt="2022-07-27 13:15", strategy=strategy)

# import numpy as np
# from czsc.gm_utils import trader_tactic_snapshot
# from czsc.strategies import trader_strategy_a as strategy
# from czsc.signals.utils import check_cross_info
# try:
# import talib as ta
# except:
# from czsc.utils import ta
#
#
# if __name__ == '__main__':
# _symbol = "SHSE.000001"
# ct = trader_tactic_snapshot(_symbol, end_dt="2022-07-03 15:15", strategy=strategy)
# close = np.array([x.close for x in ct.kas['60分钟'].bars_raw])
# fast = ta.SMA(close, timeperiod=5)
# slow = ta.SMA(close, timeperiod=13)
# cross = check_cross_info(fast.round(2), slow.round(2))



2 changes: 1 addition & 1 deletion examples/ts_fast_backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from czsc.strategies import trader_example1 as strategy
# from examples import tactics

os.environ['czsc_verbose'] = "1" # 是否输出详细执行信息,0 不输出,1 输出
os.environ['czsc_verbose'] = "0" # 是否输出详细执行信息,包括一些用于debug的信息,0 不输出,1 输出
os.environ['czsc_min_bi_len'] = "6" # 通过环境变量设定最小笔长度,6 对应新笔定义,7 对应老笔定义

pd.set_option('mode.chained_assignment', None)
Expand Down

0 comments on commit d256dc8

Please sign in to comment.