提交 3b9affee 编写于 作者: Z zengbin93

0.3.3 优化中枢识别代码

上级 216e5246
......@@ -7,7 +7,7 @@ from .solid import SolidAnalyze
from .solid import is_in_tolerance, is_first_buy, is_first_sell, is_second_buy, \
is_second_sell, is_third_buy, is_third_sell, is_xd_buy, is_xd_sell
__version__ = "0.3.2"
__version__ = "0.3.3"
__author__ = "zengbin93"
__email__ = "zeng_bin8888@163.com"
......
......@@ -461,27 +461,31 @@ class KlineAnalyze(object):
zs_xd = []
for i in range(len(k_xd)):
if len(zs_xd) < 3:
if len(zs_xd) < 5:
zs_xd.append(k_xd[i])
continue
xd_p = k_xd[i]
zs_d = max([x['xd'] for x in zs_xd[:3] if x['fx_mark'] == 'd'])
zs_g = min([x['xd'] for x in zs_xd[:3] if x['fx_mark'] == 'g'])
zs_d = max([x['xd'] for x in zs_xd[1:5] if x['fx_mark'] == 'd'])
zs_g = min([x['xd'] for x in zs_xd[1:5] if x['fx_mark'] == 'g'])
if zs_g <= zs_d:
zs_xd.append(k_xd[i])
zs_xd.pop(0)
continue
if xd_p['fx_mark'] == "d" and xd_p['xd'] > zs_g:
# 线段在中枢上方结束,形成三买
k_zs.append({'zs': (zs_d, zs_g), "zs_xd": deepcopy(zs_xd)})
zs_xd = deepcopy(k_xd[i - 2:i + 1])
zs_xd = deepcopy(k_xd[i: i+1])
elif xd_p['fx_mark'] == "g" and xd_p['xd'] < zs_d:
# 线段在中枢下方结束,形成三卖
k_zs.append({'zs': (zs_d, zs_g), "zs_xd": deepcopy(zs_xd)})
zs_xd = deepcopy(k_xd[i - 2:i + 1])
zs_xd = deepcopy(k_xd[i: i+1])
else:
zs_xd.append(deepcopy(xd_p))
if len(zs_xd) >= 4:
zs_d = max([x['xd'] for x in zs_xd if x['fx_mark'] == 'd'])
zs_g = min([x['xd'] for x in zs_xd if x['fx_mark'] == 'g'])
if len(zs_xd) >= 5:
zs_d = max([x['xd'] for x in zs_xd[1:5] if x['fx_mark'] == 'd'])
zs_g = min([x['xd'] for x in zs_xd[1:5] if x['fx_mark'] == 'g'])
k_zs.append({'zs': (zs_d, zs_g), "zs_xd": deepcopy(zs_xd)})
return k_zs
......
......@@ -15,21 +15,21 @@ def test_bei_chi():
ka = KlineAnalyze(df)
# 线段背驰
zs1 = ['2018-07-26 15:00:00', '2018-10-19 15:00:00']
zs2 = ['2018-01-29 15:00:00', '2018-07-06 15:00:00']
assert is_bei_chi(ka, zs1, zs2, direction='down', mode='xd', adjust=0.9)
zs1 = {"start_dt": '2018-07-26 15:00:00', "end_dt": '2018-10-19 15:00:00', "direction": "down"}
zs2 = {"start_dt": '2018-01-29 15:00:00', "end_dt": '2018-07-06 15:00:00', "direction": "down"}
assert is_bei_chi(ka, zs1, zs2, mode='xd', adjust=0.9)
zs1 = ['2013-12-10 15:00:00', '2014-01-20 15:00:00']
zs2 = ['2013-09-12 15:00:00', '2013-11-14 15:00:00']
assert not is_bei_chi(ka, zs1, zs2, direction='down', mode='xd', adjust=0.9)
zs1 = {"start_dt": '2013-12-10 15:00:00', "end_dt": '2014-01-20 15:00:00', "direction": "down"}
zs2 = {"start_dt": '2013-09-12 15:00:00', "end_dt": '2013-11-14 15:00:00', "direction": "down"}
assert not is_bei_chi(ka, zs1, zs2, mode='xd', adjust=0.9)
# 笔背驰
zs1 = ['2019-05-17 15:00:00', '2019-06-10 15:00:00']
zs2 = ['2019-04-08 15:00:00', '2019-05-10 15:00:00']
zs1 = {"start_dt": '2019-05-17 15:00:00', "end_dt": '2019-06-10 15:00:00'}
zs2 = {"start_dt": '2019-04-08 15:00:00', "end_dt": '2019-05-10 15:00:00'}
assert is_bei_chi(ka, zs1, zs2, mode='bi', adjust=0.9)
zs1 = ['2018-09-28 15:00:00', '2018-10-19 15:00:00']
zs2 = ['2018-08-28 15:00:00', '2018-09-12 15:00:00']
zs1 = {"start_dt": '2018-09-28 15:00:00', "end_dt": '2018-10-19 15:00:00'}
zs2 = {"start_dt": '2018-08-28 15:00:00', "end_dt": '2018-09-12 15:00:00'}
assert not is_bei_chi(ka, zs1, zs2, mode='bi', adjust=0.9)
......@@ -44,5 +44,6 @@ def test_kline_analyze():
# 测试背驰识别
assert not ka.bi_bei_chi()
assert not ka.xd_bei_chi()
print(ka.zs[-2])
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册