COME COPIARE QUESTO CODICE SU MATLAB

di il
1 risposte

COME COPIARE QUESTO CODICE SU MATLAB

Raga salve a tutti volevo chiedervi se è possibile importare questo codice di matlab su matlab e come fare ..sto scrivendo la tesi e ho reperito vari codici ma su matlab sono una s*ga per favore illuminatemi

function f=bs_daoc(S,K,sigma,r,T,B)
% Input arguments: S = stock price at time t
% K = exercise price
% r = interest rate in percentage
% sigma = volatility in percentage
% T = time to maturity (in a year)
% B = barrier level
%
% Output argument: f = down and out call price
randn(’state’,100)
% Precompute invariant quantities:
power1 = -1+(2*r)/(sigma^2);
power2 = 1+(2*r)/(sigma^2);
a = (B/S)^power1;
b = (B/S)^power2;
d1 = (log(S/K)+(r+0.5*sigma^2)*(T))/(sigma*sqrt(T));
d2 = d1 - sigma*sqrt(T);
d3 = (log(S/B)+(r+0.5*sigma^2)*(T))/(sigma*sqrt(T)); d4 = (log(S/B)+(r-0.5*sigma^2)*(T))/(sigma*sqrt(T));
d5 = (log(S/B)-(r-0.5*sigma^2)*(T))/(sigma*sqrt(T));
d6 = (log(S/B)-(r+0.5*sigma^2)*(T))/(sigma*sqrt(T));
d7 = (log(S*K/(B^2))-(r-0.5*sigma^2)*(T))/(sigma*sqrt(T));
d8 = (log(S*K/(B^2))-(r+0.5*sigma^2)*(T))/(sigma*sqrt(T));
% Normal distributions of d values:
Nd1 = 0.5*(1+erf(d1/sqrt(2)));
Nd2 = 0.5*(1+erf(d2/sqrt(2)));
Nd3 = 0.5*(1+erf(d3/sqrt(2)));
Nd4 = 0.5*(1+erf(d4/sqrt(2)));
Nd5 = 0.5*(1+erf(d5/sqrt(2)));
Nd6 = 0.5*(1+erf(d6/sqrt(2)));
Nd7 = 0.5*(1+erf(d7/sqrt(2)));
Nd8 = 0.5*(1+erf(d8/sqrt(2)));
% For down-and-out call:
if K > B
bs_daoc = S*(Nd1-b*(1-Nd8))-K*exp(-r*T)*(Nd2-a*(1-Nd7))
else
bs_daoc = S*(Nd3-b*(1-Nd6))-K*exp(-r*T)*(Nd4-a*(1-Nd5))
end
f=bs_daoc;
grazie questo è uno dei codici magari se mi spiegate come fare con questo posso fare qualcosa con glia altri

1 Risposte

Devi accedere o registrarti per scrivere nel forum
1 risposte