Instalacion
install.packages("quantmod")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
Ejecucucion de libreria
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-10 189.259995 189.990005 187.039993 188.610001 59922200
## 2023-07-11 189.160004 189.300003 186.600006 188.080002 46638100
## 2023-07-12 189.679993 191.699997 188.470001 189.770004 60750200
## 2023-07-13 190.500000 191.190002 189.779999 190.539993 41342300
## 2023-07-14 190.229996 191.179993 189.630005 190.690002 41573900
## 2023-07-17 191.899994 194.320007 191.809998 193.990005 50520200
## 2023-07-18 193.350006 194.330002 192.419998 193.729996 48353800
## 2023-07-19 193.100006 198.229996 192.649994 195.100006 80507300
## 2023-07-20 195.089996 196.470001 192.500000 193.130005 59581200
## 2023-07-21 194.100006 194.970001 191.229996 191.940002 71917800
## 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-10 188.610001
## 2023-07-11 188.080002
## 2023-07-12 189.770004
## 2023-07-13 190.539993
## 2023-07-14 190.690002
## 2023-07-17 193.990005
## 2023-07-18 193.729996
## 2023-07-19 195.100006
## 2023-07-20 193.130005
## 2023-07-21 191.940002
Grafica
chartSeries(apple_df, name="AAPL", subset="last 6 months", theme=chartTheme("white"))

msft_df <- getSymbols("MSFT", src='yahoo', auto.assign=FALSE)
msft_df
## MSFT.Open MSFT.High MSFT.Low MSFT.Close MSFT.Volume MSFT.Adjusted
## 2007-01-03 29.91 30.25 29.40 29.86 76935100 21.52598
## 2007-01-04 29.70 29.97 29.44 29.81 45774500 21.48994
## 2007-01-05 29.63 29.75 29.45 29.64 44607200 21.36738
## 2007-01-08 29.65 30.10 29.53 29.93 50220200 21.57644
## 2007-01-09 30.00 30.18 29.73 29.96 44636600 21.59807
## 2007-01-10 29.80 29.89 29.43 29.66 55017400 21.38180
## 2007-01-11 29.76 30.75 29.65 30.70 99464300 22.13153
## 2007-01-12 30.65 31.39 30.64 31.21 103972500 22.49919
## 2007-01-16 31.26 31.45 31.03 31.16 62379600 22.46315
## 2007-01-17 31.26 31.44 31.01 31.10 58519600 22.41990
## ...
## 2023-07-10 334.60 335.23 327.59 331.83 32791400 331.82999
## 2023-07-11 331.06 332.86 327.00 332.47 26698200 332.47000
## 2023-07-12 336.60 341.65 335.67 337.20 29995300 337.20001
## 2023-07-13 339.56 343.74 339.02 342.66 20567200 342.66000
## 2023-07-14 347.59 351.43 344.31 345.24 28302200 345.23999
## 2023-07-17 345.68 346.99 342.20 345.73 20363900 345.73001
## 2023-07-18 345.83 366.78 342.17 359.49 64872700 359.48999
## 2023-07-19 361.75 362.46 352.44 355.08 39732900 355.07999
## 2023-07-20 353.57 357.97 345.37 346.87 33778400 346.87000
## 2023-07-21 349.15 350.30 339.83 343.77 69368900 343.76999
Grafica Microsoft
chartSeries(msft_df, name="MSFT", subset="last 6 months", theme=chartTheme("white"))
