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
def TradeList_to_np(t_list): """转化为numpy结构数组""" t_type = np.dtype({'names':['交易日期','证券代码', '证券名称', '业务名称', '计划交易价格', '实际成交价格', '目标价格', '成交数量', '佣金', '印花税', '过户费', '其它成本', '交易总成本', '止损价', '现金余额', '信号来源'], 'formats':['datetime64[D]','U10','U20', 'U10', 'd', 'd', 'd', 'i', 'd', 'd', 'd', 'd','d', 'd', 'd', 'U5']}) return np.array([(t.datetime, t.stock.market_code, t.stock.name, getBusinessName(t.business), t.planPrice, t.realPrice, t.goalPrice, t.number, t.cost.commission, t.cost.stamptax, t.cost.transferfee, t.cost.others, t.cost.total, t.stoploss, t.cash, getSystemPartName(t.part) ) for t in t_list], dtype=t_type)