提交 d789098e 编写于 作者: Z zengbin93

0.5.1 优化初始化

上级 f0b85abf
......@@ -142,10 +142,6 @@ class KlineAnalyze:
self.name = name
self.verbose = verbose
self.min_bi_k = min_bi_k
self.symbol = None
self.latest_price = None
self.start_dt = None
self.end_dt = None
self.kline_raw = [] # 原始K线序列
self.kline_new = [] # 去除包含关系的K线序列
......@@ -170,6 +166,12 @@ class KlineAnalyze:
self.kline_raw = [{k: v for k, v in zip(columns, row)} for row in kline.values]
else:
self.kline_raw = kline
self.symbol = self.kline_raw[0]['symbol']
self.start_dt = self.kline_raw[0]['dt']
self.end_dt = self.kline_raw[-1]['dt']
self.latest_price = self.kline_raw[-1]['close']
self._update_kline_new()
self._update_fx_list()
self._update_bi_list()
......@@ -185,8 +187,7 @@ class KlineAnalyze:
'close': 3210.1,
'high': 3373.53,
'low': 3209.76,
'vol': 486366915.0,
'is_end': True}
'vol': 486366915.0}
无包含关系K线对象样例:
{'symbol': '000001.SH',
......@@ -195,9 +196,7 @@ class KlineAnalyze:
'close': 3210.1,
'high': 3373.53,
'low': 3209.76,
'vol': 486366915.0,
'is_end': True,
'direction': 'down'}
'vol': 486366915.0}
"""
if len(self.kline_new) < 4:
for x in self.kline_raw[:4]:
......@@ -501,10 +500,7 @@ class KlineAnalyze:
print(f"输入K线处于未完成状态,更新:replace {self.kline_raw[-1]} with {k}")
self.kline_raw[-1] = k
self.symbol = k['symbol']
self.end_dt = k['dt']
self.latest_price = k['close']
self.start_dt = self.kline_raw[0]['dt']
self._update_kline_new()
self._update_fx_list()
......
......@@ -2,25 +2,47 @@
import sys
import warnings
from cobra.data.kline import get_kline
sys.path.insert(0, '.')
sys.path.insert(0, '..')
import os
import pandas as pd
import czsc
from czsc.analyze import KlineAnalyze
warnings.warn(f"czsc version is {czsc.__version__}")
kline = get_kline(ts_code="000001.SH", end_dt="2020-07-16 15:00:00", freq='D', asset='I')
cur_path = os.path.split(os.path.realpath(__file__))[0]
file_kline = os.path.join(cur_path, "data/000001.SH_D.csv")
kline = pd.read_csv(file_kline, encoding="utf-8")
kline.loc[:, "dt"] = pd.to_datetime(kline.dt)
kline.loc[:, "is_end"] = True
# ka = KlineAnalyze(kline, name="日线")
# print(ka)
def test_kline_analyze():
ka = KlineAnalyze(kline, name="日线")
# 测试绘图
file_img = "kline.png"
ka.to_image(file_img, max_k_count=5000)
assert os.path.exists(file_img)
os.remove(file_img)
file_html = "kline.html"
ka.to_html(file_html)
assert os.path.exists(file_html)
os.remove(file_html)
# 测试分型识别结果
assert ka.fx_list[-1]['fx_mark'] == 'g' and ka.fx_list[-1]['fx'] == 3456.97
assert ka.fx_list[-5]['fx_mark'] == 'g' and ka.fx_list[-5]['fx'] == 2983.44
# 测试笔识别结果
assert ka.bi_list[-1]['fx_mark'] == 'g' and ka.bi_list[-1]['bi'] == 3456.97
assert ka.bi_list[-4]['fx_mark'] == 'd' and ka.bi_list[-4]['bi'] == 2646.8
# 测试线段识别结果
assert ka.xd_list[-2]['fx_mark'] == 'g' and ka.xd_list[-2]['xd'] == 3288.45
assert ka.xd_list[-3]['fx_mark'] == 'd' and ka.xd_list[-3]['xd'] == 2440.91
# 测试增量更新
ka_raw_len = len(ka.kline_raw)
for x in [2890, 2910, 2783, 3120]:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册