1. Trang chủ
  2. » Công Nghệ Thông Tin

Financial Toolbox For Use with MATLAB Computation Visualization Programming phần 2 pptx

40 843 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 40
Dung lượng 261,46 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Analyzing and Computing Cash Flows The Financial Toolbox cash-flow functions compute interest rates, payments,present and future values, annuities, rates of return, and depreciation stre

Trang 1

The default basis is actual days if none is specified The toolbox basis choicesare:

Thus you can compute the difference between two dates in four different ways.The first way (basis = 0) simply returns the difference in actual days betweentwo dates The second (basis = 1) returns the difference, but adjusted to a360-day year in which all months have 30 days The third and fourth methodsreturn a difference in dates as a fraction of either a 360- or 365-day year,respectively

fridates = lweekdate(6, 1998, 1:12);

fridays = datestr(fridates)fridays =

30-Jan-199827-Feb-199827-Mar-199824-Apr-199829-May-199826-Jun-199831-Jul-199828-Aug-199825-Sep-199830-Oct-199827-Nov-199825-Dec-1998

basis = 0 Actual days (default)basis = 1 360-day year (assumes all months are 30 days)

Trang 2

Or your company closes on Martin Luther King Jr Day, which is the third

Monday in January Thenweekdatefunction determines those dates for 1998through 2001:

Accounting for holidays and other non-trading days is important when

examining financial dates The toolbox provides theholidaysfunction, whichcontains holidays and special non-trading days for the New York Stock

Exchange between 1950 and 2030, inclusive You can edit theholidays.mfile

to customize it with your own holidays and non-trading days In this example,use it to determine the standard holidays in the last half of 1998:

lhhdates = holidays('1-Jul-1998', '31-Dec-1998');

Trang 3

year, the day-count basis, and the end-of-month rule For example, todetermine the cash-flow dates for a security that pays four coupons per year onthe last day of the month, on an actual/365 day-count basis, just enter thesettlement date, the maturity date, and the parameters:

paydates = cfdates('14-Mar-1997', '30-Nov-1998', 4, 3, 1);paydays = datestr(paydates)

paydays =31-May-199731-Aug-199730-Nov-199728-Feb-199831-May-199831-Aug-199830-Nov-1998

Formatting Currency and Charting Financial Data

The Financial Toolbox provides several functions to format currency and chartfinancial data

Currency Formats

The currency formatting functions are:

These examples show their usedec = frac2cur('12.1', 8)returnsdec = 12.125, which is the decimal equivalent of 12-1/8 The secondinput variable is the denominator of the fraction

str = cur2str(−8264, 2)returns the string($8264.00) For this toolbox function, the output format is

a numerical format with dollar sign prefix, two decimal places, and negativenumbers in parentheses; e.g.,($123.45)and$6789.01 The standard

cur2frac Converts decimal currency values to fractional valuescur2str Converts a value to Financial Toolbox bank formatfrac2cur Converts fractional currency values to decimal values

Trang 4

MATLAB bank format uses two decimal places, no dollar sign, and a minus

sign for negative numbers; e.g.,−123.45and6789.01

Financial Charts

The toolbox financial charting functions

plot financial data and produce presentation-quality figures quickly and easily.They work with standard MATLAB functions that draw axes, control

appearance, and add labels and titles

Here are two plotting examples: a high-low-close chart of sample IBM stock

price data, and a Bollinger band chart of the same data These examples loaddata from an external file (ibm.dat), then call the functions using subsets of thedata.ibmis an R-by-6 matrix where each row R is a trading day’s data and

where columns 2, 3, and 4 contain the high, low, and closing prices,

respectively

Note: The data inibm.datis fictional and for illustrative use only

High-Low-Close Chart Example. First load the data and set up matrix dimensions.loadandsizeare standard MATLAB functions

load ibm.dat;

[ro, co] = size(ibm);

Open a figure window for the chart Use the Financial Toolboxhighlow

function to plot high, low, and close prices for the last 50 trading days in the

data file

figure;

pointfig Point and figure chart

highlow High, low, open, close chart

movavg Leading and lagging moving averages chart

Trang 5

Add labels and title, and set axes with standard MATLAB functions Use theFinancial Toolboxdateaxisfunction to provide dates for the x-axis ticks.

