def twoDimensionalScatter(title, title_x, title_y,
x, y,
lim_x = None, lim_y = None,
color = 'b', size = 20, alpha=None):
"""
Create a two-dimensional scatter plot.
INPUTS
"""
pylab.figure()
pylab.scatter(x, y, c=color, s=size, alpha=alpha, edgecolors='none')
pylab.xlabel(title_x)
pylab.ylabel(title_y)
pylab.title(title)
if type(color) is not str:
pylab.colorbar()
if lim_x:
pylab.xlim(lim_x[0], lim_x[1])
if lim_y:
pylab.ylim(lim_y[0], lim_y[1])
############################################################
python类title()的实例源码
def view_dataset(X, color='blue', title=None, save=None):
n_components = 2
pca = PCA(n_components)
pca.fit(X)
x = pca.transform(X)
fig = pylab.figure()
ax = fig.add_subplot(1, 1, 1)
ax.scatter(x[:, 0], x[:, 1], c=color, s=5, lw=0.1)
ax.grid(True)
if title is None:
ax.set_title("Dataset ({} samples)".format(X.shape[0]))
else:
ax.set_title(title + " ({} samples)".format(X.shape[0]))
ax.set_xlabel("1st component")
ax.set_ylabel("2nd component")
if save is None:
pylab.show()
else:
pylab.savefig(save)
pylab.close(fig)
return
def view_loss_curve(losss, title=None, save=None):
'''Plot loss curve'''
x_min = 1
x_max = len(losss) - 1
fig = pylab.figure()
ax = fig.gca()
ax.semilogy(range(x_min, x_max + 1), losss[1:], color='blue', linestyle='solid')
ax.grid(True, which='both')
if title is None:
ax.set_title("Loss curve")
else:
ax.set_title(title)
ax.set_xlabel("iteration")
ax.set_ylabel("loss")
ax.set_xlim([x_min - 1, x_max + 1])
if save is None:
pylab.show()
else:
pylab.savefig(save)
pylab.close(fig)
return
def display_results_figure(results, METRIC):
import pylab as pb
color = iter(pb.cm.rainbow(np.linspace(0, 1, len(results))))
plots = []
for method in results.keys():
x = []
y = []
for train_perc in sorted(results[method].keys()):
x.append(train_perc)
y.append(results[method][train_perc][0])
c = next(color)
(pi, ) = pb.plot(x, y, color=c)
plots.append(pi)
from matplotlib.font_manager import FontProperties
fontP = FontProperties()
fontP.set_size('small')
pb.legend(plots, map(method_name_mapper, results.keys()),
prop=fontP, bbox_to_anchor=(0.6, .65))
pb.xlabel('#Tweets from target rumour for training')
pb.ylabel('Accuracy')
pb.title(METRIC.__name__)
pb.savefig('incrementing_training_size.png')
two_sigma_financial_modelling.py 文件源码
项目:PortfolioTimeSeriesAnalysis
作者: MizioAnd
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def predicted_vs_actual_y_xgb(self, xgb, best_nrounds, xgb_params, x_train_split, x_test_split, y_train_split,
y_test_split, title_name):
# Split the training data into an extra set of test
# x_train_split, x_test_split, y_train_split, y_test_split = train_test_split(x_train, y_train)
dtrain_split = xgb.DMatrix(x_train_split, label=y_train_split)
dtest_split = xgb.DMatrix(x_test_split)
print(np.shape(x_train_split), np.shape(x_test_split), np.shape(y_train_split), np.shape(y_test_split))
gbdt = xgb.train(xgb_params, dtrain_split, best_nrounds)
y_predicted = gbdt.predict(dtest_split)
plt.figure(figsize=(10, 5))
plt.scatter(y_test_split, y_predicted, s=20)
rmse_pred_vs_actual = self.rmse(y_predicted, y_test_split)
plt.title(''.join([title_name, ', Predicted vs. Actual.', ' rmse = ', str(rmse_pred_vs_actual)]))
plt.xlabel('Actual y')
plt.ylabel('Predicted y')
plt.plot([min(y_test_split), max(y_test_split)], [min(y_test_split), max(y_test_split)])
plt.tight_layout()
def display_pr_curve(precision, recall):
# following examples from sklearn
# TODO: f1 operating point
import pylab as plt
# Plot Precision-Recall curve
plt.clf()
plt.plot(recall, precision, label='Precision-Recall curve')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.ylim([0.0, 1.05])
plt.xlim([0.0, 1.0])
plt.title('Precision-Recall example: Max f1={0:0.2f}'.format(max_f1))
plt.legend(loc="lower left")
plt.show()
def plotaffine(aff, RR, DD, exag=1000, affineOnly=False, doclf=True, **kwargs):
import pylab as plt
if doclf:
plt.clf()
if affineOnly:
dr,dd = aff.getAffineOffset(RR, DD)
else:
rr,dd = aff.apply(RR, DD)
dr = rr - RR
dd = dd - DD
#plt.plot(RR, DD, 'r.')
#plt.plot(RR + dr*exag, DD + dd*exag, 'bx')
plt.quiver(RR, DD, exag*dr, exag*dd,
angles='xy', scale_units='xy', scale=1,
pivot='middle', color='b', **kwargs)
#pivot='tail'
ax = plt.axis()
plt.plot([aff.getReferenceRa()], [aff.getReferenceDec()], 'r+', mew=2, ms=5)
plt.axis(ax)
esuf = ''
if exag != 1.:
esuf = ' (x %g)' % exag
plt.title('Affine transformation found' + esuf)
def plot_rectified(self):
import pylab
pylab.title('rectified')
pylab.imshow(self.rectified)
for line in self.vlines:
p0, p1 = line
p0 = self.inv_transform(p0)
p1 = self.inv_transform(p1)
pylab.plot((p0[0], p1[0]), (p0[1], p1[1]), c='green')
for line in self.hlines:
p0, p1 = line
p0 = self.inv_transform(p0)
p1 = self.inv_transform(p1)
pylab.plot((p0[0], p1[0]), (p0[1], p1[1]), c='red')
pylab.axis('image');
pylab.grid(c='yellow', lw=1)
pylab.plt.yticks(np.arange(0, self.l, 100.0));
pylab.xlim(0, self.w)
pylab.ylim(self.l, 0)
def plot_original(self):
import pylab
pylab.title('original')
pylab.imshow(self.data)
for line in self.lines:
p0, p1 = line
pylab.plot((p0[0], p1[0]), (p0[1], p1[1]), c='blue', alpha=0.3)
for line in self.vlines:
p0, p1 = line
pylab.plot((p0[0], p1[0]), (p0[1], p1[1]), c='green')
for line in self.hlines:
p0, p1 = line
pylab.plot((p0[0], p1[0]), (p0[1], p1[1]), c='red')
pylab.axis('image');
pylab.grid(c='yellow', lw=1)
pylab.plt.yticks(np.arange(0, self.l, 100.0));
pylab.xlim(0, self.w)
pylab.ylim(self.l, 0)
def plot(self):
""" Plot the layer data (for debugging)
:return: The current figure
"""
import pylab as pl
aspect = self.nrows / float(self.ncols)
figure_width = 6 #inches
rows = max(1, int(np.sqrt(self.nlayers)))
cols = int(np.ceil(self.nlayers/rows))
# noinspection PyUnresolvedReferences
pallette = {i:rgb for (i, rgb) in enumerate(pl.cm.jet(np.linspace(0, 1, 4), bytes=True))}
f, a = pl.subplots(rows, cols)
f.set_size_inches(6 * cols, 6 * rows)
a = a.flatten()
for i, label in enumerate(self.label_names):
pl.sca(a[i])
pl.title(label)
pl.imshow(self.color_data)
pl.imshow(colorize(self.label_data[:, :, i], pallette), alpha=0.5)
# axis('off')
return f
def plot(self, overlay_alpha=0.5):
import pylab as pl
rows = int(sqrt(self.layers()))
cols = int(ceil(self.layers()/rows))
for i in range(rows*cols):
pl.subplot(rows, cols, i+1)
pl.axis('off')
if i >= self.layers():
continue
pl.title('{}({})'.format(self.labels[i], i))
pl.imshow(self.image)
pl.imshow(colorize(self.features[i].argmax(0),
colors=np.array([[0, 0, 255],
[0, 255, 255],
[255, 255, 0],
[255, 0, 0]])),
alpha=overlay_alpha)
def plotPopScore(population, fitness=False):
""" Plot the population score distribution
Example:
>>> Interaction.plotPopScore(population)
:param population: population object (:class:`GPopulation.GPopulation`)
:param fitness: if True, the fitness score will be used, otherwise, the raw.
:rtype: None
"""
score_list = getPopScores(population, fitness)
pylab.plot(score_list, 'o')
pylab.title("Plot of population score distribution")
pylab.xlabel('Individual')
pylab.ylabel('Score')
pylab.grid(True)
pylab.show()
# -----------------------------------------------------------------
def plotHistPopScore(population, fitness=False):
""" Population score distribution histogram
Example:
>>> Interaction.plotHistPopScore(population)
:param population: population object (:class:`GPopulation.GPopulation`)
:param fitness: if True, the fitness score will be used, otherwise, the raw.
:rtype: None
"""
score_list = getPopScores(population, fitness)
n, bins, patches = pylab.hist(score_list, 50, facecolor='green', alpha=0.75, normed=1)
pylab.plot(bins, pylab.normpdf(bins, numpy.mean(score_list), numpy.std(score_list)), 'r--')
pylab.xlabel('Score')
pylab.ylabel('Frequency')
pylab.grid(True)
pylab.title("Plot of population score distribution")
pylab.show()
# -----------------------------------------------------------------
def plotPopScore(population, fitness=False):
""" Plot the population score distribution
Example:
>>> Interaction.plotPopScore(population)
:param population: population object (:class:`GPopulation.GPopulation`)
:param fitness: if True, the fitness score will be used, otherwise, the raw.
:rtype: None
"""
score_list = getPopScores(population, fitness)
pylab.plot(score_list, 'o')
pylab.title("Plot of population score distribution")
pylab.xlabel('Individual')
pylab.ylabel('Score')
pylab.grid(True)
pylab.show()
# -----------------------------------------------------------------
def plotHistPopScore(population, fitness=False):
""" Population score distribution histogram
Example:
>>> Interaction.plotHistPopScore(population)
:param population: population object (:class:`GPopulation.GPopulation`)
:param fitness: if True, the fitness score will be used, otherwise, the raw.
:rtype: None
"""
score_list = getPopScores(population, fitness)
n, bins, patches = pylab.hist(score_list, 50, facecolor='green', alpha=0.75, normed=1)
pylab.plot(bins, pylab.normpdf(bins, numpy.mean(score_list), numpy.std(score_list)), 'r--')
pylab.xlabel('Score')
pylab.ylabel('Frequency')
pylab.grid(True)
pylab.title("Plot of population score distribution")
pylab.show()
# -----------------------------------------------------------------
def plot_profiles(self):
"""
Plot TOPP profiles, e.g. for debugging.
"""
import pylab
pylab.ion()
self.topp.WriteProfilesList()
self.topp.WriteSwitchPointsList()
profileslist = TOPP.TOPPpy.ProfilesFromString(
self.topp.resprofilesliststring)
switchpointslist = TOPP.TOPPpy.SwitchPointsFromString(
self.topp.switchpointsliststring)
TOPP.TOPPpy.PlotProfiles(profileslist, switchpointslist)
TOPP.TOPPpy.PlotAlphaBeta(self.topp)
pylab.title("%s phase profile" % type(self).__name__)
pylab.axis([0, 1, 0, 10])
def predicted_vs_actual_sale_price(self, x_train, y_train, title_name):
# Split the training data into an extra set of test
x_train_split, x_test_split, y_train_split, y_test_split = train_test_split(x_train, y_train)
print(np.shape(x_train_split), np.shape(x_test_split), np.shape(y_train_split), np.shape(y_test_split))
lasso = LassoCV(alphas=[0.0001, 0.0003, 0.0006, 0.001, 0.003, 0.006, 0.01, 0.03, 0.06, 0.1,
0.3, 0.6, 1],
max_iter=50000, cv=10)
# lasso = RidgeCV(alphas=[0.0001, 0.0003, 0.0006, 0.001, 0.003, 0.006, 0.01, 0.03, 0.06, 0.1,
# 0.3, 0.6, 1], cv=10)
lasso.fit(x_train_split, y_train_split)
y_predicted = lasso.predict(X=x_test_split)
plt.figure(figsize=(10, 5))
plt.scatter(y_test_split, y_predicted, s=20)
rmse_pred_vs_actual = self.rmse(y_predicted, y_test_split)
plt.title(''.join([title_name, ', Predicted vs. Actual.', ' rmse = ', str(rmse_pred_vs_actual)]))
plt.xlabel('Actual Sale Price')
plt.ylabel('Predicted Sale Price')
plt.plot([min(y_test_split), max(y_test_split)], [min(y_test_split), max(y_test_split)])
plt.tight_layout()
def predicted_vs_actual_sale_price_xgb(self, xgb_params, x_train, y_train, seed, title_name):
# Split the training data into an extra set of test
x_train_split, x_test_split, y_train_split, y_test_split = train_test_split(x_train, y_train)
dtrain_split = xgb.DMatrix(x_train_split, label=y_train_split)
dtest_split = xgb.DMatrix(x_test_split)
res = xgb.cv(xgb_params, dtrain_split, num_boost_round=1000, nfold=4, seed=seed, stratified=False,
early_stopping_rounds=25, verbose_eval=10, show_stdv=True)
best_nrounds = res.shape[0] - 1
print(np.shape(x_train_split), np.shape(x_test_split), np.shape(y_train_split), np.shape(y_test_split))
gbdt = xgb.train(xgb_params, dtrain_split, best_nrounds)
y_predicted = gbdt.predict(dtest_split)
plt.figure(figsize=(10, 5))
plt.scatter(y_test_split, y_predicted, s=20)
rmse_pred_vs_actual = self.rmse(y_predicted, y_test_split)
plt.title(''.join([title_name, ', Predicted vs. Actual.', ' rmse = ', str(rmse_pred_vs_actual)]))
plt.xlabel('Actual Sale Price')
plt.ylabel('Predicted Sale Price')
plt.plot([min(y_test_split), max(y_test_split)], [min(y_test_split), max(y_test_split)])
plt.tight_layout()
def check_acf(df):
df_num = df.select_dtypes(include=[np.float, np.int])
for index in df_num.columns:
plt.figure(figsize=(8,10))
if index in ['LOG_BULL_RETURN', 'LOG_BEAR_RETURN','RTISf', 'TOTAL_SCANNED_MESSAGES_DIFF', 'TOTAL_SENTIMENT_MESSAGES_DIFF']:
fig = sm.graphics.tsa.plot_acf(df_num[index][1:],lags=40)
plt.title(index)
elif index in ['LOG_BULL_BEAR_RATIO']:
fig = sm.graphics.tsa.plot_acf(df_num[index][2:],lags=40)
plt.title(index)
else:
fig = sm.graphics.tsa.plot_acf(df_num[index],lags=40)
plt.title(index)
return fig
# check adf test
4(improved-7).py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def show_results(self):
pl.plot(self.t1, self.n_A1, 'b--', label='A1: Time Step = 0.05')
pl.plot(self.t1, self.n_B1, 'b', label='B1: Time Step = 0.05')
pl.plot(self.t2, self.n_A2, 'g--', label='A2: Time Step = 0.1')
pl.plot(self.t2, self.n_B2, 'g', label='B2: Time Step = 0.1')
pl.plot(self.t1, self.n_A1_true, 'r--', label='True A1: Time Step = 0.05')
pl.plot(self.t1, self.n_B1_true, 'r', label='True B1: Time Step = 0.05')
pl.plot(self.t2, self.n_A2_true, 'c--', label='True A2: Time Step = 0.1')
pl.plot(self.t2, self.n_B2_true, 'c', label='True B2: Time Step = 0.1')
pl.title('Double Decay Probelm-Approximation Compared with True in Defferent Time Steps')
pl.xlim(0.0, 0.1)
pl.ylim(0.0, 100.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='best', shadow=True, fontsize='small')
pl.grid(True)
pl.savefig("computational_physics homework 4(improved-7).png")
7 code plus.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def show(self):
# pl.semilogy(self.theta, self.omega)
# , label = '$L =%.1f m, $'%self.l + '$dt = %.2f s, $'%self.dt + '$\\theta_0 = %.2f radians, $'%self.theta[0] + '$q = %i, $'%self.q + '$F_D = %.2f, $'%self.F_D + '$\\Omega_D = %.1f$'%self.Omega_D)
pl.plot(self.theta_phase ,self.omega_phase, '.', label = '$t \\approx 2\\pi n / \\Omega_D$')
pl.xlabel('$\\theta$ (radians)')
pl.ylabel('$\\omega$ (radians/s)')
pl.legend()
# pl.text(-1.4, 0.3, '$\\omega$ versus $\\theta$ $F_D = 1.2$', fontsize = 'x-large')
pl.title('Chaotic Regime')
# pl.show()
# pl.semilogy(self.time_array, self.delta)
# pl.legend(loc = 'upper center', fontsize = 'small')
# pl.xlabel('$time (s)$')
# pl.ylabel('$\\Delta\\theta (radians)$')
# pl.xlim(0, self.T)
# pl.ylim(float(input('ylim-: ')),float(input('ylim+: ')))
# pl.ylim(1E-11, 0.01)
# pl.text(4, -0.15, 'nonlinear pendulum - Euler-Cromer method')
# pl.text(10, 1E-3, '$\\Delta\\theta versus time F_D = 0.5$')
# pl.title('Simple Harmonic Motion')
pl.title('Chaotic Regime')
7 code plus.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def show_log(self):
# pl.subplot(121)
pl.semilogy(self.time_array, self.delta, 'c')
pl.xlabel('$time (s)$')
pl.ylabel('$\\Delta\\theta$ (radians)')
pl.xlim(0, self.T)
# pl.ylim(1E-11, 0.01)
pl.text(42, 1E-7, '$\\Delta\\theta$ versus time $F_D = 1.2$', fontsize = 'x-large')
pl.title('Chaotic Regime')
pl.show()
# def show_log_sub122(self):
# pl.subplot(122)
# pl.semilogy(self.time_array, self.delta, 'g')
# pl.xlabel('$time (s)$')
# pl.ylabel('$\\Delta\\theta$ (radians)')
# pl.xlim(0, self.T)
# pl.ylim(1E-6, 100)
# pl.text(20, 1E-5, '$\\Delta\\theta$ versus time $F_D = 1.2$', fontsize = 'x-large')
# pl.title('Chaotic Regime')
# pl.show()
7 code.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def show_log(self):
# pl.subplot(121)
pl.semilogy(self.time_array, self.delta, 'c')
pl.xlabel('$time (s)$')
pl.ylabel('$\\Delta\\theta$ (radians)')
pl.xlim(0, self.T)
# pl.ylim(1E-11, 0.01)
pl.text(42, 1E-7, '$\\Delta\\theta$ versus time $F_D = 1.2$', fontsize = 'x-large')
pl.title('Chaotic Regime')
pl.show()
# def show_log_sub122(self):
# pl.subplot(122)
# pl.semilogy(self.time_array, self.delta, 'g')
# pl.xlabel('$time (s)$')
# pl.ylabel('$\\Delta\\theta$ (radians)')
# pl.xlim(0, self.T)
# pl.ylim(1E-6, 100)
# pl.text(20, 1E-5, '$\\Delta\\theta$ versus time $F_D = 1.2$', fontsize = 'x-large')
# pl.title('Chaotic Regime')
# pl.show()
6 code.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def show_complex(self):
font = {'family': 'serif',
'color': 'k',
'weight': 'normal',
'size': 16,
}
pl.title('The Trajectory of Tageted Baseball\n with air flow in adiabatic model', fontdict = font)
pl.plot(self.x, self.y, label = '$v_0 = %.5f m/s$'%self.v0 + ', ' + '$\\theta = %.4f \degree$'%self.theta)
pl.xlabel('x $m$')
pl.ylabel('y $m$')
pl.xlim(0, 300)
pl.ylim(-100, 20)
pl.grid()
pl.legend(loc = 'upper right', shadow = True, fontsize = 'small')
pl.text(15, -90, 'scan to approach the minimum velocity and corresponding launching angle', fontdict = font)
pl.show()
6 code.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def show_simple(self):
font = {'family': 'serif',
'color': 'k',
'weight': 'normal',
'size': 16,
}
pl.title('The Trajectory of Tageted Baseball\n with air flow in adiabatic model', fontdict = font)
pl.plot(self.x, self.y, label ='$\\alpha = %.0f \degree$'%self.alpha)
pl.xlabel('x $m$')
pl.ylabel('y $m$')
pl.xlim(0, 400)
pl.ylim(-100, 200)
pl.grid()
pl.legend(loc = 'upper right', shadow = True, fontsize = 'medium')
pl.text(5, -80, 'trojectories varing with angles of wind', fontdict = font)
pl.show()
5 code 1.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def show_results(self):
font = {'family': 'serif',
'color': 'k',
'weight': 'normal',
'size': 14,
}
pl.plot(self.x, self.y, 'c', label='firing angle = 45°')
pl.title('The Trajectory of a Cannon Shell', fontdict = font)
pl.xlabel('x (k$m$)')
pl.ylabel('y ($km$)')
pl.xlim(0, 60)
pl.ylim(0, 20)
pl.grid(True)
pl.legend(loc='upper right', shadow=True, fontsize='large')
pl.text(41, 16, 'Only with air drag', fontdict = font)
pl.show()
5 code 2.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 29
收藏 0
点赞 0
评论 0
def show_results(self):
font = {'family': 'serif',
'color': 'k',
'weight': 'normal',
'size': 12,
}
pl.plot(self.x, self.y, 'c', label='firing angle = 45°')
pl.title('The Trajectory of a Cannon Shell', fontdict = font)
pl.xlabel('x (k$m$)')
pl.ylabel('y ($km$)')
pl.xlim(0, 60)
pl.ylim(0, 20)
pl.grid(True)
pl.legend(loc='upper right', shadow=True, fontsize='large')
pl.text(34, 16, ' With both air drag and \n reduced air density-isothermal', fontdict = font)
pl.show()
5 code 3.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def show_results(self):
font = {'family': 'serif',
'color': 'k',
'weight': 'normal',
'size': 12,
}
pl.plot(self.x, self.y, 'c', label='firing angle = 45°')
pl.title('The Trajectory of a Cannon Shell', fontdict = font)
pl.xlabel('x (k$m$)')
pl.ylabel('y ($km$)')
pl.xlim(0, 60)
pl.ylim(0, 20)
pl.grid(True)
pl.legend(loc='upper right', shadow=True, fontsize='large')
pl.text(34.5, 16, ' With both air drag and \n reduced air density-adiabatic', fontdict = font)
pl.show()
def DrawDvs(pl, closes, curve, sign, dvs, pandl, sh, title, leag=None, lad=None ):
pl.figure
pl.subplot(311)
pl.title("id:%s Sharpe ratio: %.2f"%(str(title),sh))
pl.plot(closes)
DrawLine(pl, sign, closes)
pl.subplot(312)
pl.grid()
if dvs != None:
pl.plot(dvs)
if isinstance(curve, np.ndarray):
DrawZZ(pl, curve, 'r')
if leag != None:
pl.plot(leag, 'r')
if lad != None:
pl.plot(lad, 'b')
#pl.plot(stock.GuiYiHua(closes[:i])[60:])
pl.subplot(313)
pl.plot(sign)
pl.plot(pandl)
pl.show()
pl.close()
def TradeResult_Boll(pl, bars, trade_positions, zhijin,changwei, title=''):
"""??????
bars: df ??? c????
trade_positions: np.darray or df ????
zhijin: df index?bars
changwei: df index?bars
title: str ??????decode(utf8)
"""
signals = pd.DataFrame(index=bars.index)
signals['signal'] = 0.0
signals['signal'] = np.zeros(len(bars['c']))
if agl.IsNone(trade_positions):
signals['positions'] = signals['signal'].diff()
signals['positions'][10] = 1
signals['positions'][13] = 1
signals['positions'][20] = -1
else:
signals['positions'] = trade_positions
ShowTradeResult2(pl, bars, signals, zhijin,changwei , 0, title=title)