Page 1 of 1

Draw vertical lines at specific observations of time series

Posted: Sat Aug 15, 2015 4:09 am
by tho_mi
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

Re: Draw vertical lines at specific observations of time ser

Posted: Sat Aug 15, 2015 2:38 pm
by EViews Gareth
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.

Re: Draw vertical lines at specific observations of time ser

Posted: Thu Aug 20, 2015 8:20 am
by tho_mi
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.

Re: Draw vertical lines at specific observations of time ser

Posted: Tue Aug 25, 2015 6:14 am
by tho_mi
Any other recommendations?

Re: Draw vertical lines at specific observations of time ser

Posted: Tue Aug 25, 2015 8:42 am
by EViews Jason
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

Re: Draw vertical lines at specific observations of time ser

Posted: Tue Nov 10, 2015 8:49 am
by tho_mi
Sorry for the very late reply. Your solution/recommendation works, thanks a lot!