What Is the Financial Toolbox? . . . . . . . . . . . . . . . . . . . . . 1-2
Using Matrix Functions for Finance . . . . . . . . . . . . . . . . . 1-4
Key Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Referencing Matrix Elements . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Transposing Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6
Matrix Algebra Refresher . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7
Adding and Subtracting Matrices . . . . . . . . . . . . . . . . . . . . 1-7
Multiplying Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8
Dividing Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13
Solving Simultaneous Linear Equations . . . . . . . . . . . . . . . 1-13
Operating Element-by-Element . . . . . . . . . . . . . . . . . . . . . . 1-17
Function Input/Output Arguments . . . . . . . . . . . . . . . . . . 1-18
Input Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-18
Function Output Arguments . . . . . . . . . . . . . . . . . . . . . . . . 1-20
Interest Rate Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-21
Performing Common Financial Tasks
2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Handling and Converting Dates . . . . . . . . . . . . . . . . . . . . . 2-4
Date Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Date Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
Current Date and Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8
Determining Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9
v
Formatting Currency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12
Charting Financial Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13
High-Low-Close Chart Example . . . . . . . . . . . . . . . . . . . . . . 2-13
Bollinger Chart Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15
Analyzing and Computing Cash Flows . . . . . . . . . . . . . . . 2-17
Interest Rates/Rates of Return . . . . . . . . . . . . . . . . . . . . . . . 2-17
Present or Future Values . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18
Depreciation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19
Annuities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19
Pricing and Computing Yields for Fixed-Income
Securities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21
Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21
SIA Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24
SIA Default Parameter Values . . . . . . . . . . . . . . . . . . . . . . . 2-25
SIA Coupon Date Calculations . . . . . . . . . . . . . . . . . . . . . . . 2-28
SIA Semiannual Yield Conventions . . . . . . . . . . . . . . . . . . . 2-29
Pricing Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29
Yield Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-30
Fixed-Income Sensitivities . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31
Term Structure of Interest Rates . . . . . . . . . . . . . . . . . . . . . 2-31
Pricing and Analyzing Equity Derivatives . . . . . . . . . . . 2-35
Sensitivity Measures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-35
Analysis Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-36
Portfolio Analysis
3
Analyzing Portfolios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Portfolio Optimization Functions . . . . . . . . . . . . . . . . . . . 3-3
Portfolio Construction Examples . . . . . . . . . . . . . . . . . . . . 3-5
Efficient Frontier Example . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5
vi Contents
Portfolio Selection and Risk Aversion . . . . . . . . . . . . . . . 3-8
Optimal Risky Portfolio Example . . . . . . . . . . . . . . . . . . . . . 3-9
Constraint Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12
Linear Constraint Equations . . . . . . . . . . . . . . . . . . . . . . . . 3-14
Specifying Additional Constraints . . . . . . . . . . . . . . . . . . . . 3-17
Active Returns and Tracking Error Efficient
Frontier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Investment Performance Metrics
4
Overview of Performance Metrics . . . . . . . . . . . . . . . . . . . 4-2
Illustrative Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Using the Sharpe Ratio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5
Sharpe Ratio Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5
Using the Information Ratio . . . . . . . . . . . . . . . . . . . . . . . . 4-6
Information Ratio Example . . . . . . . . . . . . . . . . . . . . . . . . . 4-6
Tracking Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7
Tracking Error Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7
Risk-Adjusted Return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8
Risk-Adjusted Return Example . . . . . . . . . . . . . . . . . . . . . . 4-8
Sample and Expected Lower Partial Moments . . . . . . . . 4-10
Sample Lower Partial Moments Example . . . . . . . . . . . . . . 4-10
Expected Lower Partial Moments Example . . . . . . . . . . . . 4-11
Maximum and Expected Maximum Drawdown . . . . . . . 4-12
Maximum Drawdown Example . . . . . . . . . . . . . . . . . . . . . . 4-12
Expected Maximum Drawdown Example . . . . . . . . . . . . . . 4-13
vii
Regression with Missing Data
5
Multivariate Normal Regression with Missing Data . . . 5-2
Multivariate Normal Regression . . . . . . . . . . . . . . . . . . . . . 5-2
Maximum Likelihood Estimation . . . . . . . . . . . . . . . . . . . . . 5-3
Special Case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Least-Squares Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Mean and Covariance Estimation . . . . . . . . . . . . . . . . . . . . 5-5
Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5
Fisher Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5
Statistical Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6
Maximum Likelihood Estimation with Missing Data . . 5-8
ECM Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8
Standard Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
Data Augmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
Multivariate Normal Regression Functions . . . . . . . . . . . . 5-11
Multivariate Normal Regression Without Missing Data . . 5-12
Multivariate Normal Regression with Missing Data . . . . . 5-13
Least-Squares Regression with Missing Data . . . . . . . . . . . 5-13
Multivariate Normal Parameter Estimation with Missing
Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
Support Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15
Regressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15
Multivariate Normal Regression (MVNR) . . . . . . . . . . . . . . 5-16
Least-Squares Regression (LSR) . . . . . . . . . . . . . . . . . . . . . 5-16
Covariance-Weighted Least Squares (CWLS) . . . . . . . . . . . 5-17
Feasible Generalized Least Squares (FGLS) . . . . . . . . . . . . 5-18
Seemingly Unrelated Regression (SUR) . . . . . . . . . . . . . . . 5-19
Mean and Covariance Parameter Estimation . . . . . . . . . . . 5-21
Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-21
Slow Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-22
Nonrandom Residuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-23
Nonconvergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-23
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-25
Portfolios with Missing Data . . . . . . . . . . . . . . . . . . . . . . . . 5-25
Valuation with Missing Data . . . . . . . . . . . . . . . . . . . . . . . . 5-33
Capital Asset Pricing Model . . . . . . . . . . . . . . . . . . . . . . . . . 5-33
Estimation of the CAPM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-34
Estimation with Missing Data . . . . . . . . . . . . . . . . . . . . . . . 5-35
viii Contents
Separate Estimation of Some Technology Stock Betas . . . . 5-35
Grouped Estimation of Some Technology Stock Betas . . . . 5-38
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-41
Solving Sample Problems
6
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
Common Problems in Finance . . . . . . . . . . . . . . . . . . . . . . 6-3
Sensitivity of Bond Prices to Changes in Interest Rates . . 6-3
Constructing a Bond Portfolio to Hedge Against Duration
and Convexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6
Sensitivity of Bond Prices to Parallel Shifts in the Yield
Curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9
Constructing Greek-Neutral Portfolios of European Stock
Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12
Term Structure Analysis and Interest Rate Swap
Pricing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-16
Producing Graphics with the Toolbox . . . . . . . . . . . . . . . 6-20
Plotting an Efficient Frontier . . . . . . . . . . . . . . . . . . . . . . . . 6-20
Plotting Sensitivities of an Option . . . . . . . . . . . . . . . . . . . . 6-22
Plotting Sensitivities of a Portfolio of Options . . . . . . . . . . 6-24
Financial Time Series Analysis
7
Analyzing Financial Time Series . . . . . . . . . . . . . . . . . . . . 7-2
Creating Financial Time Series Objects . . . . . . . . . . . . . . 7-3
Using the Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
Transforming a Text File . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14
Visualizing Financial Time Series Objects . . . . . . . . . . . 7-18
ix
Using chartfts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-18
Zoom Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-21
Combine Axes Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-24
Using Financial Time Series
8
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Working with Financial Time Series Objects . . . . . . . . . 8-3
Financial Time Series Object Structure . . . . . . . . . . . . . . . 8-3
Data Extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3
Object to Matrix Conversion . . . . . . . . . . . . . . . . . . . . . . . . . 8-5
Indexing a Financial Time Series Object . . . . . . . . . . . . . . . 8-7
Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15
Data Transformation and Frequency Conversion . . . . . . . . 8-19
Demonstration Program . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-24
Loading the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-24
Create Financial Time Series Objects . . . . . . . . . . . . . . . . . 8-25
Create Closing Prices Adjustment Series . . . . . . . . . . . . . . 8-26
Adjust Closing Prices and Make Them Spot Prices . . . . . . 8-26
Create Return Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-27
Regress Return Series Against Metric Data . . . . . . . . . . . . 8-27
Plot the Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-28
Calculate the Dividend Rate . . . . . . . . . . . . . . . . . . . . . . . . . 8-29
Financial Time Series Tool (FTSTool)
9
What Is the Financial Time Series Tool? . . . . . . . . . . . . . 9-2
Getting Started with FTSTool . . . . . . . . . . . . . . . . . . . . . . . 9-4
Loading Data with FTSTool . . . . . . . . . . . . . . . . . . . . . . . . . 9-5
x Contents
Obtaining External Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-5
Obtaining Internal Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-7
Viewing the MATLAB Workspace . . . . . . . . . . . . . . . . . . . . 9-8
Using FTSTool for Supported Tasks . . . . . . . . . . . . . . . . . 9-10
Creating a Financial Time Series Object . . . . . . . . . . . . . . . 9-10
Merging Financial Time Series Objects . . . . . . . . . . . . . . . . 9-11
Converting a Financial Time Series Object to a MATLAB
Double-Precision Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . 9-12
Plotting the Output in Several Formats . . . . . . . . . . . . . . . 9-12
Viewing Data for a Financial Time Series Object in the
Data Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-13
Modifying Data for a Financial Time Series Object in the
Data Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-14
Viewing and Modifying the Properties for a FINTS
Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-16
Using FTSTool with Other Time Series GUIs . . . . . . . . . 9-18
Financial Time Series Graphical User Interface
10
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
Main Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
Using the Financial Time Series GUI . . . . . . . . . . . . . . . . 10-7
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-7
Data Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-8
Analysis Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-13
Graphs Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-15
Saving Time Series Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-19
Technical Analysis
11
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
xi
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5
Moving Average Convergence/Divergence (MACD) . . . . . . 11-5
Williams %R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6
Relative Strength Index (RSI) . . . . . . . . . . . . . . . . . . . . . . . 11-8
On-Balance Volume (OBV) . . . . . . . . . . . . . . . . . . . . . . . . . . 11-9
Functions — By Category