MCPcopy Index your code
hub / github.com/QuantFans/quantdigger / plot_entry

Function plot_entry

quantdigger/widgets/mplotwidgets/stock_plot.py:76–136  ·  view source on GitHub ↗
(fig, exit_profit, entry_best, entry_worst, entry_nbar_best, entry_nbar_worst, nbar, binwidth=1)

Source from the content-addressed store, hash-verified

74
75
76def plot_entry(fig, exit_profit, entry_best, entry_worst, entry_nbar_best, entry_nbar_worst, nbar, binwidth=1):
77 fig.canvas.set_window_title(u'�볡��Ϣ')
78 axescolor = '#f6f6f6' # the axes background color
79 left, width = 0.1, 0.8
80 rect1 = [left, 0.7, width, 0.2]#left, bottom, width, height
81 rect2 = [left, 0.3, width, 0.4]
82 rect3 = [left, 0.1, width, 0.2]
83
84 ax1 = fig.add_axes(rect1, axisbg=axescolor)
85 ax2 = fig.add_axes(rect2, axisbg=axescolor, sharex = ax1)
86 ax3 = fig.add_axes(rect3, axisbg=axescolor, sharex = ax1)
87 (entry_best-exit_profit).plot(ax=ax1, kind='bar', grid = False, use_index = False, label=u"��ʵ��")
88 entry_worst.plot(ax=ax1, kind='bar', grid = False, use_index = False, color = 'y', label=u"�����ƫ��")
89 if nbar>0:
90 entry_nbar_best.plot(ax=ax3, kind='bar', color='red', grid=False, use_index=False, label=u"%s������"%nbar)
91 #ax3.bar(range(len(entry_nbar_best)), entry_nbar_best, color='r', label=u"%s������"%nbar)
92 entry_nbar_worst.plot(ax=ax3, kind='bar', color='y', grid=False, use_index=False, label=u"%s�����"%nbar)
93 temp = entry_nbar_worst[entry_nbar_worst<0]
94 ax3.plot(range(len(entry_nbar_best)), [temp.mean()]*len(entry_nbar_best), 'y--', label=u"ƽ������: %s"%temp.mean())
95 temp = entry_nbar_best[entry_nbar_best>0]
96 ax3.plot(range(len(entry_nbar_best)), [temp.mean()]*len(entry_nbar_best),
97 'r--', label=u'ƽ������: %s'%temp.mean() )
98 ax3.legend(loc='upper left',prop=font).get_frame().set_alpha(0.5)
99
100 for i in xrange(len(exit_profit)):
101 if(entry_best[i]>0 and exit_profit[i]>0):
102 px21 = ax2.bar(i, exit_profit[i], width=binwidth, color='blue')
103 px22 = ax2.bar(i, entry_best[i]-exit_profit[i], width=binwidth, color='red', bottom = exit_profit[i])
104 elif(entry_best[i]<0 and exit_profit[i]<0):
105 ax2.bar(i, entry_best[i], width=binwidth, color='red')
106 ax2.bar(i, exit_profit[i]-entry_best[i], width=binwidth, color='blue', bottom = entry_best[i])
107 else:
108 ax2.bar(i, entry_best[i], width=binwidth, color='red')
109 ax2.bar(i, exit_profit[i], width=binwidth, color='blue')
110
111 ax2.legend((px21[0], px22[0]), (u'ʵ��ӯ��', u'�������ӯ��'), loc='upper left', prop=font).get_frame().set_alpha(0.5)
112 ax1.legend(loc='upper left', prop=font).get_frame().set_alpha(0.5)
113 ax1.set_ylabel(u"���������ڵIJ�ֵ", fontproperties = font)
114 ax2.set_ylabel(u"���������ڵ�ӯ��", fontproperties = font)
115 for ax in ax1, ax2, ax3:
116 #if ax!=ax3:
117 ax.set_xticklabels([])
118
119 ax3.set_xlabel("")
120 ax1.set_title(u"�볡�����Ϣ", fontproperties=font_big)
121 c1 = Cursor(ax2, useblit=True, color='red', linewidth=1, vertOn = True, horizOn = True)
122 multi = MultiCursor(fig.canvas, fig.axes, color='r', lw=1, horizOn=False, vertOn=True)
123
124 #handle = EventHandler(exit_profit, fig)
125 #fig.canvas.mpl_connect('motion_notify_event', handle.on_move)
126 #fig.canvas.mpl_connect('pick_event', handle.on_pick)
127
128 def format_coord(x, y):
129 """ ״̬����Ϣ��ʾ """
130 i = int(x)/1
131 c = pd.to_datetime(exit_profit.index[i]).strftime("%Y-%m-%d %H:%M:%S") + " Profit: %s MAE: %s"%(exit_profit[i], entry_worst[i])
132 return str(c)
133 ax1.format_coord = format_coord

Callers 1

entry_analyzeFunction · 0.85

Calls 1

plotMethod · 0.45

Tested by

no test coverage detected