%martingale representation of exp(sigma*B(1))
sigma=1;

dt=0.0001;
t=[0:dt:1];
n=size(t);
n=n(2);

clf reset;
 
Bmt = cumsum(sqrt(dt)*randn(1,n));
plot(t,Bmt(1:n),'Color',[0 0 0]);
hold on;
   
Bmtr=Bmt(1:n-1); 
inand=zeros(1,n-1);
rmax=zeros(1,n-1);
rmax(1)=max(0,Bmt(1));
for i=2:n-1
    rmax(i)=max(Bmt(i),rmax(i-1)); %running max
end

eBmt=exp(Bmt); 

inand=sigma*exp(sigma*Bmtr+0.5*sigma^2*(1-t(1:n-1))); %integrand
intor=Bmt(2:n)-Bmt(1:n-1); %integrator
pr=inand.*intor;
It=cumsum(pr); %integral

plot(t, eBmt, 'Color',[0 0 1]);
%plot(t(1:n-1), inand, 'Color',[0 1 0]);
plot(t(1:n-1), exp(sigma^2/2)+It, 'Color',[1 0 0]);
legend('B_t', 'exp(\sigma B_t)', 'integral','Location', 'northeastoutside');
hold on;
   
title('Martingale representation of exp(\sigma B_1)');
 

  