Skip to content

Commit

Permalink
add research model
Browse files Browse the repository at this point in the history
  • Loading branch information
somewheve committed Mar 5, 2021
1 parent 20420d8 commit ab6e71e
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
6 changes: 4 additions & 2 deletions ctpbee/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def running_timer(common_signal):
self.trader = Trader(self.app_signal, self)
self.market = Market(self.app_signal)
print(">>>> 回测接口载入成功")
self._start_looper()
return self._start_looper()
else:
raise ValueError("错误的参数, 仅仅支持")

Expand Down Expand Up @@ -384,9 +384,11 @@ def _start_looper(self):
except StopIteration:
self.logger.info("回测结束,正在生成结果")
break
except ValueError:
except ValueError:
raise ValueError("数据存在问题, 请检查")

return self.trader

def remove_extension(self, extension_name: Text) -> None:
"""
移除插件(策略)
Expand Down
1 change: 1 addition & 0 deletions ctpbee/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Exchange(Enum):
OKEX = "OKEX"
HUOBI = "HUOBI"
BITFINEX = "BITFINEX"
NONE = "none"


TODAY_EXCHANGE = [Exchange.INE, Exchange.SHFE]
Expand Down
4 changes: 2 additions & 2 deletions ctpbee/interface/ctp/md_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def onRtnDepthMarketData(self, data: dict):
symbol = data["InstrumentID"]
exchange = symbol_exchange_map.get(symbol, "")
if not exchange:
return
exchange = Exchange.NONE

timestamp = f"{data['ActionDay']} {data['UpdateTime']}.{int(data['UpdateMillisec'] / 100)}"
try:
Expand All @@ -102,7 +102,7 @@ def onRtnDepthMarketData(self, data: dict):
symbol=symbol,
exchange=exchange,
datetime=datetimed,
name=symbol_name_map[symbol],
name=symbol_name_map.get(symbol, "None"),
volume=data["Volume"],
last_price=data["LastPrice"],
limit_up=data["UpperLimitPrice"],
Expand Down
10 changes: 10 additions & 0 deletions ctpbee/research/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
This module provide some useful tool to help you parse your strategy and market ticks.
I hope it will help you develop strategy easier.
match.py: contain a trade record match algorithm.
lines: contain a tool to help you point the value in the tick lines.
"""
from ctpbee.research.lines import Aux, plot_multi
46 changes: 46 additions & 0 deletions ctpbee/indicator/cator.py → ctpbee/research/lines.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import numpy as np
import matplotlib.pyplot as plt
from typing import List

# import matplotlib.text.Text
from matplotlib.font_manager import FontProperties


def plot_multi(data, cols=None, spacing=.1, **kwargs):
""" 帮助快速绘画出多个图
从网上找的 QAQ 好用
Expand Down Expand Up @@ -35,3 +43,41 @@ def plot_multi(data, cols=None, spacing=.1, **kwargs):

ax.legend(lines, labels, loc=0)
return ax


def Aux(yy: List, xx: List, ovx: dict):
"""
yx: 纵坐标数据
ax: 横坐标数据
ovx: {
"buy": [横坐标下标]
"sell": [横坐标下标]
}
"""
fig, ax = plt.subplots()

line, = ax.plot(xx, yy, lw=2)
for index in ovx["buy"]:
ax.annotate('↑', xy=(xx[index], yy[index]),
fontproperties=FontProperties(size=20),
color="red",
annotation_clip=True,
)
for index in ovx["sell"]:
ax.annotate('↓', xy=(xx[index], yy[index]),
fontproperties=FontProperties(size=20),
# arrowprops=dict(facecolor='green', shrink=0.05),
color="green",
annotation_clip=True,
)
# ax.set_ylim(-2, 2)
return plt


if __name__ == '__main__':
t = np.arange(0.0, 5.0, 0.01)
s = np.cos(5 * np.pi * t)
o = Aux(s, t, {"buy": [11, 100], "sell": [200]})
o.show()
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
long_description = ""

pkgs = ['ctpbee', 'ctpbee.context', 'ctpbee.exceptions', 'ctpbee.data_handle', 'ctpbee.interface',
'ctpbee.interface.ctp', "ctpbee.interface.looper", 'ctpbee.jsond', "ctpbee.looper", "ctpbee.indicator"]
'ctpbee.interface.ctp', "ctpbee.interface.looper", 'ctpbee.jsond', "ctpbee.looper",
"ctpbee.indicator", "ctpbee.research"]

setup(
name='ctpbee',
Expand Down

0 comments on commit ab6e71e

Please sign in to comment.