library(readr)
data <- read_csv("C:/Users/51960/Downloads/Index2018.csv")
## Parsed with column specification:
## cols(
## date = col_character(),
## spx = col_double(),
## dax = col_double(),
## ftse = col_double(),
## nikkei = col_double()
## )
head(data)
## # A tibble: 6 x 5
## date spx dax ftse nikkei
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 07/01/1994 470. 2225. 3446. 18124.
## 2 10/01/1994 475. 2225 3441. 18443.
## 3 11/01/1994 474. 2228. 3414. 18485.
## 4 12/01/1994 474. 2182. 3372. 18794.
## 5 13/01/1994 472. 2142. 3360. 18577.
## 6 14/01/1994 475. 2151. 3401. 18974.
#solo especifico que lo queiro como Año-Mes-Dia
data$date<-format(as.Date(data$date,format = "%d/%m/%Y"),"%Y-%m-%d")
data$date<-as.Date(data$date,format = "%Y-%m-%d")
data_new <- data.frame(Fechas=data$date,FTSE=data$ftse)
head(data_new)
## Fechas FTSE
## 1 1994-01-07 3445.98
## 2 1994-01-10 3440.58
## 3 1994-01-11 3413.77
## 4 1994-01-12 3372.02
## 5 1994-01-13 3360.01
## 6 1994-01-14 3400.56
attach(data_new)
acf(FTSE)
pacf(FTSE)
pacf(FTSE)
## calculamos los retornos con la libreria “timeSeries”
library(timeSeries)
## Loading required package: timeDate
retornos<- returns(data_new$FTSE,method="discrete")
head(retornos)
## [,1]
## [1,] NA
## [2,] -0.001567043
## [3,] -0.007792291
## [4,] -0.012229881
## [5,] -0.003561663
## [6,] 0.012068416
Retornos= data.frame(Fechas=data_new$Fechas,Retornos=retornos)
Retornos=Retornos[-1,]
head(Retornos)
## Fechas Retornos
## 2 1994-01-10 -0.001567043
## 3 1994-01-11 -0.007792291
## 4 1994-01-12 -0.012229881
## 5 1994-01-13 -0.003561663
## 6 1994-01-14 0.012068416
## 7 1994-01-17 0.002137883
library(ggplot2)
library(hrbrthemes)
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
## Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
## if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
library(ggthemes)
ata= ggplot(Retornos,aes(Fechas,Retornos))+geom_line(color="#BF00FF")+labs(title = "RETORNOS",subtitle = "FTSE",caption = "Hecho por Sebastián Sosa Pérez")+
theme_ft_rc()
ata
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:timeSeries':
##
## filter
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
ggplotly(ata)
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
tsdisplay(Retornos$Retornos)
daffy=autoplot(Acf(Retornos$Retornos,lag.max = 40),col="#FF00FF",size=1)+labs(title = "ACF de retornos",caption = "Hecho por Sebastián Sosa Pérez")+theme_economist()
daffy
ggplotly(daffy)
### PACF
daffy=autoplot(Pacf(Retornos$Retornos,lag.max = 40),col="#2ECCFA",size=1)+labs(title = "PACF de retornos",caption = "Hecho por Sebastián Sosa Pérez")+theme_ft_rc()
daffy
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
ggplotly(daffy)
library(tseries)
AR_1= arma(Retornos$Retornos,order = c(1,0))
summary(AR_1)
##
## Call:
## arma(x = Retornos$Retornos, order = c(1, 0))
##
## Model:
## ARMA(1,0)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.889e-02 -5.310e-03 -3.024e-05 5.541e-03 9.778e-02
##
## Coefficient(s):
## Estimate Std. Error t value Pr(>|t|)
## ar1 -0.0171293 0.0126290 -1.356 0.175
## intercept 0.0001937 0.0001412 1.372 0.170
##
## Fit:
## sigma^2 estimated as 0.0001249, Conditional Sum-of-Squares = 0.78, AIC = -38545.42
plot(AR_1)
AR_3= arma(Retornos$Retornos,order = c(3,0))
summary(AR_3)
##
## Call:
## arma(x = Retornos$Retornos, order = c(3, 0))
##
## Model:
## ARMA(3,0)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.0913071 -0.0051968 0.0002461 0.0055609 0.0927998
##
## Coefficient(s):
## Estimate Std. Error t value Pr(>|t|)
## ar1 -0.0214857 0.0126013 -1.705 0.0882 .
## ar2 -0.0495730 0.0125885 -3.938 8.22e-05 ***
## ar3 -0.0669798 0.0126012 -5.315 1.06e-07 ***
## intercept 0.0002204 0.0001407 1.566 0.1173
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Fit:
## sigma^2 estimated as 0.000124, Conditional Sum-of-Squares = 0.78, AIC = -38584.02
plot(AR_3)
AR_4= arma(Retornos$Retornos,order = c(4,0))
summary(AR_4)
##
## Call:
## arma(x = Retornos$Retornos, order = c(4, 0))
##
## Model:
## ARMA(4,0)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.0888419 -0.0052396 0.0001993 0.0055609 0.0923756
##
## Coefficient(s):
## Estimate Std. Error t value Pr(>|t|)
## ar1 -0.0195092 0.0126250 -1.545 0.12228
## ar2 -0.0482138 0.0125986 -3.827 0.00013 ***
## ar3 -0.0662641 0.0125982 -5.260 1.44e-07 ***
## ar4 0.0301457 0.0126247 2.388 0.01695 *
## intercept 0.0002141 0.0001407 1.522 0.12806
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Fit:
## sigma^2 estimated as 0.0001239, Conditional Sum-of-Squares = 0.78, AIC = -38586.89
plot(AR_4)