Book Image

Mastering R for Quantitative Finance

Book Image

Mastering R for Quantitative Finance

Overview of this book

Table of Contents (20 chapters)
Mastering R for Quantitative Finance
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Modeling in R


In the following section, we will learn the implementation of the previously described models with the help of R.

Data selection

In Chapter 4, Big Data – Advanced Analytics, we will discuss in detail the aspects and methods of getting data from open sources and working with them efficiently. Here, we only present how the time series of stock prices and other relevant information can be acquired and used for the factor model's estimations.

We used the quantmod package to collect the database.

Here is how it works in R:

library(quantmod)
stocks <- stockSymbols()

As a result, we need to wait for a few seconds while data is fetched, and then we can see the output:

Fetching AMEX symbols...
Fetching NASDAQ symbols...
Fetching NYSE symbols...

Now, we have a data frame R object that contains about 6,500 stocks that are traded on different exchanges such as AMEX, NASDAQ, or NYSE. In order to see the variables that the dataset contains, we can use the str command:

str(stocks)
'data.frame...