Skip to content

Instantly share code, notes, and snippets.

@netsatsawat
Created September 21, 2020 13:03
Show Gist options
  • Save netsatsawat/b86021e78e3442f122a86b6ceccdc07f to your computer and use it in GitHub Desktop.
Save netsatsawat/b86021e78e3442f122a86b6ceccdc07f to your computer and use it in GitHub Desktop.
Python script to map the hidden state to the GE price and plot
states = (pd.DataFrame(hidden_states, columns=['states'], index=train_df.index)
.join(train_df, how='inner')
.assign(mkt_cret=train_df.sret.cumsum())
.reset_index(drop=False)
.rename(columns={'index':'Date'}))
sns.set(font_scale=1.5)
sns.set_style('white', style_kwds)
order = np.arange(model.n_components)
fg = sns.FacetGrid(data=states, hue='states', hue_order=order,
palette=colors, aspect=1.31, height=12)
fg.map(plt.scatter, 'Date', mkt, alpha=0.8).add_legend()
sns.despine(offset=10)
fg.fig.suptitle(f'Historical {mkt} Regimes', fontsize=24, fontweight='demi')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment