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);
CashFlows=zeros(1,NSteps+1);
DiscountFactors=exp(-r*(0:1:NSteps)*dt);
Delta=blsdelta(Path(1:NSteps),K,r,T-(0:NSteps-1)*dt,sigma);
CashFlows(j)=(Position-Delta(j))*Paths(j);
CashFlows(NSteps+1)=-K+(1-Position)*Paths(NSteps+1);
CashFlows(NSteps+1)=Position*Path(NSteps+1);
Cost(i)=-dot(CashFlows,DiscountFactors);
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;
>> Paths=SPaths(S0,mu,sigma,T,NSteps,NRepl);
>> DeltaHedgingPut(S0, K, mu, r, T, sigma, Paths)
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)
nudT=(mu-0.5*sigma^2)/dt;
Increments=nudT+sidT*randn(NRepl,NSteps);
LogPaths=cumsum([log(S0)*ones(NRepl,1),Increments],2);
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 !!