Page 1 of 1

Averaging simulated matrices

Posted: Thu Jun 19, 2014 7:54 am
by rbelhach95
Dear Tom,

I have 5000 simulated matrices, please see the code below, I would like to take the average of generated 5000 matrices Call(i,j) to get the matrix Call of size MxP. Please advise. Many thanks

Code: Select all

OPEN DATA "C: \ Desktop\ R1newset.xls"
DATA(FORMAT=xls,ORG = Col) / R1  
OPEN DATA "C: \ Desktop\ Data_T1.xls"
DATA(FORMAT=xls,ORG=COL) 1 10964 S T1 div r2 T2 K
com M = 61, P=10964
dec rec  T3 ST Call Rtstr
dim T3(M,P)  Rtstr(M,P) ST(M,P) Call(M,P)
do rep  = 1, 5000
.......
* replicate 5000 returns
........
boot entries 1 61 1 65360
set draw 1 61 = R1(entries)
ewise T3(i,j) = T2(j)-T1(i)
ewise Rtstr(i,j) = (r2(i)-div(i)+draw(i))*T3(i,j)/365
ewise ST(i,j) = %if(T3(i,j)>0, S(i)*exp(Rtstr(i,j)),%na)
ewise Call(i,j) = %if(T3(i,j)>0,exp(-r2(i)*T3(i,j)/365)*%max(0,ST(i,j)-K(j)),%na)        
end do rep








Re: Averaging simulated matrices

Posted: Thu Jun 19, 2014 9:53 am
by TomDoan
Outside the loop

compute callsum=%zeros(m,p)

inside after the ewise call...

compute callsum=callsum+call

Re: Averaging simulated matrices

Posted: Thu Jun 19, 2014 11:29 am
by rbelhach95
Thanks a lot Tom. Since it is the average that I am seeking, I need to add this outside the loop
callaverage = callsum/5000, is this correct?

Thanks

Re: Averaging simulated matrices

Posted: Thu Jun 19, 2014 11:42 am
by TomDoan
Yes.

Re: Averaging simulated matrices

Posted: Thu Jun 19, 2014 12:15 pm
by rbelhach95
Thank you so much