Created
March 6, 2024 17:58
-
-
Save quantra-go-algo/2777ebbcdf4b1418dcc5bf7e633c4477 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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