Translate

Sunday, August 29, 2021

Analyzing REITs - Self Storage as of 8/26/2021

 




require(IKTrading)
require(quantmod)
require(PerformanceAnalytics)

options("getSymbols.warning4.0"=FALSE)

symbols <- c("NSA", #National Storage
             "EXR",  #Extra Space Storage
             "PSA", # Public Storage
             "SELF", #Global Self Storage 
             "CUBE",  #Cube Smart
             "LSI"  #Life Storage
             
             
             
             
             
)

from="2003-01-01"

#Home ETFs first, iShares ETFs afterwards
if(!"XLB" %in% ls()) {
  suppressMessages(getSymbols(symbols, from="2003-01-01", src="yahoo", adjust=TRUE))
}

Self <- list()
for(i in 1:length(symbols)) {
  Self[[i]] <- Cl(get(symbols[i]))
}
Self <- do.call(cbind, Self)
colnames(Self) <- gsub("\\.[A-z]*", "", colnames(Self))

cor(Self)

Storage<-Self/lag(Self)-1  
Storage[1,] <- 0

write.table(Storage, file='Storage.xls')
tail(Storage)



Home_2020=window(Storage,start=as.Date("2020-01-01"), end=as.Date("2020-12-31"))


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


charts.PerformanceSummary(Home_2021,main='Self Storage REITs Sectors',wealth.index = TRUE)

#calculate the Sharpe ratio
# Sharpe ratio = ((Expected_Return - Risk Free Return) / SD)

Home_Returns<-table.AnnualizedReturns(Home_2021, scale=252, Rf=0.005/252)

Home_Returns

Cumm_Returns=Return.cumulative(Home_2021)*100

Cumm_Returns

chart.CumReturns(Home_2021, main='Home for 2021',  begin=c("first", "axis"))

barplot(Cumm_Returns, main='Cummulative Returns for Self REITs')

barplot(Cumm_Returns)

write.csv(Home_Returns, file='return.xls')

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

write.table(cor.distance, file='correlation matrix.xls')



library(igraph)
g1 <- graph.adjacency(cor.distance, weighted = T, mode = "undirected", add.colnames = "label")
mst <- minimum.spanning.tree(g1)
plot(mst)

library(visNetwork)

mst_df <- get.data.frame( mst, what = "both" )
visNetwork( 
  data.frame(
    id = 1:nrow(mst_df$vertices) 
    ,label = mst_df$vertices
  )
  , mst_df$edges
) %>%
  visOptions( highlightNearest = TRUE)



Monday, August 2, 2021

Industrial Production as of 06/2021

 


Industrial Production as of 06/2021












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

#Industrial Production (INDPRO)
#Industrial Production: Consumer Goods (IPCONGD)
#Industrial Production: Durable Consumer Goods (IPDCONGD)
#Industrial Production: Non-Durable Consumer Goods (IPNCONGD)
#Industrial Production: Equipment: Business Equipment (IPBUSEQ)
#Industrial Production: Materials (IPMAT)
#Industrial Production: Manufacturing (SIC) (IPMANSICS)
#Industrial Production: Durable Manufacturing (NAICS) (IPDMAN)
#Industrial Production: Non-Durable Manufacturing (NAICS) (IPNMAN)



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

getSymbols(c('INDPRO','IPCONGD','IPDCONGD','IPNCONGD','IPBUSEQ','IPMAT',
             'IPMANSICS','IPDMAN','IPNMAN'
             
             ), from=start, src='FRED')

IND<-merge (INDPRO,IPCONGD,IPDCONGD,IPNCONGD,IPBUSEQ,IPMAT,
            IPMANSICS,IPDMAN,IPNMAN)
            
Diff_IND <- (IND/lag(IND)-1)*100  
Diff_IND[1,] <- 0


Diff_INDPRO=Delt(INDPRO,k=12)*100


plot(Diff_INDPRO, main='Changes from previous year - Industrial Production',las=2, subset='2000-01-01/')


Diff_IPCONGD=Delt(IPCONGD,k=12)*100

plot(Diff_IPCONGD, main='Changes from previous year - Industrial Production: Consumer Goods (IPCONGD)',las=2, subset='2000-01-01/')


Diff_IPDCONGD=Delt(IPDCONGD,k=12)*100

plot(Diff_IPDCONGD, main='Changes from previous year - Industrial Production: Durable Consumer Goods (IPDCONGD)',las=2, subset='2000-01-01/')

Diff_IPNcONGD=Delt(IPNCONGD,k=12)*100


plot(Diff_IPNCONGD, main='Changes from previous year - Industrial Production: Non-Durable Consumer Goods',las=2, subset='2000-01-01/')

Diff_IPBUSEQ=Delt(IPBUSEQ,k=12)*100

plot(Diff_IPBUSEQ, main='Changes from previous year - Industrial Production: Equipment: Business Equipment (IPBUSEQ)',las=2, subset='2000-01-01/')

Diff_IPMAT=Delt(IPMAT,k=12)*100


plot(Diff_IPMAT, main='Changes from previous year - Industrial Production: Materials (IPMAT)',las=2, subset='2000-01-01/')


Diff_IPMANSICS=Delt(IPMANSICS,k=12)*100

plot(Diff_IPMANSICS, main='Changes from previous year - Industrial Production: Manufacturing (SIC) (IPMANSICS)',las=2, subset='2000-01-01/')

Diff_IPDMAN=Delt(IPDMAN,k=12)*100

plot(Diff_IPDMAN, main='Changes from previous year - Industrial Production: Durable Manufacturing (NAICS) (IPDMAN)',las=2, subset='2000-01-01/')


Diff_IPNMAN=Delt(IPNMAN,k=12)*100

plot(Diff_IPNMAN, main='Changes from previous year -Industrial Production: Non-Durable Manufacturing (NAICS) (IPNMAN)',las=2, subset='2000-01-01/')