Book Image

Introduction to R for Quantitative Finance

By : Gergely Daróczi, Michael Puhle, Edina Berlinger (EURO), Daniel Daniel Havran, Kata Váradi, Agnes Vidovics-Dancs, Agnes Vidovics Dancs, Michael Phule, Zsolt Tulassay, Peter Csoka, Marton Michaletzky, Edina Berlinger (EURO), Varadi Kata
Book Image

Introduction to R for Quantitative Finance

By: Gergely Daróczi, Michael Puhle, Edina Berlinger (EURO), Daniel Daniel Havran, Kata Váradi, Agnes Vidovics-Dancs, Agnes Vidovics Dancs, Michael Phule, Zsolt Tulassay, Peter Csoka, Marton Michaletzky, Edina Berlinger (EURO), Varadi Kata

Overview of this book

Introduction to R for Quantitative Finance will show you how to solve real-world quantitative fi nance problems using the statistical computing language R. The book covers diverse topics ranging from time series analysis to fi nancial networks. Each chapter briefl y presents the theory behind specific concepts and deals with solving a diverse range of problems using R with the help of practical examples.This book will be your guide on how to use and master R in order to solve quantitative finance problems. This book covers the essentials of quantitative finance, taking you through a number of clear and practical examples in R that will not only help you to understand the theory, but how to effectively deal with your own real-life problems.Starting with time series analysis, you will also learn how to optimize portfolios and how asset pricing models work. The book then covers fixed income securities and derivatives such as credit risk management.
Table of Contents (17 chapters)
Introduction to R for Quantitative Finance
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Beta estimation


The sensitivity of a security towards a factor can be estimated from past price movements. We will estimate the beta from the one-factor index model. First, we show the process of collecting and synchronizing data from different sources and then present the simple beta estimation method and, at last, a linear regression model is built.

Data selection

We download the time series of the price of a given stock, for example Google, and the time series of the price of the market index, the S&P 500, from June 1st 2009 to June 1st 2013 from Quandl, as discussed in the second chapter:

> library(Quandl)
> Quandl.auth("yourauthenticationtoken")
> G <- Quandl('GOOG/NASDAQ_GOOG',
+   start_date = '2009-06-01', end_date = '2013-06-01')

The resulting G is a variable containing 6 variables, from which we only need the Close values:

> str(G)
'data.frame':     1018 obs. of  6 variables:
 $ Date  : Date, format: "2009-06-01" "2009-06-02" ...
 $ Open  : num  419 426 426 435...