<jupyter_start><jupyter_text>These seem to be leading indicators of Headline CPI<jupyter_code>con_mach_eq_roc = roc(con_mach_eq, 12)
print("Max:", con_mach_eq_roc.max())
con_mach_eq_roc.tail(1)
chemicalManuf_roc = roc(chemical_man, 12)
print("Max:", chemicalManuf_roc.max())
chemicalManuf_roc.tail(1)
crude_roc = roc(crude, 12)
print("Max:", crude_roc['WTIcrude'].max())
crude_roc.tail(1)
ironSteel_roc = roc(iron_steel, 12)
print("Max:", ironSteel_roc.max())
ironSteel_roc.tail(1)
sil_gold_roc = roc(sil_goldRatio, 12)
print("Max:", sil_gold_roc['Sil_GoldRatio'].max())
sil_gold_roc.drop(['SilverVolm', 'GoldVolm', 'DiffSilGold_Volm'], axis=1, inplace=True)
sil_gold_roc.tail(1)
# copperProd_roc = roc(copperProducts, 12)
# print("Max:", copperProd_roc.max())
# copperProd_roc.tail(15)

inflation_roc = pd.merge(DXY_roc, US10yr_roc, left_index=True, right_index=True)
inflation_roc= pd.merge(inflation_roc, CRB_roc, left_index=True, right_index=True)
inflation_roc = pd.merge(inflation_roc, sil_gold_roc, left_index=True, right_index=True)

# inflation_roc['baseEffect_roc'] = inflation_roc['CPI_Headline'].shift(24)

inflation_roc = pd.merge(inflation_roc, crude_roc, left_index=True, right_index=True)
inflation_roc = pd.merge(inflation_roc, lumber_roc, left_index=True, right_index=True)
inflation_roc = pd.merge(inflation_roc, nat_gas_roc, left_index=True, right_index=True)
# inflation_roc = pd.merge(inflation_roc, crude_roc, left_index=True, right_index=True)
inflation_roc = pd.merge(inflation_roc, corn_roc, left_index=True, right_index=True)
inflation_roc = pd.merge(inflation_roc, wheat_roc, left_index=True, right_index=True)
inflation_roc = pd.merge(inflation_roc, soy_roc, left_index=True, right_index=True)
inflation_roc = pd.merge(inflation_roc, sugar_roc, left_index=True, right_index=True)
inflation_roc = pd.merge(inflation_roc, coffee_roc, left_index=True, right_index=True)
inflation_roc = pd.merge(inflation_roc, copper_roc, left_index=True, right_index=True)

# inflation_roc = pd.merge(inflation_roc, PCE_roc, left_index=True, right_index=True)
# inflation_roc = pd.merge(inflation_roc, ironSteel_roc, left_index=True, right_index=True)
# inflation_roc = pd.merge(inflation_roc, chemicalManuf_roc, left_index=True, right_index=True)
# inflation_roc = pd.merge(inflation_roc, copperProd_roc, left_index=True, right_index=True)
# inflation_roc = pd.merge(inflation_roc, con_mach_eq_roc, left_index=True, right_index=True)
inflation_roc.drop(["CrudeVolm", "LumberVolm", "NatGasVolm", "SugarVolm", "CoffeeVolm", "CopperVolm"], axis=1, inplace=True)
print(inflation_roc.shape)
inflation_roc.tail(5)
inflation_roc.corr()
# Merging Inflation 'Possible' Factors - Commodities

inflation_factors = pd.merge(DXY, US10yr, left_index=True,right_index=True)
inflation_factors = pd.merge(inflation_factors, CRB, left_index=True, right_index=True)
inflation_factors = pd.merge(inflation_factors, sil_goldRatio, left_index=True, right_index=True)
inflation_factors.drop(['SilverVolm', 'GoldVolm', 'DiffSilGold_Volm'], axis=1, inplace=True)

# inflation_factors['baseEffect'] = inflation_factors['CPI_Headline'].shift(24)
# inflation_factors['baseEffect_2yr'] = (inflation_factors['CPI_Headline'] - inflation_factors['baseEffect']) / inflation_factors['baseEffect'] * 100
# inflation_factors.drop(['baseEffect'], axis=1, inplace=True)

# inflation_factors['Inflation_yoy%'] = percentChg(inflation_factors['CPI_Headline'], 12)
# inflation_factors.drop(['CPI_Headline'], axis=1, inplace=True)

