Instalación

install.packages("quantmod")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)

Ejecución de la librería

library(quantmod)
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo

Scraping a Apple

apple_df <- getSymbols('AAPL', src='yahoo', auto.assign=FALSE)
apple_df
##             AAPL.Open  AAPL.High   AAPL.Low AAPL.Close AAPL.Volume
## 2007-01-03   3.081786   3.092143   2.925000   2.992857  1238319600
## 2007-01-04   3.001786   3.069643   2.993571   3.059286   847260400
## 2007-01-05   3.063214   3.078571   3.014286   3.037500   834741600
## 2007-01-08   3.070000   3.090357   3.045714   3.052500   797106800
## 2007-01-09   3.087500   3.320714   3.041071   3.306071  3349298400
## 2007-01-10   3.383929   3.492857   3.337500   3.464286  2952880000
## 2007-01-11   3.426429   3.456429   3.396429   3.421429  1440252800
## 2007-01-12   3.378214   3.395000   3.329643   3.379286  1312690400
## 2007-01-16   3.417143   3.473214   3.408929   3.467857  1244076400
## 2007-01-17   3.484286   3.485714   3.386429   3.391071  1646260000
##        ...                                                        
## 2023-07-28 194.669998 196.630005 194.139999 195.830002    48291400
## 2023-07-31 196.059998 196.490005 195.259995 196.449997    38824100
## 2023-08-01 196.240005 196.729996 195.279999 195.610001    35175100
## 2023-08-02 195.039993 195.179993 191.850006 192.580002    50389300
## 2023-08-03 191.570007 192.369995 190.690002 191.169998    61235200
## 2023-08-04 185.520004 187.380005 181.919998 181.990005   115799700
## 2023-08-07 182.130005 183.130005 177.350006 178.850006    97576100
## 2023-08-08 179.690002 180.270004 177.580002 179.800003    67823000
## 2023-08-09 180.869995 180.929993 177.009995 178.190002    60378500
## 2023-08-10 179.479996 180.750000 177.600006 177.970001    54628800
##            AAPL.Adjusted
## 2007-01-03      2.543757
## 2007-01-04      2.600217
## 2007-01-05      2.581701
## 2007-01-08      2.594450
## 2007-01-09      2.809972
## 2007-01-10      2.944445
## 2007-01-11      2.908019
## 2007-01-12      2.872200
## 2007-01-16      2.947479
## 2007-01-17      2.882216
##        ...              
## 2023-07-28    195.830002
## 2023-07-31    196.449997
## 2023-08-01    195.610001
## 2023-08-02    192.580002
## 2023-08-03    191.169998
## 2023-08-04    181.990005
## 2023-08-07    178.850006
## 2023-08-08    179.800003
## 2023-08-09    178.190002
## 2023-08-10    177.970001

Gráfica

chartSeries(apple_df, name="AAPL", subset="last 6 months", theme=chartTheme("white"))

La tendencia de esta grafica es muy volatil ya que sus velitas suben y bajan

Scraping a Tesla

apple_df <- getSymbols('TSLA', src='yahoo', auto.assign=FALSE)
apple_df
##             TSLA.Open  TSLA.High   TSLA.Low TSLA.Close TSLA.Volume
## 2010-06-29   1.266667   1.666667   1.169333   1.592667   281494500
## 2010-06-30   1.719333   2.028000   1.553333   1.588667   257806500
## 2010-07-01   1.666667   1.728000   1.351333   1.464000   123282000
## 2010-07-02   1.533333   1.540000   1.247333   1.280000    77097000
## 2010-07-06   1.333333   1.333333   1.055333   1.074000   103003500
## 2010-07-07   1.093333   1.108667   0.998667   1.053333   103825500
## 2010-07-08   1.076000   1.168000   1.038000   1.164000   115671000
## 2010-07-09   1.172000   1.193333   1.103333   1.160000    60759000
## 2010-07-12   1.196667   1.204667   1.133333   1.136667    33037500
## 2010-07-13   1.159333   1.242667   1.126667   1.209333    40201500
##        ...                                                        
## 2023-07-28 259.859985 267.250000 258.230011 266.440002   111446000
## 2023-07-31 267.480011 269.079987 263.779999 267.429993    84582200
## 2023-08-01 266.260010 266.470001 260.250000 261.070007    83166000
## 2023-08-02 255.570007 259.519989 250.490005 254.110001   101752900
## 2023-08-03 252.039993 260.489990 252.000000 259.320007    97569100
## 2023-08-04 260.970001 264.769989 253.110001 253.860001    99242600
## 2023-08-07 251.449997 253.649994 242.759995 251.449997   111097900
## 2023-08-08 247.449997 250.919998 245.009995 249.699997    96642200
## 2023-08-09 250.869995 251.100006 241.899994 242.190002   101596300
## 2023-08-10 245.399994 251.800003 243.000000 245.339996   109336100
##            TSLA.Adjusted
## 2010-06-29      1.592667
## 2010-06-30      1.588667
## 2010-07-01      1.464000
## 2010-07-02      1.280000
## 2010-07-06      1.074000
## 2010-07-07      1.053333
## 2010-07-08      1.164000
## 2010-07-09      1.160000
## 2010-07-12      1.136667
## 2010-07-13      1.209333
##        ...              
## 2023-07-28    266.440002
## 2023-07-31    267.429993
## 2023-08-01    261.070007
## 2023-08-02    254.110001
## 2023-08-03    259.320007
## 2023-08-04    253.860001
## 2023-08-07    251.449997
## 2023-08-08    249.699997
## 2023-08-09    242.190002
## 2023-08-10    245.339996

Grafica

chartSeries(apple_df, name="TSLA", subset="last 6 months", theme=chartTheme("white"))

La tendecia de esta grafica esta llegando a su punto maximo que en algun momento su tendencia puede bajar mas