Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save quantra-go-algo/2777ebbcdf4b1418dcc5bf7e633c4477 to your computer and use it in GitHub Desktop.
Save quantra-go-algo/2777ebbcdf4b1418dcc5bf7e633c4477 to your computer and use it in GitHub Desktop.
# Subset the data
plot_data = data.iloc[initial_iloc:]
# Buy and hold strategy cumulative returns
plot_data['buy_and_hold_cum_returns'] = (1+plot_data['returns']).cumprod()
# Strategy returns
plot_data['strategy_returns'] = plot_data['returns'] * plot_data['signal']
# Strategy cumulative returns
plot_data['strategy_cum_returns'] = (1+plot_data['strategy_returns']*2).cumprod()
# Set the figure size
plt.figure(figsize=(15,7))
# Plot both the Buy-and-hold, SMA and HMM-DC-based strategy cumulative returns
plt.plot(plot_data.index, plot_data['buy_and_hold_cum_returns'], label = "Buy and Hold Returns")
plt.plot(plot_data.index, plot_data['strategy_cum_returns'], label = "Strategy Returns", color='g')
# Set the title of the graph
plt.title('Buy-and-Hold and Strategy Cumulative Returns', fontsize=16)
# Set the x- and y- axis labels and ticks sizes
plt.xlabel('Year', fontsize=15)
plt.ylabel('Cumulative Returns', fontsize=15)
plt.tick_params(axis='both', labelsize=15)
# Set the plot legend location
plt.legend(loc=2, prop={'size': 15}, bbox_to_anchor=(0,1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment