library("lubridate") #
library("readxl")
library("zoo") #
library("xts") #
library("dplyr") #
library("ggplot2") #
library("gridExtra") # Multiplot
library("forecast")
library("tseries") #для Arima
library("TTR") # SMA
library("fUnitRoots") #tests for stationarity
library("xlsx")
library("RODBC") # xls Excel <- odbcConnectExcel
library("Quandl")
library("highcharter")
library("quantmod")
library("XLConnect")
library("xlsx")
library("js") #Tools for Working with JavaScript in R
# load data
tmpgdplev = tempfile(fileext = ".xlsx")
download.file(url = "https://www.bea.gov/national/xls/gdplev.xlsx", destfile = tmpgdplev, mode="wb")
mydatagdplev<-read.xlsx(tmpgdplev, 1, startRow = 6)
RealGDPQ<-ts(removeNA(mydatagdplev[1:nrow(mydatagdplev),6]), frequency=4, start=c(1947,1))
prirost<-function(x)
{
d<-diff(x)
res<-NULL
for(i in 1:length(d))
{res<-append(res, d[i]/x[i])}
return(res)
}
dRGDP<-prirost(RealGDP)
dRGDPQ<-prirost(RealGDPQ)
round(dRGDP,4)
round(dRGDPQ*100,2)
prirostQ<-function(x)
{
d<-diff(x,lag = 4)
res<-NULL
for(i in 1:length(d))
{res<-append(res, d[i]/x[i])}
return(res)
}
dRGDPQ2<-prirostQ(RealGDPQ)
round(dRGDPQ2*100,2)
dQRGDPQ<-(dRGDPQ+1)^4-1
round(dQRGDPQ*100,2)
k<-NULL
for(i in 1:NROW(removeNA(mydatagdplev[ ,1])))
{k<-append(k, as.character(mydatagdplev[i,1]))}
dpc<-years(k)
n<-NA
n1<-c(NA,NA,NA,NA)
QRealGDPtable<-data.frame(Qdate, RealGDPQ, round(append(n,dRGDPQ)*100,2 ), round(append( n1,dRGDPQ2)*100,2 ), round(append(n,dQRGDPQ)*100,2 ))
colnames(QRealGDPtable)<-c("date", "QRealGDP", "Growth","QQGrowth", "annualGrowthRate")
Qdate<-as.yearqtr(1947 + seq(0, nrow(mydatagdplev)-1)/4)
#### This my working time siries
QQRGDPts<-ts(QRealGDPtable$QQGrowth, start=c(1947,1), frequency=4)
QQRGDP <- highchart(type = "stock") %>%
hc_title(text = "Q U.S. GDP ") %>%
hc_subtitle(text = "Source: U.S. Bureau of Economic Analysis", align = "left") %>%
hc_add_series(QQRGDPts, type="column")
QQRGDP