International College of Digital Innovation, CMU
October 30, 2024
In this chapter, we cannot use the quantmod package because the technology is still under development.”
Download daily price of AAPL from Yahoo finance, from \(~~\)1 Jan 2020 to 30 Sep 2024, and upload to Rstudio and make this plot
The quantmod is useful for quantitative financial modelling framework and have three goals:
download data
charting
technical indicator
getSymbols() function
getSymbols: The function for load and manage data from multiple source
Recommend the arguments
Symbols : vector of stock or asset name
src : “yahoo”, FRED” , etc (this course use yahoo)
periodicity : “daily”, “weekly”, or monthly”
from : Starting day: Year-month-day (2020-11-31)
to : Ending day: Year-month-day (2022-12-31)
The object from yahoo finance is XTS.
getSymbols(Symbols = "AAPL",
src = "yahoo",
periodicity = "daily",# "weekly", "month"
from = "2020-01-01", # Year-month-day
to = "2024-09-30") # Year-month-day
or download multiple stocks price
eXtensible Time Series (xts)]
eXtensible Time Series (xts) is a powerful package that provides an extensible time series class, enabling uniform handling of many R time series classes by extending zoo.
The main benefit of using xts is the compatibility with other packages that use different time-series classes (timeSeries, zoo, …).
We have 3 xts objects, AAPL, META, and MSFT
Warning
In this study, We don’t need the variables AAPL.Volume amd AAPL.Adjected
Extract and display the stock data for “MSFT” for the year 2021. Use the xts
package’s subsetting techniques to filter by date.
Subset the “META” data to include only the observations between January 1, 2022, and December 31, 2022.
Extract the data for “MSFT” for the first quarter of 2023 (January to March) and display the results.
Create a subset of “META” data for the first 10 weeks of 2024 and calculate the average closing price during that period.
Extract “MSFT” data for the first 6 months of 2021 and 2023, and compare the average closing prices for these two periods.
Subset the “META” data to get the last 8 weeks of observations before September 30, 2024.