require(ggplot2)
## Loading required package: ggplot2
require(plotly)
## Loading required package: plotly
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
require(forecast)
## Loading required package: forecast
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
require(tseries)
## Loading required package: tseries
library(readr)
require(fGarch)
## Loading required package: fGarch
## Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
## logical.return = TRUE, : there is no package called 'fGarch'
con=url("https://finance.yahoo.com")
twitter= get.hist.quote(instrument = "TWTR", start = "2014-01-01",quote="Close",compression = "m")
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
##
## This message is shown once per session and may be disabled by setting
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
## time series ends 2020-10-01
plot(twitter)
fb= get.hist.quote(instrument = "FB", start = "2014-01-01",quote="Close",compression = "m")
## time series ends 2020-10-01
plot(fb)
twitte.n=as.numeric(twitter)
fb.n=as.numeric(fb)
length(twitter)
## [1] 82
length(fb)
## [1] 82
fecha=seq(as.Date("2014-01-01"), as.Date("2020-10-01"), by="months")
length(fecha)
## [1] 82
DF <- data.frame(fecha, fb.n, twitte.n )
fecha2=rep(fecha,2)
precios=c( fb.n, twitte.n)
empresa=c(rep("Twitter",length(twitte.n)),rep("Facebook",length(fb.n)))
DF2=data.frame(fecha2,precios,empresa)
graf1 <- ggplot(DF2,aes(x=fecha2,y=precios,col=empresa))+geom_line()+
theme_bw()+ labs(y="Valor", x = "A昼㸱os") +
theme(axis.title.x = element_text(face="bold", vjust=-0.5, colour="black", size=rel(1))) +
theme(axis.title.y = element_text(face="bold", vjust=1.5, colour="black", size=rel(1))) +
ggtitle ("cotizacion en dolares")
print(graf1)
se peude apreciar como las acciones de twitter tienen un timido crecimiento mientras las media de las serie de las acciones de facebook ha vendio aumentando conciderablemente en los ultimos periodos. el diagnostico de esto es que es mas rentable invertir en acciones de facebook que de twitter.