You are on page 1of 21

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/325807494

Practical Quantitative Finance with R

Book · December 2016

CITATIONS READS
0 2,139

1 author:

Ji-Hai Xu
drxudotnet.com
42 PUBLICATIONS   635 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Gincker.com - a new platform for graphics creation and technical analysis in finance View project

Interactive Machine learning playground View project

All content following this page was uploaded by Ji-Hai Xu on 17 June 2018.

The user has requested enhancement of the downloaded file.


Practical Quantitative
Finance with R
Solving Real-World Problems with R
for Quant Analysts and Individual Traders
Practical Quantitative
Finance with R
Solving Real-World Problems with R
for Quant Analysts and Individual Traders

Jack Xu, PhD

UniCAD Publishing
Practical Quantitative Finance with R
Copyright © 2016 by Jack Xu, PhD
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1UC

Editor: Tyler Xu

All rights reserved. No part of the contents of this book and corresponding example source code may be
reproduced, stored in a retrieval system, or transmitted in any form or by any means without the prior written
permission of the author.

The author has made every effort in the preparation of this book to ensure the accuracy of the information;
however, this book is sold without warranty, either express or implied. No liability is assumed for incidental or
consequential damages in connection with or arising out of the use of the information or programs contained in
the book.

Contact:
jxu@dxudotnet.com
Visit us on the website: www.drxudotnet.com

Published by UniCAD Publishing.


New York, USA
ISBN-13: 978-0-9793725-7-5
ISBN-10: 0-9793725-7-7

Publisher’s Cataloging-in-Publication Data

Xu, Jack
Practical Quantitative Finance with R – Solving Real-World Problems with R for Quant Analysts and Individual
Traders/ Jack Xu
– 1st ed.
p.cm.
ISBN 978-0-9793725-7-5

1. R Programming. 2. Finance. 3. Quant. 4. Time Series. 5. Quant Developer. 6. Quant Analyst. 7. Stock
Trading. 8. Algorithmic Trading. 9. Data Analysis. 10. Pricing Engines. 11. Portfolio Optimization
I. Title. II. Title. III Title: Practical Quantitative Finance with R
For my wonderful family
Contents
Introduction ............................................................................................ xv
Overview ......................................................................................................... xv
What this Book Includes ............................................................................... xvii
Is This Book for You? .................................................................................. xvii
What Do You Need to Use This Book? ....................................................... xviii
How the Book Is Organized......................................................................... xviii
Using Code Examples ..................................................................................... xx
Customer Support ........................................................................................... xx

Chapter 1 Introduction to R ................................................................... 1


Getting Started with R ...................................................................................... 1
Variables and Assignment....................................................................... 2
Operators ................................................................................................. 3
Built-in Functions.................................................................................... 4
Random Numbers.................................................................................... 6
Vectors and Matrices ........................................................................................ 7
Vectors .................................................................................................... 7
Matrices ................................................................................................... 8
Matrix Elements ............................................................................ 9
Special Matrices .......................................................................... 10
Matrix Operations ........................................................................ 11
Arrays and List................................................................................................ 12
Factors ............................................................................................................. 14
Data Frame ...................................................................................................... 15
Data Table ....................................................................................................... 18
DT[i, j, by] Command ........................................................................... 18
Data Join................................................................................................ 20
Functions in R ................................................................................................. 22

Chapter 2 Market Data ......................................................................... 25


Market Data from Yahoo ................................................................................ 25
EOD Stock Data .................................................................................... 26
Import CSV File .......................................................................... 26
viii | Contents

Using R Function ......................................................................... 28


Using quantmod Package ............................................................ 28
Stock Quotes ......................................................................................... 30
Using R Function ......................................................................... 30
Using quantmod Package ............................................................ 31
Option Chain Data................................................................................. 32
Using R Function ......................................................................... 32
Using quantmod Package ............................................................ 34
Market Data from Google ............................................................................... 35
EOD and Minute-Bar Data.................................................................... 36
Using R Functions ....................................................................... 36
Using quantmod Package ............................................................ 40
Real-Time Stock Quotes ....................................................................... 40
Option Chain Data................................................................................. 41
Market Data from Quandl ............................................................................... 45
Quandl API............................................................................................ 45
Adjusted Stock EOD Data .................................................................... 46
Other Market Data................................................................................. 48
ISDA Rates from Markit................................................................................. 49

Chapter 3 Plots and Graphics in R....................................................... 53


