Install Dplyr
#install.packages("pak")
pak::pak("tidyverse/dplyr")
## ! Using bundled GitHub PAT. Please add your own PAT using `gitcreds::gitcreds_set()`.
## ℹ Loading metadata database✔ Loading metadata database ... done
##
## ℹ No downloads are needed
## ✔ 1 pkg + 14 deps: kept 12 [5.9s]
Getting Quantmod
library(quantmod)
## Loading required package: xts
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.4.3
##
## 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
Question 5, testing if you can use multiple sources for multiple
stocks, using Tesla and Nvidia and Yahoo and Oanda as sources
getSymbols(c("TSLA", "NVDA"), src="yahoo")
## [1] "TSLA" "NVDA"
getSymbols(c("TSLA", "NVDA"), src="oanda")
## Warning in doTryCatch(return(expr), name, parentenv, handler): incorrectly
## specified currency pair TSLA
## Warning in doTryCatch(return(expr), name, parentenv, handler): incorrectly
## specified currency pair NVDA
## [1] "TSLA" "NVDA"
head(TSLA)
## TSLA.Open TSLA.High TSLA.Low TSLA.Close TSLA.Volume TSLA.Adjusted
## 2010-06-29 1.266667 1.666667 1.169333 1.592667 281494500 1.592667
## 2010-06-30 1.719333 2.028000 1.553333 1.588667 257806500 1.588667
## 2010-07-01 1.666667 1.728000 1.351333 1.464000 123282000 1.464000
## 2010-07-02 1.533333 1.540000 1.247333 1.280000 77097000 1.280000
## 2010-07-06 1.333333 1.333333 1.055333 1.074000 103003500 1.074000
## 2010-07-07 1.093333 1.108667 0.998667 1.053333 103825500 1.053333
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.5513226
## 2007-01-04 0.599167 0.601333 0.583833 0.598500 797298000 0.5487257
## 2007-01-05 0.584333 0.586667 0.557000 0.561000 1243344000 0.5143440
## 2007-01-08 0.563000 0.576000 0.553333 0.565167 657270000 0.5181646
## 2007-01-09 0.566000 0.569833 0.553500 0.554167 764166000 0.5080792
## 2007-01-10 0.548333 0.586667 0.540000 0.581500 1108746000 0.5331393
Question 6 Getting data from Microsoft stock over a set period of
time
getSymbols("MSFT", src="yahoo", from = "2025-10-01", to = "2026-01-31")
## [1] "MSFT"
head(MSFT)
## MSFT.Open MSFT.High MSFT.Low MSFT.Close MSFT.Volume MSFT.Adjusted
## 2025-10-01 514.80 520.51 511.69 519.71 22632300 518.7391
## 2025-10-02 517.64 521.60 510.68 515.74 21222900 514.7766
## 2025-10-03 517.10 520.49 515.00 517.35 15112300 516.3835
## 2025-10-06 518.61 531.03 518.20 528.57 21388600 527.5826
## 2025-10-07 528.29 529.80 521.44 523.98 14615200 523.0011
## 2025-10-08 523.28 526.95 523.09 524.85 13363400 523.8695
Question 7 Getting the number of observations in that timeframe from
Q6
nrow(MSFT)
## [1] 84
Question8 Plotting the opening prices of Microsoft in order to see
the peak of the prices
plot(MSFT$MSFT.Open)

Question 10 Installing Fredr to use a new api to find FED data like
rates
#install.packages("fredr")
library(fredr)
fredr_set_key("fdba782502755d71d75d172987e1a88d")
rates <- fredr(series_id = "DFF", observation_start = as.Date("2018-01-01"))