Bollinger Chart Example. Next the Financial Toolboxbollingfunction produces aBollinger band chart using all the closing prices in the same IBM stock pricematrix A Bollinger band chart plots actual data along with three other bands

of data The upper band is two standard deviations above a moving average;the lower band is two standard deviations below that moving average; and the

86 88 90 92 94 96 98

International Business Machines, 941231 − 950219

Trang 6

middle band is the moving average itself This example uses a 15-day movingaverage.

Assuming the previous IBM data is still loaded, simply execute the FinancialToolbox function

bolling(ibm(:,4), 15, 0);

Specify the axes, labels, and titles Again, usedateaxisto add the x-axis dates.

axis([0 ro min(ibm(:,4)) max(ibm(:,4))]);

ylabel('Price ($)');

title(['International Business Machines']);

dateaxis('x', 6)

MATLAB does the rest On a color monitor, the red lines are the upper and

lower bands, the green line is the 15-day simple moving average, and the blueline charts the actual price data In this reproduction, the outer lines are the

upper and lower bands, the middle smooth line is the moving average, and themiddle jagged line is the actual price data Again, the plotted data and axes

you see may differ from this reproduction

Trang 7

For help using MATLAB plotting functions, see the “Graphics” section of

Getting Started with MATLAB See Using MATLAB Graphics for details on

theaxis,title,xlabel, andylabelfunctions

Analyzing and Computing Cash Flows

The Financial Toolbox cash-flow functions compute interest rates, payments,present and future values, annuities, rates of return, and depreciation streams.Some examples in this section use this income stream: an initial investment of

$20,000 followed by three annual return payments, a second investment of

$5,000, then four more returns Investments are negative cash flows, returnpayments are positive cash flows

stream = [−20000, 2000, 2500, 3500, −5000, 6500,

9500, 9500, 9500];

12/31 02/19 04/09 05/29 07/18 09/06 10/26 12/15 02/03 45

50 55 60 65 70 75 80 85 90 95

International Business Machines

Trang 8

Interest Rates / Rates of Return

Several functions calculate interest rates involved with cash flows To computethe internal rate of return of the cash stream, simply execute the toolbox

functionirr

ror = irr(stream)

which gives a rate of return of 11.72%

Note that the internal rate of return of a cash flow may not have a unique

value Every time the sign changes in a cash flow, the equation definingirr can give up to two additional answers Anirr computation requires solving apolynomial equation, and the number of real roots of such an equation can

depend on the number of sign changes in the coefficients The equation for

internal rate of return is

where Investment is a (negative) initial cash outlay at time 0, cf nis the cash

flow in the nth period, and n is the number of periods Basically,irrfinds the

rate r such that the net present value of the cash flow equals the initial

investment If all of the cf ns are positive there is only one solution Every timethere is a change of sign between coefficients, up to two additional real roots

are possible There is usually only one answer that makes sense, but it is

possible to get returns of both 5% and 11% (for example) from one income

stream

Another toolbox rate function,effrr, calculates the effective rate of return

given an annual interest rate (also known as nominal rate or annual

percentage rate, APR) and number of compounding periods per year To ask

for the effective rate of a 9% APR compounded monthly, simply enter:

rate = effrr(0.09, 12)

The answer is 9.38%

A companion functionnomrrcomputes the nominal rate of return given the

effective annual rate and the number of compounding periods

Trang 9

Present / Future Values

The toolbox includes functions to compute the present or future value of cashflows at regular or irregular time intervals with equal or unequal payments:fvfix,fvvar,pvfix, andpvvar The-fixfunctions assume equal cash flows

at regular intervals, while the-varfunctions allow irregular cash flows atirregular periods

Now compute the net present value of the sample income stream for which youcomputed the internal rate of return This exercise also serves as a check onthat calculation because the net present value of a cash stream at its internalrate of return should be zero Enter

npv = pvvar(stream, ror)which returns 2.6830e-011, or 0.000000000026830— very close to zero The

answer usually is not exactly zero due to rounding errors and the

computational precision of the computer

Note: Some other toolbox functions behave similarly The functions thatcompute a bond’s yield, for example, often must solve a nonlinear equation Ifyou then use that yield to compute the net present value of the bond’s income

stream, it usually does not exactly equal the purchase price — but the

difference is negligible for practical applications

Sensitivity

