Translate

Saturday, November 20, 2021

Analyzing Consumer Price Index (CPI) as of 10-01-2021

 


























library(Quandl)
library(ggplot2)
library(tseries);library(timeseries);library(xts);library(forecast)
library (quantmod)
library(psych)
library(plotly) #install.package(plotly)

#Food and Beverages (CPIFABSL)
#Housing (CPIHOSNS)
#Apparel (CPIAPPSL)
#Transportation (CPITRNSL)
#Medical Care (CPIMEDSL)
#Recreation (CPIRECSL)
#Education and Communication (CPIEDUSL)
# Other Goods and Services (CPIOGSSL)
#Commodities (CUSR0000SAC)
# Services (CUSR0000SAS)

start <- as.Date("1990-01-01")

getSymbols(c('CPIFABSL','CPIHOSNS','CPIAPPSL','CPITRNSL','CPIMEDSL','CPIRECSL',
             
             'CPIEDUSL','CPIOGSSL','CUSR0000SAC','CUSR0000SAS',"CPIAUCSL","CPILFESL"), from=start, src='FRED')

CPI<-merge (CPIFABSL,CPIHOSNS,CPIAPPSL,CPITRNSL,CPIMEDSL,CPIRECSL,
             
           CPIEDUSL,CPIOGSSL,CUSR0000SAC,CUSR0000SAS,CPIAUCSL,CPILFESL)

Diff_CPI <- (CPI/lag(CPI)-1)*100  
Diff_CPI[1,] <- 0


Diff_CPIAUCSL=Delt(CPIAUCSL,k=12)*100
Diff_CPIFESL=Delt(CPILFESL,k=12)*100

Diff_CPIFABSL=Delt(CPI$CPIFABSL,k=12)*100
Diff_CPIHOSNS=Delt(CPI$CPIHOSNS,k=12)*100
Diff_CPIAPPSL=Delt(CPI$CPIAPPSL,k=12)*100
Diff_CPITRNSL=Delt(CPI$CPITRNSL,k=12)*100
Diff_CPIMEDSL=Delt(CPI$CPIMEDSL,k=12)*100
Diff_CPIRECSL=Delt(CPI$CPIRECSL,k=12)*100
Diff_CPIEDUSL=Delt(CPI$CPIEDUSL,k=12)*100
Diff_CPIOGSSL=Delt(CPI$CPIOGSSL,k=12)*100
Diff_CUSR0000SAC=Delt(CPI$CUSR0000SAC,k=12)*100
Diff_CUSR0000SAS=Delt(CPI$CUSR0000SAS,k=12)*100

Diff_12<-merge(Diff_CPIFABSL, Diff_CPIHOSNS, Diff_CPIAPPSL, Diff_CPITRNSL, 
               Diff_CPIMEDSL, Diff_CPIRECSL, Diff_CPIEDUSL, Diff_CPIOGSSL,
               Diff_CUSR0000SAC, Diff_CUSR0000SAS)


Diff_12=window(Diff_12,start=as.Date("2001-01-01"), end=as.Date("2021-12-31"))

cor.distance <- cor(Diff_12)
corrplot::corrplot(cor.distance)

plot(Diff_CPIAPPSL)

plot(Diff_12)



plot(Diff_CPIAUCSL, main='Changes from previous year -CPI for All',las=2, subset='2000-01-01/')

plot(Diff_CPIFESL, main='Changes from previous year - Core CPI',las=2,subset='2000-01-01/')


plot(Diff_CPIFABSL, main='Changes from previous year -Food and Beverage',las=2, subset='2000-01-01/')

plot(Diff_CPIHOSNS, main='Changes from previous year -Housing',las=2,subset='2000-01-01/')


plot(Diff_CPIAPPSL, main='Changes from previous year -APPAREL', las=2,subset='2000-01-01/')

plot(Diff_CPITRNSL, main='Changes from previous year -Transportation',las=2,subset='2000-01-01/')


plot(Diff_CPIMEDSL, main='Changes from previous year -Medical Care',las=2,subset='2000-01-01/')


plot(Diff_CPIRECSL, main='Changes from previous year -Recreation',las=2,subset='2000-01-01/')


plot(Diff_CPIEDUSL, main='Changes from previous year -Education and Communication',las=2,subset='2000-01-01/')


plot(Diff_CPIOGSSL, main='Changes from previous year -Other Goods and Services',las=2,subset='2000-01-01/')

plot(Diff_CUSR0000SAC, main='Changes from previous year -Commodities',las=2,subset='2000-01-01/')


plot(Diff_CUSR0000SAS, main='Changes from previous year -Services',las=2,subset='2000-01-01/')






plot(Diff_CPIFABSL)

hist(Diff_CPIFABSL,col='blue')

CPI_2021=window(Diff_CPI,start=as.Date("2021-01-01"), end=as.Date("2021-12-31"))
tail(CPI_2018)

CPI_2021


barplot(CPI_2021$CPIFABSL,las=2)


No comments:

Post a Comment