function [C, Cdelta] = BSMcall(S,E,r,sigma,tau)
% Compute the value of a call option according to Black-Scholes-Merton
%
% Input arguments: S = asset price at time t
%                  E = Exercise price
%                  r = interest rate
%                  sigma = volatility
%                  tau = time to expiry (T-t)
%
% Output arguments: C = call value, Cdelta = delta value of call

if tau > 0
    N = @(x) (1+erf(x/sqrt(2))) / 2;
    d1 = (log(S/E) + (r + 0.5*sigma^2)*tau)/(sigma*sqrt(tau));
    d2 = d1 - sigma*sqrt(tau);
    Cdelta = N(d1);
    C = S.*N(d1) - E*exp(-r*tau)*N(d2);
else
    C = max(S-E,0);
    Cdelta = 0.5*(sign(S-E) + 1);
end