The Financial Toolbox can also compute the Macaulay duration for a cash flowwhere all values in the stream are not necessarily the same The Macaulayduration measures how long, on average, the owner waits before receiving apayment cfdurcomputes the Macaulay duration and modified duration(volatility) of a cash stream

Returning to the sample cash flow and using a discount rate of 6%, thisexample

rate = 0.06;

[duration, moddur] = cfdur(stream, rate)gives a duration of 23.49 periods and a modified duration (volatility) of 22.16periods The length of these periods is the same as the length of the periods in

Trang 10

the cash flow Note that using the computed internal rate of return as the

discount rate is not appropriate, since a cash flow with net present value of 0has infinite duration

Depreciation

The toolbox includes functions to compute standard depreciation schedules:

straight line, general declining-balance, fixed declining-balance, and sum of

years’ digits Functions also compute a complete amortization schedule for anasset, and return the remaining depreciable value after a depreciation

schedule has been applied

This example depreciates an automobile worth $15,000 over five years with asalvage value of $1,500 It computes the general declining balance using twodifferent depreciation rates: 50% (or 1.5), and 100% (or 2.0, also known as

double declining balance) Enter

6000.00 3600.00 2160.00 1296.00 444.00These functions return the actual depreciation amount for the first four yearsand the remaining depreciable value as the entry for the fifth year

Annuities

Several toolbox functions deal with annuities This first example shows how tocompute the interest rate associated with a series of loan payments when onlythe payment amounts and principal are known For a loan whose original

value was $5000.00 and which was paid back monthly over four years at

$130.00/month:

rate = annurate(4*12, 130, 5000, 0, 0)

The function returns a rate of 0.0094 monthly, or approximately 11.28%

annually

Trang 11

The next example uses a present-value function to show how to compute theinitial principal when the payment and rate are known For a loan paid at

$300.00/month over four years at 11% annual interest:

principal = pvfix(0.11/12, 4*12, 300, 0, 0)The function returns the original principal value of $11,607.43

The final example computes an amortization schedule for a loan or annuity.The original value was $5000.00 and was paid back over 12 months at anannual rate of 9%

[prpmt, intpmt, balance, payment] =

and a scalar for the monthly payment

Trang 12

Since terminology varies among texts on this subject, here are some basic

definitions that apply to these Financial Toolbox functions You can also find

these and other definitions in the Glossary.

The settlement date of a bond is the date when money first changes hands; i.e.,

when a buyer pays for a bond It need not coincide with the issue date The

issue date is the date a bond is first offered for sale That date usually

determines when interest payments, known as coupons, are made The first and last coupon dates are the dates when the first and last coupons are paid.

Typically a bond pays coupons annually or semi-annually

Fixed-income securities can be purchased on dates that do not coincide with

coupon or payment dates The length of the first and last periods may differ

from the regular coupon period, and thus the bond owner is not entitled to thefull value of the coupon for that period Instead, the coupon is pro-rated

according to how long the bond is held during that period The toolbox includesprice and yield functions that handle odd first period, odd last period, and oddfirst and last periods

The maturity date of a bond is the date when the issuer returns the final face value, also known as the redemption value or par value, to the buyer.

Typically the purchase price, the price actually paid for a bond, is not the

same as the redemption value The yield of a bond is determined by the ratio

of redemption value to purchase price over the life of the bond It is the nominal

annual interest rate that gives a future value of the purchase price equal to

the redemption value of the bond The coupon payments determine part of thatyield

In the Reference chapter, these fixed-income functions use standard

abbreviations for variables

Trang 13

Similar functions compute prices with regular payments, payment at maturity,and odd first and last periods, as well as prices of Treasury bills and discountedsecurities such as zero-coupon bonds.

eom End of month rule

Abbreviation Refers To

Trang 14

Yield Functions

To illustrate toolbox yield functions, this example computes the yield of a bondthat has odd first and last periods and settlement in the first period It uses

descriptive variable names rather than the standard abbreviations First set

up variables for settlement date, maturity date, issue date, first coupon date

(fcoup), and a last coupon date (lcoup)

Now for a redemption value of $100.00, supply a purchase price of $95.70,

coupon rate of 4%, paying coupons four times a year, and assume a 360-day

year of equal 30-day months (basis = 1) To find the answer the function solves

a nonlinear equation using at most 50 iterations