Base R Graphics.............................................................................................. 53
Simple 2D Plots..................................................................................... 53
Plots with Two Y Axes ......................................................................... 57
Specialized 2D Plots ............................................................................. 61
Bar Plots ...................................................................................... 62
Stair-Step Plots ............................................................................ 65
Stem Plots .................................................................................... 66
Error Bar Plots ............................................................................. 68
Histograms ................................................................................... 69
Area Plots .................................................................................... 70
Pie Plots ....................................................................................... 72
Creating Graphs Using ggplot2 ...................................................................... 73
Scatter Plots ........................................................................................... 74
Line Plots .............................................................................................. 77
Area Plots .............................................................................................. 82
Polar Plots ............................................................................................. 84
3D Plots........................................................................................................... 85
3D Line Plots......................................................................................... 86
3D Scatter Plots ..................................................................................... 87
Contents | ix

3D Surface-Like Charts......................................................................... 88
Specialized 3D Plots ............................................................................. 91
X-Y Color Plots ........................................................................... 91
Contour Plots ............................................................................... 92
Combination Plots ....................................................................... 92
3D Parametric Surfaces ......................................................................... 93
Helicoid Surface .......................................................................... 94
Sphere Surface ............................................................................. 95
Torus Surface ............................................................................... 95
Quadric Surfaces.......................................................................... 96
Interactive 3D Plots ........................................................................................ 98
Using plot3Drgl ..................................................................................... 99
Using rgl .............................................................................................. 101
Scatter Plots ............................................................................... 102
Custom Colormap ...................................................................... 103
Surface Plots .............................................................................. 106

Chapter 4 Stock Charts and Technical Indicators ........................... 111


Using Standard R Graphics........................................................................... 112
Using quantmod Package.............................................................................. 115
Line Stock Charts ................................................................................ 116
Bar and Candlestick Charts ................................................................. 118
Technical Indicators ...................................................................................... 121
Moving Average Based Indicators ...................................................... 122
Envelope and Bollinger Band Indicators ............................................ 125
MACD and RSI Indicators .................................................................. 126
On Balance Volume Indicator ............................................................. 127
Accumulation/Distribution Indicator .................................................. 129
Williams %R Indicator ........................................................................ 130
Stochastic Indicator ............................................................................. 132
Commodity Channel Index Indicator .................................................. 134
Add Custom Indicators ....................................................................... 135

Chapter 5 Options Pricing .................................................................. 139


Introduction to Options ................................................................................. 139
Option Payoffs .................................................................................... 140
Option Value ....................................................................................... 140
Pricing European Options ............................................................................. 141
Black-Scholes Model .......................................................................... 141
Generalized Black-Scholes Model ...................................................... 142
x | Contents

Implementation ................................................................................... 143


Black-Scholes Greeks ......................................................................... 144
Delta........................................................................................... 144
Gamma....................................................................................... 146
Theta .......................................................................................... 147
Rho............................................................................................. 148
Vega ........................................................................................... 149
Implied Volatility ................................................................................ 150
Pricing American Options ............................................................................ 152
BAW Approximation .......................................................................... 153
Implementation ................................................................................... 153
Applying BAW Approximation .......................................................... 156
Pricing Barrier Options ................................................................................. 158
Standard Barrier Option Formulas ...................................................... 158
Implementation ................................................................................... 160
Barrier Option Applications ................................................................ 164
Pricing European Options Using RQuantLib ............................................... 166
Scalar Inputs ........................................................................................ 166
Vector Inputs ....................................................................................... 167
Option Prices ....................................................................................... 167
Delta .................................................................................................... 169
Gamma ................................................................................................ 170
Theta .................................................................................................... 170
Vega .................................................................................................... 171
Rho ...................................................................................................... 172
Dividend Rho ...................................................................................... 173
Implied Volatility ................................................................................ 174
Pricing American Options Using RQuantLib ............................................... 175
Option Prices ....................................................................................... 175
Greeks ................................................................................................. 177
Implied Volatility ................................................................................ 178
Pricing Barrier Options Using RQuantLib ................................................... 179

Chapter 6 Pricing Fixed-Income Instruments .................................. 183


Simple Bonds Pricing ................................................................................... 183
Discounting Factors ............................................................................ 184
Pricing Bonds Using RQuantLib ........................................................ 185
Creating QuantLib-SWIG R ............................................................... 187
Pricing Bonds Using QuantLib-SWIG R ............................................ 187
Compounding Frequency Conventions ............................................... 189
Contents | xi

