Black Scholes function in a Covered Call Simulation
6 views (last 30 days)
Show older comments
Hello
I am trying to simulate a covered call strategy, which is Asset-Call. Here is what I want to do:
%SIMULATION ASSET PRICE DYNAMICS
clear
all
close
all
clc
sigmaVECTOR=xlsread('ImplVola.xlsx');
rVECTOR=xlsread('InterestratesUSTreasuryBill.xlsx');
muVECTOR=xlsread('InterestratesUSTreasuryBill.xlsx');
S0VECTOR=xlsread('SMIKurseDiv.xlsx');
%based on the Brownian motion model
%dS=muSdt+sigmaSdz,where dz is the standard Wiener process.
%To simulate the path of the asset price over the interva(0,T),
%time has to be discretized with a time step dt:
%S(t+dt)=S(t)exp(vdt+sigma(dtE)^0.5)
%***********framework definition***********
%T=time horizont
T=0.5;
%Nsteps= Number of time steps
NSteps=26;
%Nrepl=number of replications
NRepl=10;
%dividend rate q=0 da keine Dividenden in dem halben Jahr ausgezahlt werden
q=0;
for
BIG=1:1
%***********Input factors***********
%sigma= implied volatility, weekly datas by Bloomberg
sigma=sigmaVECTOR(BIG)./100;
%S0= equity price of the Swiss Market Index weekly datas by Bloomberg
S0=S0VECTOR(BIG);
%mu=drift=r riskfree interest rate of a Treasury bill datas by Bloomberg
r=rVECTOR(BIG);
mu=muVECTOR(BIG);
%Define the Stike price
X=S0*exp((r+sigma^2/2)*T);
%***********Simulation of the Asset Paths***********
%AssetPaths
SPaths=AssetPaths(S0,mu,sigma,T,NSteps,NRepl);
%***********Bewertung Calloption***********
%Call Preise für Anzahl Wochen
for
i=1:NSteps
%**********************************
% Call prices for the amout of simulations
for j=1:NRepl
%price=Callprice
[price(NRepl,i)]=blsprice(SPaths(j,i),T,r,sigma,q);
end
%**********************************
T=T-(1/26);
end
end
1. Monte Carlo Simulation of the underlying Asset: - for 26 Weeks (NSteps=26) - for 10 Replications (NRepl=10), well as soon as the code works I will change this number up to 2000 The Monte Carlo function for the Asset prices looks as followed:
%define function
function SPaths=AssetPaths(S0,mu,sigma,T,NSteps,NRepl)
%define time steps
dt=T/NSteps;
% define and simulate the paths
nudt=(mu-0.5*sigma^2)*dt;
sidt=sigma*sqrt(dt);
Increments=nudt+sidt*randn(NRepl,NSteps);
LogPaths=cumsum([log(S0)*ones(NRepl,1),Increments],2);
SPaths=exp(LogPaths);
end
This code gives me a 10x27 matrix. I saved this code as AssetPaths.m. In the next step I want for each value of the Matrix a call price which means I need the Black Scholes formula to price it.
function price=blsprice(SPaths,T,r,sigma,X)
%where q is the dividend rate q=0
q=0;
S0=6;
X=S0*exp((r+sigma^2/2)*T);
d1=(log(SPaths/X)+(r+0.5*sigma^2)*T)/(sigma*sqrt(T));
d2=d1-(sigma*sqrt(T));
n1=0.5*(1+erf(d1/sqrt(2)));
n2=0.5*(1+erf(d2/sqrt(2)));
price=SPaths*n1-X*(exp(-r*T)*n2);
end
However there is an error in the Black scholes as it always occurs an error message. Can anyone help me? I am really desperate. Thank you
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!