Skip to content

Instantly share code, notes, and snippets.

@quantra-go-algo
Created October 11, 2023 17:27
Show Gist options
  • Save quantra-go-algo/59f16876ce34ce011f3b672a19a29cff to your computer and use it in GitHub Desktop.
Save quantra-go-algo/59f16876ce34ce011f3b672a19a29cff to your computer and use it in GitHub Desktop.
# Compute the Buy-and-Hold cumulative returns
plot_data['buy_hold_cum_rets'] = np.exp(plot_data['returns'].cumsum())
# Compute the simple 4-day moving average strategy returns
plot_data['basic_stra_rets'] = plot_data['returns']*plot_data['signal'].shift(1)
# Compute the simple 4-day moving average strategy cumulative returns
plot_data['basic_stra_cum_rets'] = np.exp(plot_data['basic_stra_rets'].cumsum())
# Compute the HMM-DC-based strategy returns
plot_data['hmm_dc_stra_rets'] = plot_data['returns']*plot_data['signal'].shift(1)*plot_data['dc_leverage'].shift(1)
# Compute the HMM-DC-based strategy cumulative returns
plot_data['hmm_dc_stra_cum_rets'] = np.exp(plot_data['hmm_dc_stra_rets'].cumsum())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment