Yahoo Finance is a powerful suite of information supported by Yahoo, which provides information such as:
In addition to providing this information within an easy to use website, there is also an extensive API framework developed for the website in order to easily facilitate information being downloaded for analysis.
As I mentioned above, Yahoo Finance provides a powerful suite of financial information related to markets. Being able to have access to this data for detailed analysis has the potential to unlock untold gains, as well as to facilitate market predictions. While this isn’t a perfect science by any means, having access to this information can help create better informed decisions and facilitate decisions with live, up-to-date data, rather than data from days or even weeks ago.
Luckily for us, there are already packages that we can leverage in order to get this data.
In Python, there is yfinance, an extensive package for interacting with the data.
In R, there is quantmod, which also retrieves the information needed.It also provides a couple of charts and details that we can use in order to further help our analysis.
Quantmod does not require any credentials or authorization, so we are able to hop right into getting our data.
install.packages("quantmod")library(quantmod)That is it! Two easy steps, and we are ready to begin collecting data.
Suppose we want to collect information about Apple. We only need to know their ticker, which is ‘AAPL’ on the ‘NASDAQ’.
From there, we can combine that information with the
getSymbols function:
apple_df <- getSymbols('AAPL', src='yahoo', auto.assign=FALSE)A couple of notes about the parameters:
auto.assign=FALSE parameter allows us to control
the name of the dataframe and not have automatically put into
memorysrc='yahoo' parameter allows us to specific the
source of the stock information that we would like to use.apple_df will look like this:
| Date | AAPL.Open | AAPL.High | AAPL.Low | AAPL.Close | AAPL.Volume | AAPL.Adjusted |
|---|---|---|---|---|---|---|
| 2023-03-27 | 159.94 | 160.77 | 157.87 | 158.28 | 52390300 | 158.28 |
| 2023-03-28 | 157.97 | 158.49 | 155.98 | 157.65 | 45992200 | 157.65 |
| 2023-03-29 | 159.37 | 161.05 | 159.35 | 160.77 | 51305700 | 160.77 |
| 2023-03-30 | 161.53 | 162.47 | 161.27 | 162.36 | 49501700 | 162.36 |
| 2023-03-31 | 162.44 | 165.00 | 161.91 | 164.90 | 68694700 | 164.90 |
Now that we have this data, we are able to use some other built in
functions, such as chartSeries in order to generate some
visualizations.
This following code generates the trend of AAPL’s stock price and volume over the last 6 months.
chartSeries(apple_df, name="AAPL", subset="last 6 months", theme=chartTheme("white"))