function  [C,CDelta, P,PDelta] = BlackScholesfunc(S,E,T,r,sigma)
% [C,CDelta, P,PDelta] = BlackScholesfunc(S,E,t,r,sigma)
% Returns the call prices (C and the delta) and the put prices (P and the
% delta) given the inputs below based on the analytical solution of the
% Black Scholes PDE in Mathematics of Financial Derivatives pp 48.
% S is a vector of stock prices
% E is the strike price
% T is a vector of the number of days to expiry
% r is the risk free interest rate (NOT in %)
% sigma is the volatility (NOT in %)

% for each time we will construct the payoff as a function of the prices
% given

for j = 1:length(S)
for i = 1:length(T)
    
    d1(j,i) = (log(S(j)/E) + (r + 0.5*sigma*sigma)*(1.00001*T(end) - T(i)))/(sigma*sqrt(1.00001*T(end)-T(i)));

    d2(j,i) = (log(S(j)/E) + (r - 0.5*sigma*sigma)*(1.00001*T(end) - T(i)))/(sigma*sqrt(1.00001*T(end)-T(i)));

    C(j,i) = S(j)*normcdf(d1(j,i)) - E*exp(-r*(1.00001*T(end)-T(i)))*normcdf(d2(j,i));

    CDelta(j,i) = normcdf(d1(j,i));

    P(j,i) = E*exp(-r*(1.00001*T(end)-T(i)))*normcdf(-d2(j,i)) - S(j)*normcdf(-d1(j,i));

    PDelta(j,i) = CDelta(j,i) - 1;
    
end
end

[x,y] = meshgrid(T,S);
surf(x,y,C)
figure
surf(x,y,CDelta)



end