Daily Speculations

The Web Site of Victor Niederhoffer & Laurel Kenner

Dedicated to the scientific method, free markets, deflating ballyhoo, creating value, and laughter;  a forum for us to use our meager abilities to make the world of specinvestments a better place.




%Market VaR (simulation based)

%Gabe Carbone Aug 2006

%Returns is a 1...N row vector of stock market returns

%WindowRet is a 1...30 row vector; it is a 30 day lookback window of returns

%RetIndex is the index of WindowRet

%RandRetIndex is a randomization of RetIndex

%RandWindowRet is a randomization of WindowRet, created by applying
%WindowRet to RandRetIndex

%RandWindowRetVar is the x percentile of RandWindowRet, this is the one
%realization of the simulation-based VaR

%WindowRetVar is the mean of all 1000 realizations of RandWindowVar. It is
%an N-30 row vector.

%define i as the variable for the top-level loop from 1 to N-31
for i=1:(length(Returns(:,1))-31)
%define j as the variable for the lookback window
for j=1:30
%calculate RetIndex
%define k as the variable for the number of VaR simulations
for k=1:1000
%calculate randomized RetIndex using the uniform distribution
%calculate RandWindowRet using RandRetIndex as the index for WindowRet
%calc a realization of the VaR using the percentile function and a 5%
%calc WindowRetVar with each element being an average of all the VaR
%simulations for the corresponding lookback window