Skip to content

Instantly share code, notes, and snippets.

@lamres
Created September 3, 2019 17:59
Show Gist options
  • Save lamres/955704fc8adf6bb8588f28ab54447862 to your computer and use it in GitHub Desktop.
Save lamres/955704fc8adf6bb8588f28ab54447862 to your computer and use it in GitHub Desktop.
def analyze(context, perf):
sns.set()
# 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[-1])))
print("alpha: " + str(perf.alpha[-1]))
print("beta: " + str(perf.beta[-1]))
f = plt.figure(figsize = (7.2, 7.2))
# Plot return
ax1 = f.add_subplot(211)
ax1.plot(perf.algorithm_period_return, 'blue')
ax1.plot(perf.benchmark_period_return, 'red')
ax1.legend()
ax1.set_title("Returns")
ax1.set_xlabel('Time')
ax1.set_ylabel('Value')
# Plot state
ax2 = f.add_subplot(212, sharex = ax1)
ax2.plot(perf.state, 'grey')
ax2.set_title("State")
ax2.set_xlabel('Time')
ax2.set_ylabel('Value')
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment