Page 1 of 1
Summing elements of vector series
Posted: Tue Nov 25, 2014 8:46 am
by rbelhach95
Dear Tom,
I have a vector series R(rep) of 5000 monthly returns, I used
Code: Select all
sample(smpl=%valid(R(rep))) R(rep) / goodsource
to throw away the NAs. I would like to randomly sum up 12 of these goodsource returns, then replicate this process 61 times, i.e. obtain 61 annual returns
Please advise. Thank you
Rachid
Re: Summing elements of vector series
Posted: Tue Nov 25, 2014 10:55 am
by TomDoan
This will do the sum for one set of 12. You would just have to loop over the last two instructions.
Code: Select all
sample(smpl=%valid(R(rep))) R(rep) / goodsource
compute goodnobs=%nobs
boot entries 1 12 1 %nobs
sstats 1 12 goodsource(entries(t))>>sumof12
Re: Summing elements of vector series
Posted: Tue Nov 25, 2014 11:56 am
by rbelhach95
Many thanks for your help. I have the ewise instruction in my code below, how do I loop over those two instruction? I would like sumof12 to be as shown in my code (Rtstr(i,j)) but it gives error. Thanks
Rachid
Code: Select all
com N= 5000, M= 61, P=1000
dec rec T3 ST Call Rtstr Callav
dim T3(M,P) Rtstr(M,P) ST(M,P) Call(M,P) Callav(M,P)
.........
sample(smpl=%valid(R(rep))) R(rep) / goodsource
compute goodnobs=%nobs
boot entries 1 12 1 %nobs
sstats 1 12 goodsource(entries(t))>>sumof12
ewise T3(i,j) = T2(j)-T1(i)
ewise Rtstr(i,j) = (r2(i)-div(i)+sumof12(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)
com Callsum = Callsum+Call
end do rep
com Callav = Callsum/N
Re: Summing elements of vector series
Posted: Tue Nov 25, 2014 1:43 pm
by TomDoan
Code: Select all
sample(smpl=%valid(R(rep))) R(rep) / goodsource
compute goodnobs=%nobs
dec vect sumof12(m)
do i=1,m
boot entries 1 12 1 goodnobs
sstats 1 12 goodsource(entries(t))>>sumof12(i)
end do i
Re: Summing elements of vector series
Posted: Tue Nov 25, 2014 5:11 pm
by rbelhach95
Thanks a lot Tom
Rachid