Skip to content

Instantly share code, notes, and snippets.

@lamres
Created November 15, 2018 11:24
Show Gist options
  • Select an option

  • Save lamres/8a11583f3326c3ae3d3d32b71726293b to your computer and use it in GitHub Desktop.

Select an option

Save lamres/8a11583f3326c3ae3d3d32b71726293b to your computer and use it in GitHub Desktop.
def analyze(context, perf):
# Summary output
print('Total return: ' + str(perf.algorithm_period_return[-1]))
print('Sortino coef: ' + str(perf.sortino[-1]))
print('Max drawdown: ' + str(np.min(perf.max_drawdown)))
print('Alpha: ' + str(perf.alpha[-1]))
print('Beta: ' + str(perf.beta[-1]))
perf.to_csv('perf_' + str(context.asset) + '.csv')
f = plt.figure(figsize = (7.2, 7.2))
# Plot performance
ax1 = f.add_subplot(611)
ax1.plot(perf.algorithm_period_return, 'blue')
ax1.plot(perf.benchmark_period_return, 'red')
ax1.set_title('Performance')
ax1.set_xlabel('Time')
ax1.set_ylabel('Return')
# Plot price and renko price
ax2 = f.add_subplot(612, sharex = ax1)
ax2.plot(perf.price, 'grey')
ax2.plot(perf.renko_price, 'yellow')
ax2.set_title(context.asset)
ax2.set_xlabel('Time')
ax2.set_ylabel('Price')
# Plot brick size
ax3 = f.add_subplot(613, sharex = ax1)
ax3.plot(perf.brick_size, 'blue')
xcoords = perf.index[perf.rebuilding_status == 1]
for xc in xcoords:
ax3.axvline(x = xc, color = 'red')
ax3.set_title('Brick size and rebuilding status')
ax3.set_xlabel('Time')
ax3.set_ylabel('Size and Status')
# Plot renko_price
ax4 = f.add_subplot(614, sharex = ax1)
ax4.plot(perf.num_created_bars, 'green')
ax4.set_title('Number of created Renko bars')
ax4.set_xlabel('Time')
ax4.set_ylabel('Amount')
# Plot amount of asset in portfolio
ax5 = f.add_subplot(615, sharex = ax1)
ax5.plot(perf.amount, 'black')
ax5.set_title('Asset amount in portfolio')
ax5.set_xlabel('Time')
ax5.set_ylabel('Amount')
# Plot drawdown
ax6 = f.add_subplot(616, sharex = ax1)
ax6.plot(perf.max_drawdown, 'yellow')
ax6.set_title('Max drawdown')
ax6.set_xlabel('Time')
ax6.set_ylabel('Drawdown')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment