%HW1%基于MATLAB的金融量化分析
- Q1 bootstrap the zero-rates
- Q2 implicit finite difference method
- Q3 CRR binomial tree (European call option prices )
- Q4 Bisection method
Q1 bootstrap the zero-rates
Given the 50USD (face value) bond price below:
Time to maturity | Coupon rate(paid semi-annually) | Bond price |
---|---|---|
0.5 | 0 | $49.05 |
1 | 0 | $48.09 |
1.5 | 1% | $47.81 |
2 | 1% | $47.03 |
2.5 | 1.2% | $46.51 |
3 | 1.2% | $45.75 |
3.5 | 1.5% | $45.45 |
4 | 1.5% | $44.73 |
4.5 | 1.8% | $44.63 |
5 | 1.8% | $43.91 |
5.5 | 2% | $42.95 |
6 | 2% | $41.45 |
Write a matlab programme to
i) bootstrap the zero-rates;
ii) and plot the yield curve over time using spline interpolation.
S1:
matlab code
%% Q1
clear all;Face=50;
Cr=[0 0 1 1 1.2 1.2 1.5 1.5 1.8 1.8 2 2]/100;
BondPrice=[49.05 48.09 47.81 47.03 46.51 45.75 45.45 44.73 44.63 43.91 42.95 41.45];
Maturity=[0.5:0.5:6];
Coupon=Face*Cr/2;
ZeroRate=[];
for i=1:length(Cr)PaymentTime2=Maturity(1:i);% points that payment givenZeroRate(i)=(log(Face+Coupon(i))-log(BondPrice(i)-sum(Coupon(i)*exp(-ZeroRate(1:i-1).*PaymentTime2(1:end-1)))))/Maturity(i);
end
%see the mathmatic formula below%using griddedInterpolation draw yield curve through Matlab
x=Maturity
v=ZeroRate
F= griddedInterpolant(x,v,'spline')
xq = linspace(0.5,6,500);
vq = F(xq);
plot(x,v,'ro')
hold on
plot(xq,vq,'.')
legend('Sample Points','Interpolated Values')
title('yield curve')% interp1
Time_grid=[0.5:0.05:6];
R_spline=interp1(Maturity,ZeroRate,Time_grid,'spline');
plot(Maturity,ZeroRate,'go',Time_grid,R_spline,'r');
Q2 implicit finite difference method
Given the risk-free rate 4.1% and the current stock price 115 RMB with volatility 30%. Use the implicit finite difference method to compute the 1-year American put option price with strike level 135 RMB.
clear all;S0=115; K=135; r=0.041; T=1; sigma=0.3; Smax=345; % must bigger than S0deltaS=1; dt=0.001;
% set up grid and adjust increments if necessary M = round(Smax/deltaS);
N = round(T/dt);
dt = T/N;
Value = zeros(M+1,N+1);
vecS = linspace(0,Smax,M+1)';
vecI = 0:M;
vecJ = 0:N;
% set up boundary conditions:call
% Value(:,N+1) = max(vecS-K,0);
% Value(1,:) = 0;
% Value(M+1,:) = Smax*exp(-r*dt*(N-vecJ));% set up boundary conditions