Anyway, having downloaded a bunch of stuff associated with a gaggle of stocks, this spreadsheet will sort them: (Click on the picture to download.)
All of the above spreadsheets download a single set of data for each stock ... and that's the most recent data!
If you'd like to build a historical data base yourself , you can use this guy:
You download as you'd normally do ... perhaps to check the latest numbers ... THEN, click the Save Data button to save that latest data.
Each stock must have it's own sheet, like so :
Of course, each sheet must be created ... but there's an Explain sheet that says:
In other words, you may decide which stocks get their data saved, which don't and which added sheets get deleted.
The greatest benefit to is the ability to apply the data science workflow to easily model and scale your financial analysis as described in R for Data Science. Scaling is the process of creating an analysis for one asset and then extending it to multiple groups. This idea of scaling is incredibly useful to financial analysts because typically one wants to compare many assets to make informed decisions. Fortunately, the package integrates with the making scaling super simple!
All functions return data in the (tidy data frame) format, which allows for interaction within the . This means we can:
- Seamlessly scale data retrieval and mutations
- Use the pipe () for chaining operations
- Use and : , , , /, /, etc
- Use : mapping functions with
- Model financial analysis using the data science workflow in R for Data Science
We’ll go through some useful techniques for getting and manipulating groups of data.
Scaling the Getting of Financial Data
A very basic example is retrieving the stock prices for multiple stocks. There are three primary ways to do this:
Method 1: Map a character vector with multiple stock symbols
The output is a single level tibble with all or the stock prices in one tibble. The auto-generated column name is “symbol”, which can be pre-emptively renamed by giving the vector a name (e.g. ) and then piping to .
Method 2: Map a tibble with stocks in first column
First, get a stock list in data frame format either by making the tibble or retrieving from / . The stock symbols must be in the first column.
Method 2A: Make a tibble
Second, send the stock list to . Notice how the symbol and industry columns are automatically expanded the length of the stock prices.
Method 2B: Use index or exchange
Get an index…
…or, get an exchange.
Send the index or exchange to . Important Note: This can take several minutes depending on the size of the index or exchange, which is why only the first three stocks are evaluated in the vignette.
You can use any applicable “getter” to get data for every stock in an index or an exchange! This includes: “stock.prices”, “key.ratios”, “key.stats”, “financials”, and more.
Method 3: Use purrr to map a function
We can pipe a tibble of stock symbols to a mutation that maps the function. The result is all of the stock prices in nested format.
Method 4: Compound Getters
In financial analysis, it’s very common to need data from various sources to combine in an analysis. For this reason multiple options (“compound getters”) can be used to return a “compound get”. A quick example:
This returns the stock prices and financials for each stock as one nested data frame! Any of the options that accept stock symbols can be used in this manner: , , , , , and .
Scaling the Mutation of Financial Data
Once you get the data, you typically want to do something with it. You can easily do this at scale. Let’s get the yearly returns for multiple stocks using . First, get the prices. We’ll use the data set, but you typically will use to retrieve data in “tibble” format.
Second, use to group by stock symbol. Third, apply the mutation. We can do this in one easy workflow. The function is applied to each group of stock prices, and a new data frame was returned with the annual returns in the correct periodicity.
Last, we can visualize the returns.