Pricing Bonds with a Rate Curve ........................................................ 190


Yield to Maturity ................................................................................. 192
Zero-Coupon Yield Curve ............................................................................ 192
Treasury Zero-Coupon Yield Curve ................................................... 193
Interbank Zero-Coupon Yield Curve .................................................. 200
Credit Spread Term Structures ............................................................ 203
CDS Pricing .................................................................................................. 209
Hazard Rate and Default Probability .................................................. 209
Risky Annuities and Risky Durations ................................................. 214
CDS Pricing Engine ............................................................................ 215

Chapter 7 Linear Analysis .................................................................. 223


Simple Linear Regression ............................................................................. 223
R-Squared ............................................................................................ 224
What are Alpha and Beta?................................................................... 225
Linear Regression in R ........................................................................ 225
Simple 2D PCA ............................................................................................ 230
PCA in R ............................................................................................. 231
Comparing Linear Regression with PCA ..................................................... 232
Multiple Linear Regressions ......................................................................... 236
MLR for Indices .................................................................................. 237
MLR for Stocks ................................................................................... 239
Multiple PCA ................................................................................................ 243
PCA for Indices ................................................................................... 243
PCA for Stocks .................................................................................... 246

Chapter 8 Time Series Analysis .......................................................... 251


Autocorrelation ............................................................................................. 251
White Noise ......................................................................................... 252
Random Walk with Drift ..................................................................... 253
Model for Financial Data .................................................................... 256
Model Selection ............................................................................................ 259
AIC ...................................................................................................... 259
BIC ...................................................................................................... 260
ARIMA Model .............................................................................................. 260
AR Model ............................................................................................ 261
Moving Average Model ...................................................................... 263
Autoregressive Moving Average Model ............................................. 266
ARIMA Model Applications............................................................... 272
GARCH Model ............................................................................................. 279
xii | Contents

Cointegration ................................................................................................ 283


Testing for Stationarity ....................................................................... 283
Cointergrating Time Series ................................................................. 285

Chapter 9 Machine Learning .............................................................. 291


KNN Classifier ............................................................................................. 291
KNN Model ......................................................................................... 291
KNN Model for Classification ............................................................ 292
Confusion Matrix ................................................................................ 297
KNN Model for Regression ................................................................ 298
Random Forest .............................................................................................. 301
Random Forest Algorithm................................................................... 301
Random Forest for Classification........................................................ 302
Random Forest for Regression ............................................................ 304
Support Vector Machine ............................................................................... 306
SVM for Classification ....................................................................... 306
SVM for Regression ............................................................................ 309
Artificial Neural Networks ........................................................................... 310
Introduction to Neural Networks ........................................................ 310
Neural Networks for Classification ..................................................... 313
Neural Network for Regression .......................................................... 316

Chapter 10 Trading Strategies and Backtesting ............................... 321


Trading Strategy Identification ..................................................................... 321
Trading Signals ............................................................................................. 324
Signals from Moving Average ............................................................ 324
Signals from Linear Regression .......................................................... 325
Signals from RSI ................................................................................. 327
Signals from Williams %R.................................................................. 328
Backtest System Implementation.................................................................. 329
P&L Computation ............................................................................... 330
Risk Measures ..................................................................................... 332
Pairs Trading ................................................................................................. 334
Pairs Identification .............................................................................. 335
Signals for Pairs Trading ..................................................................... 337
Market Neutral .................................................................................... 339
P&L for Pairs Trading ......................................................................... 340
Regime-Switching Model ............................................................................. 343
Hidden Markov Model ........................................................................ 344
Average True Range Indicator ............................................................ 346
Contents | xiii

Regime-Switching Strategy ................................................................ 347


R Packages for Trading System .................................................................... 350
Using Standard Indicators ................................................................... 351
Using Custom Indicators ..................................................................... 358
Multi-Asset Portfolios ......................................................................... 361

Chapter 11 Portfolio Optimization ..................................................... 367


Theoretical Background ................................................................................ 367
Efficient Frontier ................................................................................. 368
Portfolio Weights ................................................................................ 370
Quadratic Programming ................................................................................ 374
QP Model ............................................................................................ 374
QP Solvers ........................................................................................... 375
Portfolio Optimization Using QP Solver ............................................ 376
PortfolioAnalytics Package........................................................................... 378
Standard Deviation as Risk ................................................................. 378
Expected Shortfall as Risk .................................................................. 380
Efficient Frontier ................................................................................. 381
Complex Portfolios ....................................................................................... 386
Market Neutral Portfolios ................................................................... 387
Portfolio Rebalancing.......................................................................... 389

