#### 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.
Introduction to R for Quantitative Finance
Credits
www.PacktPub.com
Preface
Free Chapter
Time Series Analysis
Portfolio Optimization
Asset Pricing Models
Fixed Income Securities
Estimating the Term Structure of Interest Rates
Derivatives Pricing
Credit Risk Management
Extreme Value Theory
References
Index

## Working with real data

It is useful to know that portfolio optimization is totally integrated in various R packages that we will discuss later. However, it's better to walk before we run; so let's start with a simple self-made `R` function that we would also itemize line by line as follows:

```minvariance <- function(assets, mu = 0.005) {
return  <- log(tail(assets, -1) / head(assets, -1))
Q       <- rbind(cov(return), rep(1, ncol(assets)),
colMeans(return))
Q       <- cbind(Q, rbind(t(tail(Q, 2)), matrix(0, 2, 2)))
b       <- c(rep(0, ncol(assets)), 1, mu)
solve(Q, b)
}```

This is a direct implementation of the algorithm that we discussed in the Theorem (Lagrange) section.

For demonstration purposes, we have fetched some IT stock prices from a Quandl superset (http://www.quandl.com/USER_1KR/1KT), which is a public service providing an easy access to a large amount of quant data. Although the URL points to a downloadable comma-separated values (CSV...