| 137 | |
| 138 | |
| 139 | def plot_exit(fig, exit_profit, exit_nbar_best, exit_nbar_worst, profits_more, risks, nbar, binwidth=1): |
| 140 | #fig.canvas.set_window_title(u'������Ϣ') |
| 141 | axescolor = '#f6f6f6' # the axes background color |
| 142 | left, width = 0.1, 0.8 |
| 143 | rect2 = [left, 0.4, width, 0.4] |
| 144 | rect3 = [left, 0.1, width, 0.3] |
| 145 | |
| 146 | ax1 = fig.add_axes(rect3, axisbg=axescolor) |
| 147 | ax2 = fig.add_axes(rect2, axisbg=axescolor, sharex=ax1) |
| 148 | if nbar > 0: |
| 149 | print "**66666" |
| 150 | # plot ax1 |
| 151 | profits_more.plot(ax=ax1, kind='bar', grid = False, use_index = False, label=u"%s������"%nbar) |
| 152 | risks.plot(ax=ax1, kind='bar', grid = False, use_index = False, color = 'y', label=u"%s�����"%nbar) |
| 153 | temp = risks[risks<0] |
| 154 | ax1.plot(range(len(temp)), [temp.mean()]*len(temp), 'y--', label=u"ƽ������: %s"%temp.mean()) |
| 155 | temp = profits_more[profits_more>0] |
| 156 | ax1.plot(range(len(temp)), [temp.mean()]*len(temp), 'r--', label=u"ƽ������: %s"%temp.mean()) |
| 157 | ax1.legend(prop=font, loc='upper left').get_frame().set_alpha(0.5) |
| 158 | #ax1.annotate(str(np.mean(risks)), xy=(len(records)/2, np.mean(risks)), xycoords='data', |
| 159 | #xytext=(-30, -30), textcoords='offset points', color='b', |
| 160 | #arrowprops=dict(arrowstyle="->", |
| 161 | #connectionstyle="arc3,rad=.2") |
| 162 | #) |
| 163 | |
| 164 | # plot ax2 |
| 165 | for i in xrange(len(exit_profit)): |
| 166 | if(exit_nbar_best[i]>exit_profit[i] and exit_profit[i]>0): |
| 167 | px21 = ax2.bar(i, exit_profit[i], width=binwidth, color='blue') |
| 168 | px22 = ax2.bar(i, exit_nbar_best[i]-exit_profit[i], width=binwidth, color='red', bottom = exit_profit[i]) |
| 169 | elif(exit_nbar_best[i]<exit_profit[i] and exit_profit[i]>0 and exit_nbar_best[i]>0): |
| 170 | ax2.bar(i, exit_nbar_best[i], width=binwidth, color='red') |
| 171 | ax2.bar(i, exit_profit[i]-exit_nbar_best[i], width=binwidth, color='blue', bottom = exit_nbar_best[i]) |
| 172 | elif(exit_nbar_best[i]<exit_profit[i] and exit_profit[i]<0): |
| 173 | ax2.bar(i, exit_profit[i], width=binwidth, color='red') |
| 174 | ax2.bar(i, exit_nbar_best[i]-exit_profit[i], width=binwidth, color='blue', bottom = exit_profit[i]) |
| 175 | elif(exit_nbar_best[i]>exit_profit[i] and exit_profit[i]<0 and exit_nbar_best[i]<0): |
| 176 | ax2.bar(i, exit_nbar_best[i], width=binwidth, color='red') |
| 177 | ax2.bar(i, exit_profit[i]-exit_nbar_best[i], width=binwidth, color='blue', bottom = exit_nbar_best[i]) |
| 178 | else: |
| 179 | ax2.bar(i, exit_nbar_best[i], width=binwidth, color='red') |
| 180 | ax2.bar(i, exit_profit[i], width=binwidth, color='blue') |
| 181 | ax2.legend((px21[0], px22[0]), (u'ʵ��ӯ��', u'�ӳ�����ӯ��'),loc='upper left', prop=font).get_frame().set_alpha(0.5) |
| 182 | ax2.set_ylabel(u"���������ڵ�ӯ��", fontproperties = font) |
| 183 | for ax in ax1, ax2: |
| 184 | #if ax!=ax1: |
| 185 | ax.set_xticklabels([]) |
| 186 | |
| 187 | ax1.set_xlabel("") |
| 188 | ax2.set_title(u"���������Ϣ", fontproperties=font_big) |
| 189 | multi = MultiCursor(fig.canvas, fig.axes, color='r', lw=1, horizOn=False, vertOn=True) |
| 190 | return [ax1, ax2], [multi] |
| 191 | else: |
| 192 | return [], [] |
| 193 | |
| 194 | |
| 195 | def plot_summary(fig, exit_profit, entry_best, entry_worst, entry_nbar_best, entry_nbar_worst, |