inflation_factors = pd.merge(inflation_factors, copper, left_index=True, right_index=True)
inflation_factors = pd.merge(inflation_factors, lumber, left_index=True, right_index=True)
inflation_factors = pd.merge(inflation_factors, nat_gas, left_index=True, right_index=True)
inflation_factors = pd.merge(inflation_factors, crude, left_index=True, right_index=True)
inflation_factors = pd.merge(inflation_factors, corn, left_index=True, right_index=True)
inflation_factors = pd.merge(inflation_factors, wheat, left_index=True, right_index=True)
inflation_factors = pd.merge(inflation_factors, soy, left_index=True, right_index=True)
inflation_factors = pd.merge(inflation_factors, sugar, left_index=True, right_index=True)
inflation_factors = pd.merge(inflation_factors, coffee, left_index=True, right_index=True)

inflation_factors.drop(["CrudeVolm", "LumberVolm", "NatGasVolm", "SugarVolm", "CoffeeVolm", "CopperVolm"], axis=1, inplace=True)


# inflation_factors = pd.merge(inflation_factors, PCE, left_index=True, right_index=True)

print(inflation_factors.shape)
inflation_factors.tail(15)
inflation_factors.corr()
inflation_factors.columns
inflation_factors.to_csv('inflation_factors.csv')
inflation_roc.to_csv('inflation_roc.csv')
data = inflation_factors.copy()
data.head()
CPI_Headline['CPI_yoy%'] = percentChg(CPI_Headline, 12)
data = pd.merge(CPI_Headline, data, left_index=True, right_index=True)
data.head()
CPI = data[['CPI_Headline']]
CPI.head()
def roc(df, n):
    """Calulates the First Difference of the 2nd Derivative (Rate of Change/Acceleration)"""    
    df1 = df.copy()
    df1 = (np.log(df1).diff(n))
    df1 = df1 - (df1.shift(1))
    df1 = df1 * 100
    return df1

def ROC(df, n):
    """Calulates the 2nd Derivative (Rate of Change/Acceleration)"""    
    df1 = df.copy()
    df1 = np.log(df1 / df1.shift(n))
    df1 = df1 * 100
    return df1
# CPI_Headline['CPI_Headline'].diff(12).tail(13)

# data.head()
CPI_Headline = pdr.DataReader('CPIAUCSL', data_source, start, end)
CPI_Headline.index.names = ['Date']
CPI_Headline.columns = ['CPI_Headline']
CPI_Headline.dropna(inplace=True)
CPI_Headline['CPI_yoy%'] = percentChg(CPI_Headline, 12)
CPI_Headline.tail(13)
# CPI_Headline['CPI_yoy_roc'] = ROC(CPI_Headline['CPI_Headline'], 12)
CPI_Headline['CPI_yoyFirstDiffroc'] = roc(CPI_Headline['CPI_Headline'], 12)
# CPI_Headline['mean_yoy2'] = CPI_Headline['CPI_yoy%'].rolling(2).mean()
CPI_Headline.tail(40)
plt.style.use('fivethirtyeight')
fig, ax = plt.subplots(figsize=(30,10))  # chart 3:1

ax.set_title("CPI", 
             fontsize=22, fontweight='bold', x=.242, y=1.07)
# plt.plot(CPI_Headline.index, CPI_Headline['mean_yoy2'], color='red', linewidth=1)
plt.plot(CPI_Headline.index, CPI_Headline['CPI_yoy%'], color='black', linewidth=1)
plt.plot(CPI_Headline.index, CPI_Headline['CPI_yoyFirstDiffroc'], color='green', linewidth=3)
# plt.plot(vix['Close'].rolling(90).mean(), color='r', linewidth=1)

# Turn off the spines
ax.spines['left'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_visible(False)

plt.show()<jupyter_output><empty_output><jupyter_text>Variational Inference: Bayesian Neural Network  Factor Analysis<jupyter_code># CRB_d = investpy.indices.get_index_historical_data('TR/CC CRB', 
#                                                  from_date = '01/01/1980', 
#                                                  to_date = '01/01/2030', 
#                                                  country='world', 
#                                                  order='ascending', 
#                                                  interval='weekly')
# CRB_d.tail(20)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13824181919023848, 'fraction_numerical': 0.017193566278424846, 'mean_word_length': 6.552879581151832, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '235297', 'license': 'MIT', 'n_tokens_mistral': 2795, 'n_tokens_neox': 2640, 'n_words': 394, 'path': 'notebooks/inflation.ipynb', 'repo_name': 'drewamorbordelon/measuring_mapping_macro', 'size': '7212'}