if (!requireNamespace("quantmod", quietly = TRUE)) {
install.packages("quantmod")
}
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
# Load the package
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
# Now, getSymbols() will work
getSymbols("MSFT", from = "2024-10-01", to = "2025-01-31")
## [1] "MSFT"
getSymbols("MSFT", src = "yahoo", from = "2024-10-01", to = "2025-01-31")
## [1] "MSFT"
library(quantmod)
getSymbols("MSFT", src = "yahoo", from = "2024-10-01", to = "2025-01-31")
## [1] "MSFT"
# Count rows
nrow(MSFT)
## [1] 83
# Check last date included
tail(index(MSFT))
## [1] "2025-01-23" "2025-01-24" "2025-01-27" "2025-01-28" "2025-01-29"
## [6] "2025-01-30"
getSymbols("MSFT", src="yahoo",from = "2024-10-01", to = "2025-02-01")
## [1] "MSFT"
nrow(MSFT)
## [1] 84
nrow(MSFT)
## [1] 84
which.max(Op(MSFT)) # index of highest Open price
## [1] 56
index(MSFT)[which.max(Op(MSFT))] # actual date
## [1] "2024-12-18"
data(mtcars)
head(mtcars)
aggregate(mpg ~ cyl, data = mtcars, FUN = mean)
plot(mtcars\(hp, mtcars\)mpg, main = “Horsepower vs. MPG”, xlab = “Horsepower”, ylab = “Miles per Gallon”, col = mtcars\(cyl, pch = 19) legend("topright", legend = unique(mtcars\)cyl), col = unique(mtcars$cyl), pch = 19, title = “Cylinders”)
# Extract the Open prices
msft_open_prices <- Op(MSFT)
# Find the highest Open price
highest_open_price <- max(msft_open_prices)
# Find the date of the highest Open price
date_of_highest_open <- index(msft_open_prices[which.max(msft_open_prices)])
# Print the results
print(paste("The highest Open price is:", highest_open_price))
## [1] "The highest Open price is: 451.320007324219"
print(paste("The date of the highest Open price is:", date_of_highest_open))
## [1] "The date of the highest Open price is: 2024-12-18"