Page 1 of 1

last day of a month

Posted: Tue Jul 14, 2020 12:27 pm
by superjocker
Hi, I am trying to sample the last day of each month in a daily series. is there a way to do it?

Thanks

Re: last day of a month

Posted: Tue Jul 14, 2020 12:29 pm
by EViews Gareth

Code: Select all

smpl if @month<>@month(1)
(i.e. if the month doesn't equal tomorrow's month)

Re: last day of a month

Posted: Tue Jul 14, 2020 12:53 pm
by superjocker
Thanks, you know it all. I have another question, how do you get the returns for a month, taking into account that some months have 31 days, others 30 and some 28 or 29?

Thanks

Re: last day of a month

Posted: Tue Jul 14, 2020 1:31 pm
by EViews Gareth
I think I would build an index series, that resets to 100 on the first of the month, and compounds the daily returns, then compute the return based on the value of the index at the end of the month. Something like (and this is off the top of my head, so might need adjustment):

Code: Select all

series index = @recode(@day=1, 100, index(-1)*(1+return)) series monthreturn = @recode(@month<>@month(1), index/100, na)

Re: last day of a month

Posted: Wed Jul 15, 2020 7:51 am
by superjocker
Yes, thank you, it works.

Regards

Re: last day of a month

Posted: Wed Jul 15, 2020 11:05 am
by superjocker
I made some changes to part of your code to make it work, here it is in case anybody needs it.

series return1 = @recode(@month<>@month(1), stockprice, na)
series return2= @recode(return1=na, return2(-1), return1)
series return3=(return2-return2(-1))/return2(-1)
series return4 = @recode(@month<>@month(1), return3, na)

then delete return 1, 2 y 3 and sample
smpl if @month<>@month(1)

thank you