Manipulation of Sums using SSTATS

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

Manipulation of Sums using SSTATS

Unread post by rbelhach95 »

Dear Tom,

I would like to implement the following: Please see the code below.

I have R1 returns simulated N=5000 times, my option database consists of 10964 quotations, these quotations are divided into 60 sets of different maturities e.g. I have, T3= 21 days, T3=49 days, T3= 77 day, etc....Below I have used the sstats instruction to, for example, pick a random draw of 21 values among 500,000 randoms numbers and then adding 21 values, this methodology need to be implemented for all the 60 different maturities. By estimating the time it will take for the whole database based on what it took me for T3= 21 days:
5573 hours for 10,000 simulations
928 hours for 1000 simulations

My question is the following: Is there a way to manipulate these sub-matrices to shorten the time?
Many thanks
Rachid

Code: Select all

DATA(FORMAT=xls,ORG=COL) 1 138 S T1 div r2 T2 K
com M = 61, P=10964, N=5000
com Callsum = %zeros(M,P)
dec rec T3 ST Call Rtstr Callav
dim T3(M,P) Rtstr(M,P) ST(M,P) Call(M,P)  Callav(M,P)
dec vect[series] R1(N)

do rep = 1,N
.....
set R1(rep) = risk-neutral returns
sample(smpl=%valid(R1(rep))) R1(rep) / goodsource 1
compute goodnobs = %nobs
boot entries 1 21 1 goodnobs
sstats 1 21 goodsource(entries(t))>>sumof21
ewise T3(i,j) = T2(j)-T1(i)
ewise Rtstr(i,j) = S(i)*exp((r2(i)-div(i))*T3(i,j)/365+sumof21)
ewise ST(i,j) = %if(T3(i,j)>0,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)
com Callsum = Callsum+Call
end do rep
com Callav = Callsum/N
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Manipulation of Sums using SSTATS

Unread post by TomDoan »

The main problem isn't with what you posted, but with the ... that you omitted. I get an estimate of about 2 hours if I just draw random values for r1. You can clean what you have up a bit by recognizing that most of

ewise T3(i,j) = T2(j)-T1(i)
ewise Rtstr(i,j) = S(i)*exp((r2(i)-div(i))*T3(i,j)/365+sumof21)
ewise ST(i,j) = %if(T3(i,j)>0,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)

is using data rather than simulations. For instance, T3 is the same for all simulations, so you can pull that outside the loop and do it just once. Similarly s(i)*exp(..../365) can be computed once, so you only have to multiply it by exp(sumof21) inside the loop, exp(...) in the final expression similarly can be outside the loop. That will probably cut that down to maybe an hour. But again, it's the ... that's the hot spot of the calculation.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Manipulation of Sums using SSTATS

Unread post by rbelhach95 »

Many Thanks for your feedback. What you suggested will definitely shorten the time, but the difficulty that I am having is in this part of the code

Code: Select all

compute goodnobs = %nobs
boot entries 1 21 1 goodnobs
sstats 1 21 goodsource(entries(t))>>sumof21
As I mentioned in my last post, I have a collection of 60 different maturities, how can I use sstats to generate sumof21, somof49, sumof77, ...,sumof2133, in this succession which will give me the first column of the matrix of size MxP?
Thanks
Rachid
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Manipulation of Sums using SSTATS

Unread post by TomDoan »

Each BOOT instruction will draw a completely independent set of entry numbers. Wouldn't you want the entries used for the first 21 to be used for the first 49, first 77, etc? If so, you would want one BOOT over the full 2133. Given that you are just summing, create the bootstrapped returns and do an ACCUMULATE to get running sums and pull out the values that you need (the 21st, the 49th, etc.) Create a VECT[INT] with the locations where you want to sample and use that to pick out the values from the running sum series.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Manipulation of Sums using SSTATS

Unread post by rbelhach95 »

Many thanks Tom for your useful input, I will try what you suggested.
Rachid
Post Reply