function [put,call,DeltaP,DeltaC] = BlackScholesPut(S,K,r,sigma,T)
%[put,call,DeltaP,DeltaC] = BlackScholesPut(S0,K,r,sigma,T)
%European put & call option prices under Black-Scholes model
%
%inputs:
%     S0: current stock price 
%      K: strike 
%      r: annual interest rate for continuous compounding
%  sigma: annual volatility
%      T: time to maturity in years
%outputs:
%    put: price of European put option
%   call: price of European call option
% DeltaP: Delta (deriv. w.r.t. S0) of put price
% DeltaC: Delta (deriv. w.r.t. S0) of call price 
%
%The arguments S,K,r,sigma,T can be one of the following
%   * all scalars
%   * one argument is a vector, the others are scalars
%   * all are vectors of the same size

Phi = @(x) erfc(-x/sqrt(2))/2;   % CDF for std. normal distr.

d1 = (log(S./K) + (r+sigma.^2/2).*T)./(sigma.*sqrt(T));
d2 = d1 - sigma.*sqrt(T);
call = S.*Phi(d1) - K.*exp(-r.*T).*Phi(d2);
put = call + K.*exp(-r.*T) - S;   % use put-call parity
DeltaC = Phi(d1);
DeltaP = Phi(d1) - 1;


