150 likes | 268 Vues
This implementation demonstrates a binomial lattice method for pricing convertible bonds. It calculates the bond price based on market variables such as stock price (S), initial investment (I), conversion ratio (Q), risk-free rate (r), maturity time (T), volatility (sigma), and number of steps (N). The script also visualizes the sensitivity of the convertible bond price to stock price and volatility using MATLAB plots. Additionally, it includes a Monte Carlo simulation to estimate the normal cumulative distribution function (CDF) for further analysis, demonstrating robust computational techniques in financial modeling.
E N D
HW9 100071021 楊佑濬
Convertible Bonds function [ price, lattice] = CBprice( S, I, Q, r, T, sigma, N) deltaT = T/N; u = exp( sigma * sqrt(deltaT) ); d = 1/u; p = ( exp( r * deltaT ) - d ) / ( u - d ); for i = 0 : N CB(i+1) = max( I/Q, S * u^(N-i) * d^(i) ); end for i = N : -1 : 1 for j = 0 : i-1 CB(j+1) = exp(-r*deltaT) * ( CB(j+1)*p + CB(j+2)*(1-p) ); S_p = S * u^(i-1-j) * d^(j) ; CB(j+1) = max( CB(j+1) , S_p ); end lattice(1:i,i) = CB(1:i); end price = CB(1); end
S = 35; I = 100000; Q = 2500; r = 0.02; T = 5; sigma = 0.3; N = 100; >> CBprice(S,I,Q,r,T,sigma,N) ans = 44.959 >>
Demo Code S = 35; I = 100000; Q = 2500; r = 0.02; T = 5; sigma = 0.3; N = 100; for ST = 1 : 100 P(ST) = CBprice(ST,I,Q,r,T,sigma,N); end B = I/Q * exp(-r*T); figure; plot(ones(100)*B); hold on; plot(P); title('S0 to CB price'); for i = 1 : 100 P(i) = CBprice(S,I,Q,r,T,i*0.002,N); end figure; plot(ones(100)*B); hold on; plot(P); title('Sigma to CB price');
Monte Carlo of Normal CDF function [ p ] = MCnormcdf( X, N ) if(nargin<2) N = 10000000; end for i = 1:length(X) p(i) = 1/sqrt(2*pi) * mean( exp(-1* ((rand(1,N)*X(i)).^2) / 2 ) ) * X(i) + 0.5; end end
Demo Code x = linspace(-40,40,1000); tic; plot(x,MCnormcdf(x),x,normcdf(x)); toc;
Outcome • i7-4770 3.40GHz 8 cores / 8G memory >> MCdemo Elapsed time is 128.180229 seconds. >> • i5-2520M 2.50GHz 4 cores / 8G memory >> MCdemo Elapsed time is 302.060766 seconds. >>
Demo Code x = linspace(-3,3,1000); tic; plot(x,MCnormcdf(x),x,normcdf(x)); toc; for i = 1:10000 MC(i) = MCnormcdf(1.96,i); end plot(1:10000,MC,1:10000,normcdf(1.96));