Skip to content

Commit

Permalink
0.7.7 first commit(waditu#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Sep 23, 2021
1 parent 21c68c8 commit 8e408a9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
4 changes: 2 additions & 2 deletions czsc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from .utils.ta import SMA, EMA, MACD, KDJ
from .data.jq import JqCzscTrader

__version__ = "0.7.6"
__version__ = "0.7.7"
__author__ = "zengbin93"
__email__ = "[email protected]"
__date__ = "20210902"
__date__ = "20210923"

print(f"欢迎使用CZSC!当前版本标识为 {__version__}@{__date__}")

20 changes: 18 additions & 2 deletions czsc/data/ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
email: [email protected]
create_dt: 2021/6/25 18:52
"""

import os
import pandas as pd
import tushare as ts
from datetime import datetime, timedelta
from typing import List
from ..analyze import CzscTrader, RawBar, KlineGenerator
from ..signals import get_default_signals
from ..enum import Freq
from ..utils.cache import home_path


# 数据频度 :支持分钟(min)/日(D)/周(W)/月(M)K线,其中1min表示1分钟(类推1/5/15/30/60分钟)。
Expand All @@ -20,13 +21,28 @@
Freq.F60: "60min", Freq.D: 'D', Freq.W: "W", Freq.M: "M"}
freq_cn_map = {"1分钟": Freq.F1, "5分钟": Freq.F5, "15分钟": Freq.F15, "30分钟": Freq.F30,
"60分钟": Freq.F60, "日线": Freq.D}

exchanges = {
"SSE": "上交所",
"SZSE": "深交所",
"CFFEX": "中金所",
"SHFE": "上期所",
"CZCE": "郑商所",
"DCE": "大商所",
"INE": "能源",
"IB": "银行间",
"XHKG": "港交所"
}

dt_fmt = "%Y-%m-%d %H:%M:%S"
date_fmt = "%Y%m%d"

pro = ts.pro_api()

def get_trade_cal():
file_cal = os.path.join(home_path, "trade_cal.csv")
for k, v in exchanges.items():
df = pro.trade_cal(exchange=k, start_date='19700101', end_date='20211231')


def format_kline(kline: pd.DataFrame, freq: Freq) -> List[RawBar]:
"""Tushare K线数据转换
Expand Down
14 changes: 8 additions & 6 deletions czsc/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class RawBar:
high: [float, int]
low: [float, int]
vol: [float, int]
amount: [float, int] = None


@dataclass
Expand All @@ -39,7 +40,8 @@ class NewBar:
high: [float, int]
low: [float, int]
vol: [float, int]
elements: List[RawBar] # 存入具有包含关系的原始K线
amount: [float, int] = None
elements: List = None # 存入具有包含关系的原始K线


@dataclass
Expand All @@ -50,8 +52,8 @@ class FX:
high: [float, int]
low: [float, int]
fx: [float, int]
power: str
elements: List[NewBar]
power: str = None
elements: List = None


@dataclass
Expand All @@ -71,16 +73,16 @@ class BI:
symbol: str
fx_a: FX = None # 笔开始的分型
fx_b: FX = None # 笔结束的分型
fxs: List[FX] = None # 笔内部的分型列表
fxs: List = None # 笔内部的分型列表
direction: Direction = None
high: float = None
low: float = None
power: float = None
bars: List[NewBar] = None
bars: List = None
rsq: float = None
change: float = None
length: float = None
fake_bis: List[FakeBI] = None
fake_bis: List = None

def __post_init__(self):
self.sdt = self.fx_a.dt
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
version=czsc.__version__,
author=czsc.__author__,
author_email=czsc.__email__,
keywords=["缠论", "技术分析", "A股", "期货", "缠中说禅", "单因子分析"],
keywords=["缠论", "技术分析", "A股", "期货", "缠中说禅"],
description="缠中说禅技术分析工具",
long_description="缠中说禅技术分析工具,源自 http://blog.sina.com.cn/chzhshch",
license="MIT",
license="Apache Software License",

url="https://github.com/zengbin93/czsc",
packages=find_packages(exclude=['test', 'images', 'docs', 'examples']),
include_package_data=True,
install_requires=["pandas", "pyecharts", "tushare", "requests", "seaborn"],

package_data={'': ['data/*.csv']},
classifiers=[
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
]
)
4 changes: 2 additions & 2 deletions test/test_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ def test_czsc_trader():
]),
]
ct = CzscTrader(op_freq=Freq.F5, kg=kg, get_signals=get_default_signals, events=events)
assert len(ct.s) == 214
assert len(ct.s) == 215
for row in bars[-10000:]:
op = ct.check_operate(row)
print(" : op : ", op)
print(" : cache : ", dict(ct.cache), "\n")
assert len(ct.s) == 214
assert len(ct.s) == 215


def test_get_signals():
Expand Down

0 comments on commit 8e408a9

Please sign in to comment.