完善帮助信息

This commit is contained in:
fasiondog 2017-09-26 07:07:56 +08:00
parent fbb0e9176b
commit c1e7a30e03
8 changed files with 302 additions and 195 deletions

View File

@ -1,13 +1,64 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120100220, Added by fasiondog
# history:
# 1. 20100220, Added by fasiondog
#===============================================================================
from .drawplot import (create_figure,
ax_set_locator_formatter,
adjust_axes_show,
ax_draw_macd,
ax_draw_macd2,
kplot,
mkplot,
iplot,
ibar,
sgplot,
cnplot,
sysplot)
#from interactive import *
from . import volume as vl
from . import elder as el
from . import kaufman as kf
__all__ = [
'vl', 'el', 'kf',
'create_figure',
'ax_set_locator_formatter',
'adjust_axes_show',
'ax_draw_macd',
'ax_draw_macd2',
'kplot',
'mkplot',
'iplot',
'ibar',
'sgplot',
'cnplot',
'sysplot'
]

View File

@ -1,10 +1,32 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120170704, Added by fasiondog
# History:
# 1. 20170704, Added by fasiondog
#===============================================================================
from hikyuu.trade_manage import OrderBrokerBase

View File

@ -1,10 +1,32 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120170704, Added by fasiondog
# History
# 1. 20170704, Added by fasiondog
#===============================================================================
import smtplib

View File

