♣26♣Labs
26.1 Financial Analysis with quantmod
The quantmod package for R is directly helpful for financial modelling. It is “designed to assist the quantitative trader in the development, testing, and deployment of statistically based trading models” (see https://www.quantmod.com). It allows the user to build financial models, has a simple interface to get data, and has a suite of plots that not only look professional but also provide insight for the trader.
Its website is https:\\www.quantmod.com.
Also note that this section uses concepts of financial markets. It is best to understand at least the difference between bonds and stocks before going through this section. If these concepts are new, we recommend Chapter 30 “Asset Valuation Basics” on page 597.
26.1.1 The Basics of quantmod
The package
quantmod
can be installed as any other package. In the following code, we check if it is already installed and do so if it is not in our local library. An important function in
quantmod
is
getSymbols()
. This function allows to download historic data about financial instruments with just one line of code.
Now, we are ready to use
quantmod
. For example, we can start downloading some data with the function
getSymbols()
:
Get The Big R-Book now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.