import pandas as pd
import quantecon as qe
import warnings
'ignore') warnings.filterwarnings(
= "../data/stochastic_matrix_coffee_price-regime-R-8.csv"
fp = pd.read_csv(fp, usecols = ["L", "M", "H"])
df = ["L", "M", "H"]
col_order = df[col_order] df
= df.values
sm sm
from quantecon import MarkovChain
= qe.MarkovChain(sm, ("L", "M", "H")) mc
mc.is_irreducible
mc.communication_classes
mc.is_aperiodic
mc.stationary_distributions
import plotly.express as px
= px.imshow(sm, text_auto=True, labels=dict(x="Previous Month Price", y="Current Month Price"),
fig =['Low', 'Medium', 'High'],
x=['Low', 'Medium', 'High'])
y
fig.update_layout(={
title'text': "Stochastic Matrix for Region 8",
'y':.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'})
fig.show()
= mc.stationary_distributions.flatten().tolist()
d = {"Low": d[0], "Medium": d[1], "High": d[2]}
stationary_dist = pd.DataFrame.from_dict(stationary_dist, orient='index').round(3)
dfp = dfp.reset_index()
dfp = ["Price", "Probability"]
dfp.columns dfp