% Program to simulate VAR by the monte-carlo method
% Only one stock
% James Thompson

mu=0.001;              % daily mean return
sigma=.01;             % volatility
t=3;                   % number of periods
S0=130;                % Beginning stock price
n=100;                 % Number of shares
S=[];                  % This will hold our stock price distribution
iter=10000;           % number of monte carlo iterations we wish to run    
conf=0.99;             % the confidence level we are working at
K=131;                 % Strike Price
ncall=100000;           % Number of call options
nput=100000;            % Number of put options
portfolio=[];          % Will hold the value of our porfolio

S0=130.50;
t=2;
sigma=0.15;

%Generate stock price paths
Z=normrnd(0,1,[1 iter]);
S1= (S0*exp((mu-(1/2)*sigma*sigma)*t + sigma*sqrt(t)*Z));
call=max(S1-K,0);
put=max(K-S1,0);


mcall=mean(call);
mput=mean(put);

%calculate the money that Nick Leeson makes by selling the call and put
%options
start=nput*mput + mcall*ncall;

%save mcall and mput and use them for the next part.  Don't use the hard coded numbers how it has them here.
%start=nput*1.2373+ ncall*0.6346;


portfolio= start*ones(1,iter) - (max(S1-K,0)*ncall + max(K-S1,0)*nput);

m=mean(portfolio);
portfolio=sort(portfolio);
VAR=m-portfolio(int32((iter*(1-conf))))
%ABSVAR=0-portfolio(int32((iter*(1-conf))))