Call the function

bndyield(purch, coupr, settledate, maturedate, freq, basis, eom, issuedate, fcoup, lcoup)

which returns the yield of 6.73%

You can also use vectors for each of these arguments but be careful that eachvector has the same number of arguments You receive a vector of yields in

return Using vectors computes yields for several securities at once

Toolbox functions also compute yields of Treasury bills and fixed-income

securities with payments at regular times or at maturity For example, usingthe previous dates and redemption value, a price of $95.00 and a 6% coupon

rate, this function

price = 95.0;

cpn = 0.06;

yldmat(settledate, maturedate, issuedate, redeem, price, cpn)

Trang 15

calculates a 13.62% yield for a security whose interest is paid at maturity.

Fixed-Income Sensitivities

The toolbox includes functions to perform sensitivity analysis such as convexityand the Macaulay and modified durations for fixed-income securities TheMacaulay duration of an income stream, such as a coupon bond, measures howlong, on average, the owner waits before receiving a payment It is theweighted average of the times payments are made, with the weights at time Tequal to the present value of the money received at time T The modifiedduration is the Macaulay duration discounted by the per-period interest rate;i.e., divided by (1+rate/frequency) Modified duration is also known asvolatility

To illustrate, this example computes the Macaulay and modified durations for

a bond with settlement and maturity dates as above, a redemption or par value

of $100.00, a 5% coupon rate, a 4.5% yield, semi-annual coupons, and date basis

Term Structure of Interest Rates

The toolbox contains several functions to derive and analyze interest ratecurves, including data conversion and extrapolation, bootstrapping, andinterest-rate curve conversion functions

One of the first problems in analyzing the term structure of interest rates isdealing with market data reported in different formats Treasury bills, forexample, are quoted with bid and asked bank-discount rates Treasury notesand bonds, on the other hand, are quoted with bid and asked prices based on

$100 face value To examine the full spectrum of Treasury securities, analystsmust convert data to a single format Toolbox functions ease this conversion

Trang 16

In this brief example, we use only one security each; analysts often use 30, 100,

or more of each

First, capture Treasury bill quotes in their reported format

Maturity Days Bid Ask AskYield

tbill = [datenum('12/26/1997') 53 0.0503 0.0499 0.0510];

then capture Treasury bond quotes in their reported format

Coupon Maturity Bid Ask AskYieldtbond = [0.08875 datenum(1998,11,4) 103+4/32 103+6/32 0.0564];and note that these quotes are based on a November 3, 1997 settlement date.settle = datenum('3-Nov-1997');

Next use the toolboxtbl2bondfunction to convert the Treasury bill data to

Treasury bond format:

tbtbond = tbl2bond(tbill)

tbtbond =

0 729750 99.259 99.265 0.052091(The second element oftbtbondis the serial date number for December 26,

1997.)

Now combine short-term (Treasury bill) with long-term (Treasury bond) data

to set up the overall term structure

tbondsall = [tbtbond; tbond]

[bonds, prices, yields] = tr2bonds(tbondsall);

With this market data, we are now ready to use one of the toolbox

bootstrapping functions to derive an implied zero curve Bootstrapping is a

Trang 17

process whereby you begin with known data points and solve for unknown datapoints using an underlying arbitrage theory Every coupon bond can be valued

as a package of zero-coupon bonds which mimic its cash flow and riskcharacteristics By mapping yields-to-maturity for each theoreticalzero-coupon bond, to the dates spanning the investment horizon, we can create

a theoretical zero-rate curve The toolbox provides two bootstrapping functions:zbtpricederives a zero curve from bond data and prices, andzbtyieldderives

a zero curve from bond data and yields We usezbtprice[zerorates, curvedates] = zbtprice(bonds, prices, settle)zerorates =

0.051107 0.054501curvedates = 729750 730063wherecurvedatesgives the investment horizon

datestr(curvedates)ans =

26-Dec-199704-Nov-1998Additional toolbox functions construct discount, forward, and par yield curvesfrom the zero curve, and vice-versa:

[discrates, curvedates] = zero2disc(zerorates, curvedates, settle); [fwdrates, curvedates] = zero2fwd(zerorates, curvedates, settle); [pyldrates, curvedates] = zero2pyld(zerorates, curvedates, settle);

Pricing and Analyzing Equity Derivatives