Index ...................................................................................................... 393


Introduction

Overview
Welcome to Practical Quantitative Finance with R. R is not only a general-purpose statistical computing
language, but also an excellent choice for fast prototyping quant models and backtesting trading
strategies in quantitative finance. This book focuses on introducing R as the scripting environment
choice for quantitative finance application development. It will provide the basic R programming,
quantitative analysis, and mathematical tools you need to develop real-world financial applications. All
the techniques described in this book can be directly used to solve those problems that many quants face
every day. I hope this book will be useful for quant developers/analysts, individual traders, and students
of all skill levels.
In recent years, quantitative finance has been an attractive field due to the intellectual challenge and high
remuneration. Many scientists, engineers, and students wish to change their careers to become a quant
developer/analyst in investment banks and hedge fund firms. Most of them have solid background in
mathematics, statistical analysis, physics modeling, and programming, but lack knowledge and
experience in quantitative finance. A question that they constantly ask is “what do I need to prepare
myself to become a quant developer or analyst?” This book will provide answer to this question and
prepare you for careers in quantitative analysis and development.
On the other hand, more and more individuals want to become independent (“retail”) quantitative traders
who are looking to start their own quantitative or algorithmic trading business. The most common issue
they are facing is what kind of background do they need in order to be successful in quantitative trading?
Most of those individuals received their advanced degrees in physics, mathematics, engineering, or
computer science. This kind of training in hard sciences will give them an edge in quantitative analysis
and pricing complex derivative instruments. However, the capability to quickly convert trading ideas
into trading strategies and the programming skill in implementing the automatic trading system are
equally important. This book will prepare you with all the necessary analysis and programming
techniques to become a well-equipped individual quant trader.
So what programming languages are most commonly used in quantitative finance? No doubt about it,
C++ is traditionally associated with finance applications for pricing complex derivative securities; and
much of the older financial infrastructure is also based on C++. In general, C++, C#, and Java tend to be
used for application and infrastructure development. In my previous book, Practical C# and WPF for
xvi | Introduction

Financial Markets, I have chosen C# and WPF as the programming framework in developing various
business applications in financial markets. The reason for using C# in that book is that C# is relatively
easy to learn in comparison to C++. You can learn C# and use it to develop financial applications quickly.
People with a background in VBA, R, or Java will find the transition to C# much easier than the transition
to C++. Furthermore, in many cases developers’ productivity levels are much higher than those achieved
with C++. It is also possible to create interoperable .NET applications that contain different technologies
such as C++, VBA, Matlab, and R legacy code.
In addition to create business applications and infrastructure, we also need a script-programming
environment that allows for rapid prototyping of an idea, provides us instant feedback, and enables the
data and result visualization in an efficient manner. In this regard, R, Python, and Matlab provide the
scripting environment and can be used to prototype quant models. All of these three are high-level
languages with capabilities such as time series analysis, linear/matrix/vectorization computation, and
fast prototyping for trading strategies. They all have strong communities developing code for numerical
analysis and quantitative finance. R is especially strong in the finance community. In my work as a quant,
I have used all of these three script languages extensively for prototyping quant models and strategy
backtesting. You can use any one of them as long as you are comfortable with it. In this book, I will
choose R as our scripting environment, mainly because R is a free open-source language, and has strong
packages in quantitative finance, as well as efficient data visualization power.
The main advantage of R is that it is free, extremely flexible and extensible. R is not only free, but also
open source. You can see the source code, and change it as per your own requirements. People across
different disciplines around world reviewed the core of the R system and contributed to make it better.
You can use R to perform data processing and analysis and to produce a variety of graphics. R has a
substantial collection of packages, which are written by experts in quantitative finance. That is why,
whether you are a quant analyst/developer, or individual trader, you should find a set of functions that
serve your purpose. The graphic system in R is one of the most powerful tools in this era, and you have
full control over every part of graphics produced in R. R is now becoming one of the platforms to
implement and prototype the research work, quant models, and trading strategies. You should be able to
find an R package suitable for the most recent developments in quantitative finance.
I write this book with the intention of providing a complete and comprehensive explanation of R
programming and usage of the relevant R packages in quantitative finance. The book pays special
attention to creating various business applications and reusable R libraries that can be directly used in
real-world finance applications. Much of this book contains original work based on my own
programming experience when I was prototyping quant models, pricing framework, and trading
strategies in quantitative financial field.
Practical Quantitative Finance with R provides everything you need to create your own advanced
applications and reusable packages in quantitative finance using R. It shows you how to use R and
relevant R packages to create a variety of financial applications that range from simple market data
collection, data visualization, and quantitative analysis to pricing equity options and complex fixed
income instruments, machine learning, trading strategy development, and portfolio optimization. I will
try my best to introduce you to R programming in quantitative finance in a simple way – simple enough
to be easily followed by a quant or individual trader who has basic prior experience in developing
business applications using R.
Introduction | xvii