@ -82,13 +82,8 @@ def create_four_axes_figure(figsize=(10,8)):
return ax1,ax2,ax3,ax4
def create_figure(n = 1, figsize = (10,8)):
"""生成含有指定坐标轴数量的窗口最大只支持4个坐标轴。是对下面4个函数的简单包装
- create_one_axes_figure
- create_two_axes_figure
- create_three_axes_figure
- create_four_axes_figure
def create_figure(n=1, figsize=(10,8)):
"""生成含有指定坐标轴数量的窗口最大只支持4个坐标轴。
:param int n:
:param figsize: (, )
@ -258,9 +253,10 @@ def get_draw_title(kdata):
def adjust_axes_show(axeslist):
"""
axeslist (ax1,ax2,ax3)
"""用于调整上下紧密相连的坐标轴显示时,其上一坐标轴最小值刻度和下一坐标轴最大值刻度
:param axeslist: (ax1,ax2,...)
"""
for ax in axeslist[:-1]:
for label in ax.get_xticklabels():
@ -269,106 +265,6 @@ def adjust_axes_show(axeslist):
ylabels[0].set_visible(False)
def ax_draw_signal(axes, kdata, dates, direct="BUY", style = 1):
"""
"""
refdates = kdata.getDatetimeList()
date_index = dict([(d,i) for i,d in enumerate(refdates)])
ylim = axes.get_ylim()
height = ylim[1]-ylim[0]
if style == 1:
arrow = dict(arrowstyle="->")
else:
if direct == "BUY":
arrow = dict(facecolor='red', frac=0.5)
else:
arrow = dict(facecolor='blue', frac=0.5)
for d in dates:
if d not in date_index:
continue
pos = date_index[d]
krecord = kdata[pos]
if direct == "BUY":
axes.annotate('B',
(pos, krecord.lowPrice - height*0.01),
(pos, krecord.lowPrice - height*0.1),
arrowprops = arrow,
horizontalalignment = 'center',
verticalalignment = 'bottom',
color='red')
else:
axes.annotate('S',
(pos, krecord.highPrice + height*0.01),
(pos, krecord.highPrice + height*0.1),
arrowprops = arrow,
horizontalalignment = 'center',
verticalalignment = 'top',
color='blue')
#axes.plot([pos],[krecord.closePrice],'rh')
def ax_draw_sys_signal(axes, kdata, sys, style = 2):
"""
"""
refdates = kdata.getDatetimeList()
date_index = dict([(d, i) for i,d in enumerate(refdates)])
ylim = axes.get_ylim()
height = ylim[1]-ylim[0]
if style == 1:
arrow_buy = dict(arrowstyle="->")
arrow_sell = arrow_buy
else:
arrow_buy = dict(facecolor='red', frac=0.5)
arrow_sell = dict(facecolor='blue', frac=0.5)
buy_request = sys.getBuyTradeRequest()
sell_request = sys.getSellTradeRequest()
text_request = ''
if buy_request.valid:
text_request = u' %.2f' % (buy_request.stoploss)
color = 'r'
if sell_request.valid:
text_request = u' : %s' % (getSystemPartName(sell_request.part))
color = 'b'
if buy_request.valid or sell_request.valid:
axes.text(0.99,0.03, text_request, horizontalalignment='right',
verticalalignment='bottom',
transform=axes.transAxes, color=color)
dates = sys.getTradeRecordList()
for d in dates:
if not date_index.has_key(d.datetime):
continue
pos = date_index[d.datetime]
krecord = kdata[pos]
if d.business == BUSINESS.BUY:
axes.annotate('SG',
(pos, krecord.lowPrice - height*0.01),
(pos, krecord.lowPrice - height*0.1),
arrowprops = arrow_buy,
horizontalalignment = 'center',
verticalalignment = 'bottom',
color='red')
elif d.business == BUSINESS.SELL:
text = getSystemPartName(d.part)
axes.annotate(text,
(pos, krecord.highPrice + height*0.01),
(pos, krecord.highPrice + height*0.1),
arrowprops = arrow_sell,
horizontalalignment = 'center',
verticalalignment = 'top',
color='blue')
else:
None
#axes.plot([pos],[krecord.closePrice],'rh')
def kplot(kdata, new=True, axes=None,
colorup='r', colordown='g', width=0.6, alpha=1.0):
"""绘制K线图
@ -386,7 +282,7 @@ def kplot(kdata, new=True, axes=None,
return
if not axes:
axes = create_one_axes_figure() if new else gca()
axes = create_figure() if new else gca()
OFFSET = width/2.0
rfcolor = matplotlib.rcParams['axes.facecolor']
@ -445,7 +341,7 @@ def mkplot(kdata, new=True, axes=None, colorup='r', colordown='g', ticksize=3):
return
if not axes:
axes = create_one_axes_figure() if new else gca()
axes = create_figure() if new else gca()
for t in range(len(kdata)):
record = kdata[t]
@ -503,7 +399,7 @@ def iplot(indicator, new=True, axes=None,
return
if not axes:
axes = create_one_axes_figure() if new else gca()
axes = create_figure() if new else gca()
if not label:
label = "%s %.2f" % (indicator.long_name, indicator[-1])
@ -558,7 +454,7 @@ def ibar(indicator, new=True, axes=None,
return
if not axes:
axes = create_one_axes_figure() if new else gca()
axes = create_figure() if new else gca()
if not label:
label = "%s %.2f" % (indicator.long_name, indicator[-1])
@ -594,12 +490,12 @@ def ibar(indicator, new=True, axes=None,
def ax_draw_macd(axes, kdata, n1=12, n2=26, n3=9):
"""绘制MACD
axes
kdataKData
n1: MACD参数1MACD
n2: MACD参数2MACD
n3: MACD参数3MACD
:param axes:
:param KData kdata: KData
:param int n1: MACD 1
:param int n2: MACD 2
:param int n3: MACD 3
"""
macd = MACD(CLOSE(kdata), n1, n2, n3)
bmacd, fmacd, smacd = macd.getResult(0), macd.getResult(1), macd.getResult(2)
@ -626,17 +522,17 @@ def ax_draw_macd(axes, kdata, n1=12, n2=26, n3=9):
def ax_draw_macd2(axes, ref, kdata, n1=12, n2=26, n3=9):
"""
MACDBAR值变化与参考序列ref变化不一致时
"""绘制MACD。
BAR值变化与参考序列ref变化不一致时
BAR和参考序列ref同时上涨
BAR和参考序列ref同时下跌绿
:
axes
ref: EMA
kdataKData
n1: MACD参数1MACD
n2: MACD参数2MACD
n3: MACD参数3MACD
:param axes:
:param ref: EMA
:param KData kdata: KData
:param int n1: MACD 1
:param int n2: MACD 2
:param int n3: MACD 3
"""
macd = MACD(CLOSE(kdata), n1, n2, n3)
bmacd, fmacd, smacd = macd.getResult(0), macd.getResult(1), macd.getResult(2)
@ -673,17 +569,16 @@ def ax_draw_macd2(axes, ref, kdata, n1=12, n2=26, n3=9):
label.set_visible(False)
def sgplot(sg, new = True, axes = None, style = 1, kdata = None):
def sgplot(sg, new=True, axes=None, style=1, kdata=None):
"""绘制买入/卖出信号
:param SignalBase sg:
:param new: axes的情况下生效True时
:param axes:
:param new: axes的情况下生效True时
:param axes:
:param style: 1 | 2
:param KData kdata: KData
None
使
None
使
"""
if kdata is None:
kdata = sg.getTO()
@ -695,7 +590,7 @@ def sgplot(sg, new = True, axes = None, style = 1, kdata = None):
if axes is None:
if new:
axes = create_one_axes_figure()
axes = create_figure()
kplot(kdata, axes=axes)
else:
axes = gca()
@ -739,14 +634,14 @@ def sgplot(sg, new = True, axes = None, style = 1, kdata = None):
color='blue')
def cnplot(cn, kdata = None, axes = None, new = True):
"""
cn
kdataKDataNone使
axes
new axes的情况下生效True时
def cnplot(cn, new=True, axes=None, kdata=None):
"""绘制系统有效条件
:param ConditionBase cn:
:param new: axes的情况下生效True时
:param axes:
:param KData kdata: KDataNone
使
"""
if kdata is None:
kdata = cn.getTO()
@ -758,7 +653,7 @@ def cnplot(cn, kdata = None, axes = None, new = True):
if axes is None:
if new:
axes = create_one_axes_figure()
axes = create_figure()
kplot(kdata, axes=axes)
else:
axes = gca()
@ -770,14 +665,14 @@ def cnplot(cn, kdata = None, axes = None, new = True):
axes.fill_between(x, y1, y2, where=y2 < y1, facecolor='red', alpha=0.6)
def sysplot(sys, style = 1, axes = None, new = True):
"""
/
sys
style: 1 | 2
axes
new axes的情况下生效True时
def sysplot(sys, new=True, axes=None, style=1):
"""绘制系统实际买入/卖出信号
:param SystemBase sys:
:param new: axes的情况下生效True时
:param axes:
:param style: 1 | 2
"""
kdata = sys.getTO()
@ -786,7 +681,7 @@ def sysplot(sys, style = 1, axes = None, new = True):
if axes is None:
if new:
axes = create_one_axes_figure()
axes = create_figure()
kplot(kdata, axes=axes)
else:
axes = gca()

View File

@ -1,10 +1,32 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120100224, Added by fasiondog
# History:
# 1. 20100224, Added by fasiondog
#===============================================================================
"""
@ -59,6 +81,7 @@ def _draw_ema_pipe(axes, kdata, ema, n=22, w=0.10):
axes.fill_between(range(emas_len),fy1,fy2,alpha=0.2, color='y' )
def draw(stock, query=QueryByIndex(-130), ma_n=22, ma_w='auto', vigor_n=13):
"""绘制亚历山大.艾尔德交易系统图形"""
kdata = stock.getKData(query)
close = CLOSE(kdata)
ema = EMA(close, ma_n)

View File

@ -1,12 +1,39 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120120926, Added by fasiondog
# History:
# 1. 20120926, Added by fasiondog
#===============================================================================
import urllib
import sys
import os
import configparser
from hikyuu import *
from hikyuu.indicator import *
from hikyuu.trade_manage import *
@ -20,28 +47,28 @@ from hikyuu.trade_sys.stoploss import *
from hikyuu.trade_sys.profitgoal import *
from hikyuu.trade_sys.slippage import *
from .drawplot import *
from hikyuu.interactive import *
#import time
#==============================================================================
# 引入扯线木偶
#==============================================================================
#Puppet是一套以同花顺交易客户端为核心的完整的闭环实盘交易系统框架。
#来自:"睿瞳深邃(https://github.com/Raytone-D" 感谢睿瞳深邃的大度共享 :-)
#可以用tm.regBroker(crtRB(Puppet())) 的方式注册进tm实例实现实盘下单
if sys.platform == 'win32':
from .puppet import *
from . import volume as vl
from . import elder as el
from . import kaufman as kf
from .broker import *
from .broker_mail import *
import urllib
import sys
import os
import configparser
#==============================================================================
#
# 读取配置信息,并初始化
#
#==============================================================================
data_config_file = os.path.expanduser('~') + "/.hikyuu/data_dir.ini"
data_config = configparser.ConfigParser()
data_config.read(data_config_file)
@ -59,6 +86,13 @@ sm = StockManager.instance()
#endtime = time.time()
#print "%.2fs" % (endtime-starttime)
#==============================================================================
#
# 引入blocka、blocksh、blocksz、blockg全局变量便于交互式环境下使用
#
#==============================================================================
blocka = Block("A", "ALL")
for s in sm:
if s.type in (constant.STOCKTYPE_A, constant.STOCKTYPE_GEM):
@ -77,7 +111,14 @@ for s in blocka:
blockg = Block("G", "GEM")
for s in sm:
if s.type == constant.STOCKTYPE_GEM:
blockg.add(s)
blockg.add(s)
#==============================================================================
#
# 为 KData、Indicator 等添加 plot 方法
#
#==============================================================================
KData.plot = kplot
KData.kplot = kplot
@ -91,8 +132,13 @@ ConditionBase.plot = cnplot
System.plot = sysplot
#================================================================
#更新实时数据
#==============================================================================
#
# 增加临时的实时数据更新函数 realtimeUpdate
#
#==============================================================================
def UpdateOneRealtimeRecord_from_sina(tmpstr):
try:
if len(tmpstr) > 3 and tmpstr[:3] == 'var':

View File

@ -1,10 +1,32 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120100224, Added by fasiondog
# History:
# 1. 20100224, Added by fasiondog
#===============================================================================
"""
@ -16,20 +38,19 @@ from hikyuu import Query, StockManager
from hikyuu.indicator import *
from hikyuu.trade_sys.signal import SG_Single, SG_Cross, SG_Flex
from hikyuu.trade_manage import BUSINESS
from .drawplot import (create_two_axes_figure, ax_set_locator_formatter,
from .drawplot import (create_figure, ax_set_locator_formatter,
create_three_axes_figure, adjust_axes_show,
ax_draw_signal, ax_draw_sys_signal, ax_draw_macd)
ax_draw_macd)
def draw(stock, query = Query(-130),
n = 10, filter_n = 20, filter_p = 0.1,
sg_type = "CROSS",
show_high_low = False,
arrow_style = 1):
"""
"""
"""绘制佩里.J.考夫曼Perry J.Kaufman 自适应移动平均系统(AMA)"""
kdata = stock.getKData(query)
ax1, ax2 = create_two_axes_figure()
ax1, ax2 = create_figure(2)
kdata.plot(axes = ax1)
cama = AMA(CLOSE(kdata), n = n )
@ -87,6 +108,7 @@ def draw2(block, query = Query(-130),
sg_type = 'CROSS',
show_high_low = True,
arrow_style = 1):
"""绘制佩里.J.考夫曼Perry J.Kaufman 自适应移动平均系统(AMA)"""
sm = StockManager.instance()
if block.name == 'SZ':
kdata = sm['sz000001'].getKData(query)

View File

@ -1,10 +1,32 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#===============================================================================
# 作者fasiondog
# 历史120100227, Added by fasiondog
# History:
# 1. 20100227, Added by fasiondog
#===============================================================================
"""
@ -14,12 +36,15 @@ from hikyuu import Query
from hikyuu.util.mylog import escapetime
from hikyuu.indicator import Indicator, MA, CLOSE, VOL, OP
from hikyuu.trade_sys.signal import SG_Cross
from hikyuu.interactive.drawplot import (create_two_axes_figure, ax_set_locator_formatter, adjust_axes_show,
create_three_axes_figure, ax_draw_macd,
ax_draw_signal)
from hikyuu.interactive.drawplot import (create_figure,
ax_set_locator_formatter,
adjust_axes_show,
create_three_axes_figure,
ax_draw_macd)
def draw(stock, query=Query(-130), ma1_n=5, ma2_n=10, ma3_n=20, ma4_n=60,
ma5_n=100, ma_type="SMA", vma1_n=5, vma2_n=10):
"""绘制普通K线图 + 成交量(成交金额)"""
kdata = stock.getKData(query)
close = CLOSE(kdata,)
ma1 = MA(close, ma1_n, ma_type)
@ -28,7 +53,7 @@ def draw(stock, query=Query(-130), ma1_n=5, ma2_n=10, ma3_n=20, ma4_n=60,
ma4 = MA(close, ma4_n, ma_type)
ma5 = MA(close, ma5_n, ma_type)
ax1, ax2 = create_two_axes_figure()
ax1, ax2 = create_figure(2)
kdata.plot(axes=ax1)
ma1.plot(axes=ax1, legend_on=True)
ma2.plot(axes=ax1, legend_on=True)
@ -38,8 +63,7 @@ def draw(stock, query=Query(-130), ma1_n=5, ma2_n=10, ma3_n=20, ma4_n=60,
sg = SG_Cross(OP(MA(n=ma1_n, type=ma_type)), OP(MA(n=ma2_n, type=ma_type)))
sg.setTO(kdata)
ax_draw_signal(ax1, kdata, sg.getBuySignal(), 'BUY', 1)
ax_draw_signal(ax1, kdata, sg.getSellSignal(), 'SELL', 1)
sg.plot(axes=ax1, kdata=kdata)
vol = VOL(kdata)
total = len(kdata)
@ -63,7 +87,9 @@ def draw(stock, query=Query(-130), ma1_n=5, ma2_n=10, ma3_n=20, ma4_n=60,
adjust_axes_show([ax1, ax2])
def draw2(stock, query=Query(-130), ma1_n=7, ma2_n=20, ma3_n=30, ma4_n=42, ma5_n=100, vma1_n=5, vma2_n=10):
def draw2(stock, query=Query(-130), ma1_n=7, ma2_n=20, ma3_n=30,
ma4_n=42, ma5_n=100, vma1_n=5, vma2_n=10):
"""绘制普通K线图 + 成交量(成交金额)+ MACD"""
kdata = stock.getKData(query)
close = CLOSE(kdata)
ma1 = MA(close, ma1_n)