## return calculation

For technical questions regarding estimation of single equations, systems, VARs, Factor analysis and State Space Models in EViews. General econometric questions and advice should go in the Econometric Discussions forum.

Moderators: EViews Gareth, EViews Moderator

shineK
Posts: 24
Joined: Sat Jun 09, 2018 12:23 am
Location: New Taipei City,Taiwan
Contact:

### Re: return calculation

<<URGENT>>
Hi there,

i need to calculate the monthly return by daily data(as attached - RIsna_dwnS_all_cs)
following is the code that i wrote, but the results show lots of NA, please help to check the reason. Thank you so much!!!!!!!!!!

Code: Select all

`%dir="F:\Thesis\Eviews\St12_Ret_mth\dwnSize\2.RIsna"%dir1="F:\Thesis\Eviews\St12_Ret_mth\csv"output(t,o) {%dir1}\out1 'all datawfopen {%dir}\RIsna_dwnS_all_cs.xlsx range=Sheet1 colhead=0 namepos=all na="#N/A" names=("date") @freq D5 12/31/1969 @smpl @allgroup o ser*stomna(o, om)rowvector ds1 = @rowextract(om,1)   '取dscodescalar alfirm = @columns(om)   'count nobs of firmfor !i =1 to 9series w{!i} = series0{!i}nextfor !i =10 to @columns(o)series w{!i} = series{!i}nextfor !i=1 to 9w{!i}(1)=na   '將series第一行變成nanextfor !i=10 to @columns(o)w{!i}(1)=nanextseries Mend = @day(+1) =1for !i = 1 to @columns(o)series riM{!i}= Mend*w{!i}   '找出每個月最後一天的RInextgroup aa riM*for !i =1 to @columns(aa)scalar mcount = 12*(2016-1969)matrix(mcount, 2) m{!i} =namatrix(mcount, 2) ml{!i} =na   'lag!n=0   for !y = 1970 to 2016      for !m=1 to 12      !n=!n+1      smpl if @year=!y and @month=!m      m{!i}(!n, 1)=!y*100+!m      ml{!i}(!n, 1)=!y*100+!m      series riMkk{!i}_!y_!m = na       riMkk{!i}_!y_!m = riM{!i}      series riMLg{!i}_!y_!m = riM{!i}(-1)      stomna(riMkk{!i}_!y_!m, riMk{!i}_!y_!m)      stomna(riMLg{!i}_!y_!m, riML{!i}_!y_!m)      m{!i}(!n, 2)=@sum(riMk{!i}_!y_!m)         if m{!i}(!n, 2) =0 then   'm{!i}(!n, 2) =333         m{!i}(!n, 2) =na         endif      ml{!i}(!n, 2)=@sum(riML{!i}_!y_!m)         if ml{!i}(!n, 2) =0 then   'm{!i}(!n, 2) =333         ml{!i}(!n, 2) =na         endif      smpl @all      next   next   delete rimk*   delete riml*matrix retM{!i}= @ediv(ml{!i}, m{!i})-1vector c1 = @columnextract(m1, 1)   'monthly datecolplace(retM{!i},c1,1)   next'delete w*delete rim*'combine all retMmatrix(mcount, alfirm_act1+1) rrM = nafor !i=1 to @columns(aa)vector cc{!i} = @columnextract(retM{!i},2)colplace(rrM,cc{!i}, !i+1)nextcolplace(rrM,c1,1)rrM.write(t=txt, d=c) F:\Thesis\Eviews\St12_Ret_mth\csv\retM_F_cs.csv`
Attachments
RETM_F_CS.xlsx
result
RIsna_dwnS_all_cs.xlsx
Last edited by shineK on Tue Jul 03, 2018 10:15 pm, edited 1 time in total.
Best,
SK

shineK
Posts: 24
Joined: Sat Jun 09, 2018 12:23 am
Location: New Taipei City,Taiwan
Contact:

### Re: return calculation

Hi all,

Also,
after calculating the monthly return, i need to calculate the annual return by using monthly return, more important is that the annual period is from July t-1 to Jun t, but i do not know how to select this period out to calculate the annual return, really needs help, thanks a lot!!!!!!!!!
Best,
SK

shineK
Posts: 24
Joined: Sat Jun 09, 2018 12:23 am
Location: New Taipei City,Taiwan
Contact:

### Re: return calculation

Hi all,

I solved the monthly return problem, thank you.
But still stuck in the yearly part...
Best,
SK