These toolbox functions compute prices, sensitivities, and profits for portfolios

of options or other equity derivatives They use the Black-Scholes model forEuropean options and the binomial model for American options Suchmeasures are useful for managing portfolios and for executing collars, hedges,and straddles

Trang 18

Delta of a derivative security is the rate of change of its price relative to the

price of the underlying asset It is the first derivative of the curve that relatesthe price of the derivative to the price of the underlying security When delta

is large, the price of the derivative is sensitive to small changes in the price ofthe underlying security

Gamma

Gamma of a derivative security is the rate of change of delta relative to the

price of the underlying asset; i.e., the second derivative of the option price

relative to the security price When gamma is small, the change delta is small.This sensitivity measure is important for deciding how much to adjust a hedgeposition

Lambda

Lambda, also known as the elasticity of an option, represents the percentage

change in the price of an option relative to a 1% change in the price of the

underlying security

Rho

Rho is the rate of change in option price relative to the underlying security’s

risk-free interest rate

Vega is the rate of change in the price of a derivative security relative to the

volatility of the underlying security When vega is large the security is

sensitive to small changes in volatility For example, options traders often

Trang 19

must decide whether to buy an option to hedge against vega or gamma Thehedge selected usually depends upon how frequently one rebalances a hedgeposition and also upon the variance of the price of the underlying asset (thevolatility) If the variance is changing rapidly, balancing against vega isusually preferable.

Implied Volatility

The implied volatility of an option is the variance that makes a call option priceequal to the market price It is used to determine a market estimate for thefuture volatility of a stock and provides the input volatility (when needed) tothe other Black-Scholes functions

Analysis Models

Toolbox functions for analyzing equity derivatives use the Black-Scholes modelfor European options and the binomial model for American options TheBlack-Scholes model makes several assumptions about the underlyingsecurities and their behavior The binomial model, on the other hand, makesfar fewer assumptions about the processes underlying an option For further

explanation, please see the book by John Hull listed in the Bibliography.

Black-Scholes Model

Using the Black-Scholes model entails several assumptions:

• The option price follows an Ito process.

• The option can be exercised only on its expiration date.

• Short selling is permitted.

• There are no transaction costs.

• All securities are divisible and pay no dividends.

• There is no riskless arbitrage.

• Trading is a continuous process.

• The risk-free interest rate is constant and remains the same for all

maturities

If any of these assumptions is untrue, Black-Scholes may not be an appropriatemodel

Trang 20

To illustrate toolbox Black-Scholes functions, this example computes the call

and put prices of a European option and its delta, gamma, lambda, and impliedvolatility The asset price is $100.00, the exercise price is $95.00, the risk-freeinterest rate is 10%, the time to maturity is 0.25 years, the volatility is 0.50,

and the dividend rate is 0 Simply executing the toolbox functions:

[optcall, optput] = blsprice(100, 95, 0.10, 0.25, 0.50, 0);

[callval, putval] = blsdelta(100, 95, 0.10, 0.25, 0.50, 0);

gammaval = blsgamma(100, 95, 0.10, 0.25, 0.50, 0);

vegaval = blsvega(100, 95, 0.10, 0.25, 0.50, 0);

[lamcall, lamput] = blslambda(100, 95, 0.10, 0.25, 0.50, 0);

yields

• The option call priceoptcall= $13.70

• The option put priceoptput= $6.35

• delta for a callcallval= 0.6665 and delta for a putputval=−0.3335

• gammagammaval= 0.0145

• vegavegaval= 18.1843

• lambda for a calllamcall= 4.8664 and lambda for a putlamput= –5.2528

Now as a computation check, find the implied volatility of the option using thecall option price fromblsprice

volatility = blsimpv(100, 95, 0.10, 0.25, optcall);

The function returns an implied volatility of 0.500, the originalblspriceinput

Binomial Model

The binomial model for pricing options or other equity derivatives assumes

that the probability over time of each possible price follows a binomial

distribution The basic assumption is that prices can move to only two values,one up and one down, over any short time period Plotting the two values, andthen the subsequent two values each, and then the subsequent two values

each, and so on over time, is known as “building a binomial tree.” This modelapplies to American options, which can be exercised any time up to and

including their expiration date

Ngày đăng: 12/08/2014, 16:22

TỪ KHÓA LIÊN QUAN