Averaging simulated matrices

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Averaging simulated matrices

Unread post 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







TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Averaging simulated matrices

Unread post by TomDoan »

Outside the loop

compute callsum=%zeros(m,p)

inside after the ewise call...

compute callsum=callsum+call
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Averaging simulated matrices

Unread post 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
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Averaging simulated matrices

Unread post by TomDoan »

Yes.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Averaging simulated matrices

Unread post by rbelhach95 »

Thank you so much
Post Reply