What this Book Includes


This book and its sample code listings, which are available for download at my website at
www.drxudotnet.com, provide you with:
 A complete, in-depth instruction on practical quantitative finance programming with R. After
reading this book and running the example programs, you will be able to create various sophisticated
business applications in quantitative finance.
 Ready-to-run example programs that allow you to explore the quantitative finance programming
techniques described in the book. You can use these examples to understand how the algorithms in
finance work. You can modify the code examples or add new features to them to form the basis of
your own projects. Some of the example code listings provided in this book are already sophisticated
programming packages in quantitative finance that you can use directly in your own real-world
business applications.
 Many R functions in the sample code listings that you will find useful in your quant development.
These functions include charting libraries, various quantitative analysis models, pricing engines for
options and fixed income instruments, machine learning for trading strategy development and
backtesting, and the other useful utility functions. You can extract these functions and plug them
into your own business applications.

Is This Book for You?


You do not have to be an experienced quant developer/analyst or R programmer to use this book. I
designed this book to be useful to people of all levels of R programming experience and financial
background. In fact, I believe that if you have some prior experience with the quantitative analysis and
development, programming language such as C++, Java, VBA, C#, Matlab, or Python, you will be able
to sit down in front of your computer, startup RStudio, follow the examples provided in this book, and
quickly become proficient with quantitative application development using R. For those of you who are
already experienced quant analysts/developers or R users, I believe this book has much to offer as well.
A great deal of the information in this book about R programming in quantitative finance is not available
in other tutorial and reference books. In addition, you can use most of the example programs in this book
directly in your own real-world application development. This book will provide you with a level of
detail, explanation, instruction, and sample program code that will enable you to do just about anything
related to quantitative finance application development using R.
Perhaps you are a scientist, an engineer, a mathematician, or a student, rather than a professional quant
developer/analyst; nevertheless, this book is still a good bet for you. In fact, my own background is in
theoretical physics, a field involving extensive physical modeling, numerical calculations, and graphical
representations of calculated data. I devoted my effort to this field for many years, starting from
undergraduate up to PhD. My first computer experience was with FORTRAN. Later on, I had
programming experience with Basic, C, C++, MATLAB, VBA, C#, WPF, Python, and R. I always tried
to find an ideal development tool that would allow me not only to prototype my research work easily
but also to represent data graphically. The R development environment made it possible to develop such
integrated applications. I have been able to use R successfully to prototype quant models and trading
strategies quickly for quantitative analysis when I have worked on Wall Street.
Quant analysts/developers and individual quant traders can use the majority of the example programs in
this book routinely. Throughout the book, I will emphasize the usefulness of R programming to real-
xviii | Introduction

world quantitative finance applications. If you follow the instructions presented in this book closely, you
will easily be able to develop various practical business applications in quantitative finance from linear
analysis, machine learning to pricing engines, trading strategy development, asset allocation, and
portfolio optimization. At the same time, I will not spend too much time discussing programming style,
execution speed, and code vectorization/optimization, because a plethora of books and tutorial
information out there already deal with these topics. Most of the example programs you will find in this
book omit error handlings. This makes the code easier to understand by focusing only on the key
concepts and practical applications.

What Do You Need to Use This Book?


You will need no special equipment to make the best use of this book and understand the algorithms. To
run and modify the sample programs, you will need to install R and RStudio on your computer. R and
RStudio are both free, open-source software, available for all commonly used operating systems,
including Windows, Mac OS X, and Linux systems. You can find the installation instructions for
different systems at http://cran.r-project.org (for R itself) and http://www.rstudio.com (for RStudio). The
RStudio is an R IDE for an integrated editor, execution, and graphical environment. The example code
provided with this book was developed and tested on Windows 10 operating system with R version 3.2.3
and RStudio version 0.99.891.

How the Book Is Organized


This book is organized into eleven chapters, each of which covers a different topic about quantitative
finance applications using R. The following summaries of each chapter should give you an overview of
the book’s content:
Chapter 1, Introduction to R
This chapter introduces the basics of R and reviews some of the general aspects of R programming,
including the built-in functions, math operations, data frame, data table, and user-defined functions.
Chapter 2, Market Data
This chapter contains instructions on how to use R to interact with market data providers’ API. It
demonstrates how to retrieve the free market data from online data sources, including the end of the day
(EOD) stock data, real-time intraday data, interest rate data, foreign exchange rate data, and option-chain
data.
Chapter 3, Plots and Graphics in R
Data visualization plays a critical role in quantitative finance and trading. Quant analysts and traders
need to monitor the real-time changes in market and trading signals visually on their screen. This chapter
demonstrates how to use the R built-in plotting capability as well as the other powerful charting and
graphic packages, including ggplot2, plot3D, rgl, etc.
Chapter 4, Stock Charts and Technical Indicators
This chapter discusses various stock charts and technical indicators. We often use stock charts (line, bar,
candlestick) and indicators in quantitative analysis. A technical indicator is just a mathematical
calculation based on historic market data including price and volume, which is used to predict market
Introduction | xix

direction. It demonstrates how to use the common indicators from the TTR package and extract the output
results from the indicators.
Chapter 5, Options Pricing
This chapter covers the Black-Scholes formula used for options pricing. It shows several different
implementations for calculating the price and Greeks of the European and American options. It also
demonstrates how to use the open source quant libraries to price various exotic options, including barrier
options.
Chapter 6, Pricing Fixed-Income Instruments
This chapter discusses pricing for the fixed-income instruments, including interest rates, bonds, and
credit default swaps, as well as various related topics, such as cash flows, term structures, yield curves,
discount factors, and zero-coupon bonds. It also presents the detailed procedures on how to use QuantLib
to price these complex financial instruments.
Chapter 7, Linear Analysis
This chapter represents the most fundamental analysis approach in quantitative finance based on linear
analysis. It demonstrates how to develop different business applications using the linear regression,
principal component analysis (PCA), and correlation.
Chapter 8, Time Series Analysis
This chapter introduces some common modeling techniques for time series analysis, including the
autoregressive moving average (ARMA), the autoregressive integrated moving average (ARIMA), and
the volatility modeling generalized autoregressive conditional heteroscedasticity (GARCH). It also
examines the stationarity of a time series using different approaches, such as augmented Dickey-Fuller
(ADF) unit root test and Johansen test.
Chapter 9, Machine Learning
This chapter discusses the advanced quantitative analysis techniques: machine learning. Machine-
learning technique has become one of the most promising fields in quantitative finance. It is widely used
in quantitative finance for predicting the future stock prices. This chapter concentrates on the supervised
learning and covers several commonly used machine-learning algorithms in finance, including the K-
nearest neighbors, random forest, support vector machines, and neural networks.
Chapter 10, Trading Strategies and Backtesting
This chapter presents several trading strategies using the simple quantitative analysis techniques,
including the moving average and linear regression, as well as the commonly used technical indicators.
It also discusses a long-short based backtesting framework and a useful backtesting package named
quantstrat, which allow us to examine the historical performance of trading strategies for single stock
trading, stock pairs trading, and trading for multi-asset portfolios.
Chapter 11, Portfolio Optimization
This chapter presents introduction to portfolio optimization. Expected return and risk are the most
important parameters with regard to optimal portfolios. The goal of portfolio optimization is to find the
best asset allocation strategy that maximizes portfolio’s return and minimizes its risk. This chapter
discusses portfolio optimization using several different techniques, including, Markowitz’s classical
mean-variance method, mean-CVaR (conditional risk at risk), and the portfolioAnalytics package.
xx | Introduction

Using Code Examples


You may use the code in this book in your own applications and documentation. You do not need to
contact the author for permission unless you are reproducing a significant portion of the code. For
example, writing a program that uses several chunks of code from this book does not require permission.
Selling or distributing the example code listings does require permission. Incorporating a significant
amount of example code from this book into your applications and documentation also requires
permission. Integrating the example code from this book into commercial products is not allowed
without written permission of the author.

Customer Support
I am always interested in hearing from readers, and enjoy learning of your thoughts on this book. You
can send me comments by e-mail to jxu@DrXuDotNet.com. I also provide updates, bug fixes, and
ongoing support via my website:
www.DrXuDotNet.com
You can also obtain the complete source code for all of examples in this book from the foregoing website.

View publication stats

You might also like