I told people I was good at EViews, but now I need help.

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Samuel1989
Posts: 2
Joined: Sun Mar 19, 2017 2:08 pm

I told people I was good at EViews, but now I need help.

Postby Samuel1989 » Sun Mar 26, 2017 11:18 am

i have a quite tricky problem for you which really needs some experience. Has anybody an approach how to code this? Or general thoughts how this could be solved?

In a Workfile I have the following data:
  • 10 Groups Portfolio1 to Portfolio10 (with no values in it)
  • a group with daily returns of 200 stocks
  • a group with the cumulative 6-month returns of these 200 stocks (frequency: monthly)
  • a group with the daily marketvalues of the 200 stocks


(the series for the daily returns the cumulative returns and the marketvalues have for example the names DR_APPLE CR_APPLE MV_APPLE so the names are for every stock identical). There are the following restrictions

if in a specific month the cumulative 6-month return of a stock is in the top 10% quantile -> copy the value of the daily returns of this stock in month t+1 multiplied with its marketvalue in time t+1 into portfolio 10
else if in this specific year the cumulative 6-month return is in the next decile (10%-band) -> copy the value of the daily return of this stock in t+1 multiplied with its marketvalue in t+1 into portfolio 9
...
else if the cumulative 6-month return is in the worst 10% of the month copy the value of the daily return of this stock in t+1 multiplied with its marketvalue in t+1 in into portfolio 1

I really really need to get this solved. Thank you so much in advance!
Sam
Last edited by Samuel1989 on Tue Apr 04, 2017 1:38 am, edited 4 times in total.

EViews Matt
EViews Developer
Posts: 584
Joined: Thu Apr 25, 2013 7:48 pm

Re: Merging data

Postby EViews Matt » Mon Mar 27, 2017 4:02 pm

Hello,

Below is a starting point for you. Basically, the program determines which stocks belong in which deciles every month, and then uses that information to fill out the portfolio information. For the sake of the code, I've assumed two workfile pages, "Daily" and "Monthly", plus the existence of several groups, "dr_group", "cr_group", and "mv_group", that hold all the respective series (in the same order). I've also assumed the existence of a group, "portfolio_all", holding all the portfolios in ascending ordered, i.e., "porfolio1" ... "porfolio10". Lastly, the code doesn't implement the one month lead in the results, everything is calculated with regard to the same month.

Code: Select all

' The first half of this program creates a matrix, m, that holds the stock indices for all deciles, i.e., ' the first 10% of columns will hold the indices of the bottom decile, the last 10% of columns will ' hold the indices of the top decile, etc. ' Move to the page with cr_group. pageselect Monthly ' A temporary holding the cannonical index ordering, e.g., 1..200. rowvector(cr_group.@count) inc for !i = 1 to inc.@cols inc(!i) = !i next ' Convert all data to a matrix so we may grab individual rows as vectors. matrix tmp = @convert(cr_group) ' Results matrix matrix(tmp.@rows, tmp.@cols) m ' we'll record all the dates on the Monthly page so we can refer to them on the Daily page. svector(tmp.@rows) dates for !i = 1 to tmp.@rows ' For every observation, sort the stock indices by the cumulative return rank. rowplace(m, @rapplyranks(inc, @ranks(@rowextract(tmp, !i))), !i) ' Record the observation's date. dates(!i) = @otod(!i) next ' The second half of the program uses the above data to fill out the portfolio data. ' Move the generated data to the Daily page and clean up temporaries. copy m Daily\m copy dates Daily\dates delete inc tmp m dates ' Move to the page with dr_group and mv_group. pageselect Daily for !i = 1 to @rows(dates) ' Use the monthly dates to create a daily sample. %tmp = dates(!i) smpl if @event(%tmp) for !j = 1 to @columns(m) ' For each month, copy each stock's DR * MV to the portfolio. portfolio_all(!j) = dr_group(m(!i, !j)) * mv_group(m(!i, !j)) next next ' Clean up temporaries. delete m dates

Samuel1989
Posts: 2
Joined: Sun Mar 19, 2017 2:08 pm

I told people I was good at EViews, but now I need help.

Postby Samuel1989 » Tue Mar 28, 2017 6:51 am

Thank you very much for the code. It's really awesome! When I tried to run the code there was an message "Insufficient number of observations". Do you know where the problem could be? (Maybe this is because in the beginning of the range there are many empty values..) Here is the file and the respective program code
Attachments
data.wf1
(20.25 MiB) Downloaded 247 times
Last edited by Samuel1989 on Tue Apr 04, 2017 1:34 am, edited 3 times in total.

EViews Matt
EViews Developer
Posts: 584
Joined: Thu Apr 25, 2013 7:48 pm

Re: Merging data

Postby EViews Matt » Wed Mar 29, 2017 11:54 am

Missing data caused issues with my use of @convert, as well as a lot of other assumptions I had about your data. I've updated the script (attached), including having it create the portfolio structures that are initially incomplete in your workfile.
Attachments
portfolio.prg
(3.15 KiB) Downloaded 302 times


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests