Delta Hedging a put option

6 vues (au cours des 30 derniers jours)
Georgios Mourouzis
Georgios Mourouzis le 3 Juil 2022
Modifié(e) : Voss le 3 Juil 2022
Hello guys!! I wrote this code in order to find the cost of delta hedging a european put option and find its price. However while it runs it returns false results
function P=DeltaHedgingPut(S0,K,mu,r,T,sigma,Paths)
[NRepl,NSteps]=size(Paths);
NSteps=NSteps-1; %Τα χρονικα βηματα
Cost=zeros(NRepl,1);
dt=T/NSteps;
CashFlows=zeros(1,NSteps+1);
DiscountFactors=exp(-r*(0:1:NSteps)*dt);
for i=1:NRepl
Path=Paths(i,:);
Position=0;
Delta=blsdelta(Path(1:NSteps),K,r,T-(0:NSteps-1)*dt,sigma);
for j=1:NSteps
CashFlows(j)=(Position-Delta(j))*Paths(j);
Position=-Delta(j);
end
if Paths(NSteps+1)<K
CashFlows(NSteps+1)=-K+(1-Position)*Paths(NSteps+1);
else
CashFlows(NSteps+1)=Position*Path(NSteps+1);
end
Cost(i)=-dot(CashFlows,DiscountFactors);
end
P=mean(Cost);
end
In the command window i get this :
>> S0=37;K=40;mu=0.15;r=0.04;T=0.75;sigma=0.2;NRepl=15000;NSteps=269;
>> randn('state',0);
>> Paths=SPaths(S0,mu,sigma,T,NSteps,NRepl);
>> DeltaHedgingPut(S0, K, mu, r, T, sigma, Paths)
ans =
1.9499e+04
SPaths is used to create create different movements of thge stock of which the option is tied to
this is the code for SPaths :
function SPaths=SPaths(S0,mu,sigma,T,NSteps,NRepl)
dt=T/NSteps;
nudT=(mu-0.5*sigma^2)/dt;
sidT=sigma*sqrt(T);
Increments=nudT+sidT*randn(NRepl,NSteps);
LogPaths=cumsum([log(S0)*ones(NRepl,1),Increments],2);
SPaths=exp(LogPaths);
SPaths(:,1)=S0;
What could the mistke be ?? i cant find it anywhere??
Could it be in the Paths code? Although i doudt it !
Thanks in advance for your time and help !!
  1 commentaire
dpb
dpb le 3 Juil 2022
Format and indent the code at a minimum...
Probably very few regulars have a klew of what "delta hedging a european put option" is, what more how to calculate its cost, so with zero amplification of what is the base solution, I'd wager the chance of anybody here being able to spot a problem is minimal at best.
However, the line Position=-Delta(j);
for j=1:NSteps
CashFlows(j)=(Position-Delta(j))*Paths(j);
Position=-Delta(j);
end
looks highly suspicious to me of subsequent use being what is really intended. I have no idea what this is trying to compute; just sayin'...

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by