% Program to simulate VAR by the monte-carlo method % Only one stock % James Thompson function [VAR]=calc_VAR(iter,mu,sigma,t,S0,n,conf) %Z=randn(1,iter); Z=normrnd(0,1,[1 iter]); S1= (S0*exp((mu-(1/2)*sigma*sigma)*t + sigma*sqrt(t)*Z))*n; %S1 =(S0 + S0*(mu*t + sigma*sqrt(t)*Z))*n; m=mean(S1); S1=sort(S1); VAR=m-S1(int32((iter*(1-conf)))); ABSVAR=S0*n-S1(int32((iter*(1-conf))));