test_solid.py 992 字节
Newer Older
Z
zengbin93 已提交
1 2
# coding: utf-8
import sys
Z
zengbin93 已提交
3
import warnings
Z
zengbin93 已提交
4
from cobra.data.kline import get_klines
Z
zengbin93 已提交
5 6
sys.path.insert(0, '.')
sys.path.insert(0, '..')
7 8
import czsc
from czsc.solid import SolidAnalyze, is_in_tolerance
Z
zengbin93 已提交
9
warnings.warn(f"czsc version is {czsc.__version__}")
Z
zengbin93 已提交
10 11


Z
zengbin93 已提交
12 13 14 15 16 17 18
def test_in_tolerance():
    assert not is_in_tolerance(10, 10.31, tolerance=0.03)
    assert not is_in_tolerance(10, 9.61, tolerance=0.03)
    assert not is_in_tolerance(10, 9, tolerance=0.03)
    assert is_in_tolerance(10, 10.3, tolerance=0.03)
    assert is_in_tolerance(10, 10.15, tolerance=0.03)
    assert is_in_tolerance(10, 9.8, tolerance=0.03)
Z
zengbin93 已提交
19 20


Z
zengbin93 已提交
21 22 23
def test_solid_analyze():
    ts_code = "000001.SH"
    klines = get_klines(ts_code, end_date='2020-04-03 14:00:00', asset='I', freqs='1min,5min,30min,D')
Z
zengbin93 已提交
24 25
    sa = SolidAnalyze(klines)

Z
zengbin93 已提交
26 27 28 29
    for name in sa.bs_func.keys():
        for freq in ['1分钟', '5分钟', '30分钟']:
            detail = sa.check_bs(freq, name, pf=False, tolerance=0.03)
            print(detail, "\n\n")
Z
zengbin93 已提交
30 31 32