Draw vertical lines at specific observations of time series

For questions regarding programming in the EViews programming language.

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

tho_mi
Posts: 61
Joined: Sat May 12, 2012 2:41 am

Draw vertical lines at specific observations of time series

Postby tho_mi » Sat Aug 15, 2015 4:09 am

Hey guys,

I've got a question to drawing vertical lines. Basically I have three variables.

1. finseries containing data on some (financial) time series
2. peak - 1 if a given date is a peak, 0 otherwise
3. trough - 1 if a given date is a trough, 0 otherwise

I'd like to draw the time series and mark the peaks and troughs with vertical lines (in different colors would be nice).
My sample starts in 1960Q1 and goes until 2014Q3.

The problem is the following. Drawing lines itself is not a problem, but I'm not able to use the "correct" place. If I use the number of the observation EViews seems to try to convert it to the year and prints it there and if I try to use for example 70,5 (1970Q2) the line is not drawn at all.

Here's my code (including the calculation of peaks and troughs):

Code: Select all

!length = @obsrange series finseries = credit_cycle series peak = 0 series trough = 0 graph gr1 finseries !tp = 0 ' tp indicates whether the last turning point was a peak (1) or a trough (-1) gr1.line("a") for !i = 3 to !length-3 step 1 if !tp <> 1 and (finseries(!i) - finseries(!i-2) > 0) and (finseries(!i) - finseries(!i-1) > 0) and (finseries(!i+2) - finseries(!i) < 0) and (finseries(!i+1) - finseries(!i) < 0) then peak(!i) = 1 !tp = 1 gr1.draw(line, bottom) !i endif if !tp <> -1 and (finseries(!i) - finseries(!i-2) < 0) and (finseries(!i) - finseries(!i-1) < 0) and (finseries(!i+2) - finseries(!i) > 0) and (finseries(!i+1) - finseries(!i) > 0) then trough(!i) = 1 !tp = -1 gr1.draw(line, bottom) !i endif next
Except from the "gr1.draw(line, bottom) !i" everything work's fine. Could anyone tell me how I'm able to
1. draw the lines at the correct date and
2. draw the lines not just at one year itself, but also for specific quarters.

Thanks in advance!

Best,
Thomas

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Draw vertical lines at specific observations of time ser

Postby EViews Gareth » Sat Aug 15, 2015 2:38 pm

I'm not sure I follow your program, or what you're trying to do exactly, but it may be that you want to use the @otod function to convert an observation number into a date string, then use the date string in the line command.

tho_mi
Posts: 61
Joined: Sat May 12, 2012 2:41 am

Re: Draw vertical lines at specific observations of time ser

Postby tho_mi » Thu Aug 20, 2015 8:20 am

Thanks for your reply!
The program computes local minima and maxima and draws lines at the specific points. I'll try @otod and let you know whether it works or not.

edit:
Using the same code just with "@otod(!i)" instead of "!i" I get a graph with no lines at all.

tho_mi
Posts: 61
Joined: Sat May 12, 2012 2:41 am

Re: Draw vertical lines at specific observations of time ser

Postby tho_mi » Tue Aug 25, 2015 6:14 am

Any other recommendations?

EViews Jason
EViews Developer
Posts: 870
Joined: Tue Sep 16, 2008 3:50 pm

Re: Draw vertical lines at specific observations of time ser

Postby EViews Jason » Tue Aug 25, 2015 8:42 am

Try storing the @otod value into a string and then use that string in the draw command. The draw command is not processing the @otod function

Code: Select all

create m 90 10 series x=rnd freeze(g) x.line %date = @otod(100) 'the 100th observation g.draw(line, bottom) %date

tho_mi
Posts: 61
Joined: Sat May 12, 2012 2:41 am

Re: Draw vertical lines at specific observations of time ser

Postby tho_mi » Tue Nov 10, 2015 8:49 am

Sorry for the very late reply. Your solution/recommendation works, thanks a lot!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest