%GIRSANOV TRANSFORMATION ILLUSTRATION

mu=1; %drift

n=30; %no. of trajectories 
 
hv=zeros(1,n);

%%% parameters
dt=0.001;
T=5;
t=[0:dt:T];

clf reset;

st=size(t);
st=st(2);
Xt=zeros(n,st); 
MT=zeros(n,1);
 
for (i=[1:1:n])

   Bmt = cumsum(sqrt(dt)*randn(1,st));
   Xt(i,:)=Bmt+mu*t; 
   MT(i)=exp(-mu*Bmt(st)+0.5*mu^2*T);
   
%   plot(t,Xt(i,:),'Color',[0 i/n 1]);
%   hold on; 

end

MTmax=max(MT);

for (i=[1:1:n])
 
   a=MT(i)/MTmax;
   plot(t,Xt(i,:),'Color',[0.7*(1-a)^2 (1-a)^2 (1-a)/2]);
   hold on; 

end
 
str=sprintf('B.m. with drift %1.1f; Girsanov says darker curves are more likely',mu); 

title(str);
hold off