% Program to simulate VAR by the monte-carlo method
% Monte carlo simulation for portfolio of only one stock
% James Thompson

mu=0.001;              % daily mean return
sigma=.01;             % volatility
t=1;                   % 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


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

%Sort our stock prices and compute the VAR
m=mean(S1);
S1=sort(S1);
VAR=m-S1(int32((iter*(1-conf))))
ABSVAR=S0*n-S1(int32((iter*(1-conf))))
