library(quantmod)
## Loading required package: xts
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.5.2
##
## 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
symbols <- c("NVDA", "ORCL")
stocks <- getSymbols(
symbols,
src = "yahoo",
auto.assign = TRUE
)
head(NVDA)
## NVDA.Open NVDA.High NVDA.Low NVDA.Close NVDA.Volume NVDA.Adjusted
## 2007-01-03 0.617833 0.625333 0.579833 0.601333 1154820000 0.5513228
## 2007-01-04 0.599167 0.601333 0.583833 0.598500 797298000 0.5487252
## 2007-01-05 0.584333 0.586667 0.557000 0.561000 1243344000 0.5143443
## 2007-01-08 0.563000 0.576000 0.553333 0.565167 657270000 0.5181649
## 2007-01-09 0.566000 0.569833 0.553500 0.554167 764166000 0.5080793
## 2007-01-10 0.548333 0.586667 0.540000 0.581500 1108746000 0.5331393
head(ORCL)
## ORCL.Open ORCL.High ORCL.Low ORCL.Close ORCL.Volume ORCL.Adjusted
## 2007-01-03 17.22 17.78 17.10 17.51 52241700 13.99994
## 2007-01-04 17.55 17.87 17.30 17.68 33559800 14.13586
## 2007-01-05 17.62 17.76 17.44 17.64 36154800 14.10388
## 2007-01-08 17.63 17.93 17.45 17.86 31018100 14.27978
## 2007-01-09 17.93 17.98 17.65 17.82 31417000 14.24780
## 2007-01-10 17.66 17.80 17.55 17.77 27822400 14.20782
ORCL_df <- data.frame(
Date = index(ORCL),
coredata(ORCL)
)
write.csv(
ORCL_df,
"ORCL.csv",
row.names = FALSE
)
# write.csv(ORCL, "ORCL.csv")
write.zoo(ORCL, sep= ",", "ORCL.csv")
# Q5
getSymbols(c("NVDA", "ORCL"), src = "yahoo")
## [1] "NVDA" "ORCL"
getSymbols(c("NVDA", "ORCL"), src = "oanda")
## Warning in doTryCatch(return(expr), name, parentenv, handler): incorrectly
## specified currency pair NVDA
## Warning in doTryCatch(return(expr), name, parentenv, handler): incorrectly
## specified currency pair ORCL
## [1] "NVDA" "ORCL"
getSymbols(c("NVDA", "ORCL"), src = "csv")
## [1] "NVDA" "ORCL"
# Q6
getSymbols("MSFT", src="yahoo", from="2025-10-01", to="2026-01-31")
## [1] "MSFT"
# Q7
MSFT <- getSymbols(
"MSFT",
src = "yahoo",
from = "2025-10-01",
to = "2026-01-31",
auto.assign = FALSE
)
nrow(MSFT)
## [1] 84
# Q8
which.max(MSFT$MSFT.Open)
## [1] 20
index(MSFT)[which.max(MSFT$MSFT.Open)]
## [1] "2025-10-28"