Get startedGet started for free

Welcome to the course!

1. Welcome to the course!

Hi, and welcome to the DataCamp course on importing and managing financial data in R. My name is Joshua Ulrich, and I'll be your guide throughout the course.

2. About me

A bit about me: I'm the creator or co-author of several R packages including TTR, xts, quantmod, blotter, and quantstrat. I'm also on the R/Finance Conference organizing committee, and I founded the Saint Louis R User Group. This course will teach you how to import financial and economic data and manipulate into a form suitable for analysis and modeling.

3. What is getSymbols()?

Let's get started. The first function I'd like to introduce you to is getSymbols() from the quantmod package. getSymbols() provides a consistent interface to multiple data sources. getSymbols() is also extensible, so it's straight-forward to add new data sources. By default, getSymbols() stores data in an xts object, but it can use other classes as well. getSymbols() can also import data two ways. It can either return the data like a normal function; or it can create an object for you, similar to what the load() function in base R does.

4. getSymbols() example

Let's take a look at an example. The first argument to getSymbols() is Symbols, which is how you specify the instrument you want to import. This may be a stock ticker symbol, an exchange rate, an economic data series, or some other identifier. Since you always specify a symbol, it's customary to omit the Symbols argument from your call to getSymbols(). Another important argument is src (or source), which tells getSymbols() which data source to import data from. The default source is Yahoo, so you do not need to specify that argument if you want to import data from Yahoo Finance.

5. getSymbols() data sources

In this course, we will only cover some of the data sources getSymbols() supports. Namely, Yahoo Finance, Google Finance, Federal Reserve Economic Data (or "FRED" database provided by the Saint Louis Federal Reserve Bank), foreign exchange from Oanda-dot-com, and CSV files.

6. Other getSymbols() data sources

Other getSymbols() data sources include: Yahoo Finance Japan, MySQL or SQLite databases, RData files, and rds files.

7. getSymbols() example

As I mentioned earlier, getSymbols() can import data two ways. The auto-dot-assign argument controls whether data is returned or loaded. If auto-dot-assign is true, data will be loaded into your workspace.

8. getSymbols() example

If auto-dot-assign is false, getSymbols() will return the data and you will need to assign it to an object.

9. Let's practice!

Now that you've been formally introduced, it's time to practice using getSymbols().

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.