library(ggplot2)
library(Quandl)
library(zoo)
library(quantmod)
library(TTR)
library(forecast)
library(ggfortify)
library(psych)
library(pastecs)
library(xts)
start <- as.Date("1990-01-01")
getSymbols(c(
'NYXRSA',
'BOXRSA',
'SDXRSA',
'CHXRSA',
'DNXRSA',
'LVXRSA',
'DAXRSA',
'WDXRSA',
'MIXRSA',
'ATXRSA',
'SFXRSA',
'LXXRSA',
'SEXRSA',
'CSUSHPISA'
), from=start, src='FRED')
names(NYXRSA)<-"New York"
names(BOXRSA)<-"Boston"
names(SDXRSA)<-"San Diego"
names(CHXRSA)<-"Chicago"
names(DNXRSA)<-"Denver"
names(LVXRSA)<-"Las Vegas"
names(WDXRSA)<-"DC"
names(MIXRSA)<-"Miami"
names(DAXRSA)<-"Dallas"
names(ATXRSA)<-"Atlanta"
names(SFXRSA)<-"San Francisco"
names(LXXRSA)<-"Los Angeles"
names(SEXRSA)<-"Seattle"
names(CSUSHPISA)<-"National"
Mortgage<-getSymbols('MORTGAGE30US', src='FRED')
Housing_Price=ATXRSA
Compare_Max=Housing_Price/max(Housing_Price)*100
Diff_Housing=Delt(Housing_Price,k=12)*100
Annual_Changes=annualReturn(Housing_Price)*100
par(mfrow=c(2,1))
plot(Diff_Housing)
plot(Annual_Changes)
summary(last(Annual_Changes,'7 years'))
describe(Annual_Changes)
par(mfrow=c(3,1))
plot(ATXRSA, main="ATLANTA")
plot(Delt(ATXRSA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(ATXRSA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
par(mfrow=c(3,1))
plot(BOXRSA, main="BOSTON")
plot(Delt(BOXRSA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(BOXRSA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
par(mfrow=c(3,1))
plot(CHXRSA, main="CHICAGO")
plot(Delt(CHXRSA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(CHXRSA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
par(mfrow=c(3,1))
plot(DAXRSA, main="DALLAS")
plot(Delt(DAXRSA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(DAXRSA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
par(mfrow=c(3,1))
plot(DNXRSA, main="DENVER")
plot(Delt(DNXRSA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(DNXRSA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
par(mfrow=c(3,1))
plot(LVXRSA, main="LAS VEGAS")
plot(Delt(LVXRSA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(LVXRSA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
par(mfrow=c(3,1))
plot(MIXRSA, main="MIAMI")
plot(Delt(MIXRSA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(MIXRSA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
par(mfrow=c(3,1))
plot(NYXRSA, main="NEW YORK")
plot(Delt(NYXRSA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(NYXRSA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
par(mfrow=c(3,1))
plot(SDXRSA, main="SAN DIEGO")
plot(Delt(SDXRSA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(SDXRSA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
par(mfrow=c(3,1))
plot(SEXRSA, main="SEATTLE")
plot(Delt(SEXRSA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(SEXRSA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
par(mfrow=c(3,1))
plot(SFXRSA, main="SAN FRANSICO")
plot(Delt(SFXRSA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(SFXRSA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
par(mfrow=c(3,1))
plot(WDXRSA, main="WASHINGTON DC")
plot(Delt(WDXRSA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(WDXRSA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
par(mfrow=c(3,1))
plot(CSUSHPISA, main="US NATIONAL")
plot(Delt(CSUSHPISA, k=12)*100, main="Percent changes from previous year ", col="red")
barplot(annualReturn(CSUSHPISA), main="Annual Changes ", col="blue", cex.names=0.8, las=2)
dev.off()
barplot(Annual_Changes, main=" Annual Changes ", col="blue", cex.names=0.8, las=2)
Monthly_Price<-monthlyReturn(Housing_Price)
Monthly_Rate<-MORTGAGE30US
Housing<-na.omit(merge(Monthly_Price,MORTGAGE30US))
head(Housing)
# Scatter chart for Price chagnes
scatter.smooth(last(Housing, "10 years"))
abline(lm(Housing$monthly.returns~Housing$MORTGAGE30US), col="blue")
# Regressiion Model
alli.mod1=lm(Combined$monthly.returns~Combined$MORTGAGE30US, data=Combined)
summary(alli.mod1)
autoplot(MORTGAGE30US)
y<-(Housing_Price)
library(ggfortify)
library(forecast)
autoplot(y)
d.arima<-auto.arima(y)
d.arima
d.forecast<-forecast(d.arima)
d.forecast
autoplot(forecast(d.arima, 36))
fit<-ets(y)
autoplot(stl(y, plot=FALSE))
ggtsdiag(auto.arima(y))
autoplot(forecast(fit,36))
Housing_Prices <- as.xts(data.frame(
NYXRSA,
BOXRSA,
SDXRSA,
CHXRSA,
DNXRSA,
LVXRSA,
WDXRSA,
MIXRSA,
LXXRSA,
SFXRSA
))
Housing_return = apply(Housing_Prices, 1, function(x) {x / Housing_Prices[1,]}) %>%
t %>% as.xts
head(Housing_return)
Summary_Stat<-summary(Housing_return)
cor(Housing_return)
write.table(Summary_Stat, "Summary.xls")
plot(as.zoo(Housing_return), screens = 1, lty = 1:10, xlab = "Date", ylab = "Home Price Index")
legend("topleft", c("New York", "Boston", "San Diego","Chicago",
"Denver", "Las Vegas","DC",
"Miami", "Los Angeles", "San Francisco"), lty = 1:10, cex = 0.5)
plot(Housing_return, xlab = "Date", ylab = "Index (1987=100)")
legend("right", c("New York", "Boston", "San Diego","Chicago",
"Denver", "Las Vegas","DC",
"Miami","Los Angeles","San Francisco"),
fill=c("blue","red","green","black","sky blue","purple","yellow",
"white", "black","red"
) )
ggplot(Housing_return, aes( x=))
tail(Housing_return)
No comments:
Post a Comment