a quick question

For questions regarding programming in the EViews programming language.

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

Fregensburg
Posts: 38
Joined: Tue Jan 21, 2014 4:04 am

a quick question

Postby Fregensburg » Thu May 29, 2014 9:01 am

Dear all

This is the context: I have a time series of prices for asset y. I have a model to estimate the ‘fair value’ –however embarassing that terminology is- estimates of y, which I get from the fitted values of a regression of y onto what I think help explains its short run fluctuations.. By substracting the fair value from the actual assets, I get another time series X which I interpret as misalignment.

Then I make the claim that a positive misalignment (i.e. the asset exceeding its fair value) should cause a depreciation of the assets in the near future (say 1, 2, 3 weeks horizon). The equation I have in mind is
dlog(Y t,n) = a + BX t + e t
and B should be negative if the model is sort of ok.

What I want to do is using the forecasting equation above to measure the predictive value of misalignment. I have a data set spanning 2009-present, and I want to do one-step ahead forecasts for a subsample of say 2012-present. I want to look at the size of the coefficient B as well as its significance level for 1,2,3 and 4 weeks changes in log X.
Does anyone have any suggestions on the right type of procedure to get the forecasts and associated statistics?

Many thanks

EViews Glenn
EViews Developer
Posts: 2671
Joined: Wed Oct 15, 2008 9:17 am

Re: a quick question

Postby EViews Glenn » Thu May 29, 2014 11:16 am

From your description it sounds as though you just want to estimate an equation with dlog Y as the dependent variable at different lags. You can do so by specifying a dependent variable as @dlog(y, n) where n is your lag. You should use the full expression as the dependent variable rather than generating a new series. Once you estimate your equation that just look at the results of the equation for your significance and use the forecast proc to get the forecasts. Since the only thing on the RHS of your equation is X_t which is static, the standard static forecast will give you the one-step ahead using realized Y_{t-1} values.

Fregensburg
Posts: 38
Joined: Tue Jan 21, 2014 4:04 am

Re: a quick question

Postby Fregensburg » Fri May 30, 2014 6:27 am

Won't the procedure you outlined only give me the static forecast, though, rather than the forecasts and their associated stats?
I am trying to replicate the method used in pages 8-9 in this research note:

http://www.morganstanley.com/institutio ... 120927.pdf

Specifically, the beginning of the second column of page 8, described further in the first three paragraphs of page 9, with results in Exhibit 4. The author claims to be doing out of sample forecasts, but I think that what he does, instead, is have a full series of regressors (that is, Zxy in from (14)), which I've already estimated) and then doing -I think- one step ahead rolling regressions over the forecast window. But I'm really unsure. Will be super-grateful for your suggestions, as I'm kind of stuck.

EViews Glenn
EViews Developer
Posts: 2671
Joined: Wed Oct 15, 2008 9:17 am

Re: a quick question

Postby EViews Glenn » Sat May 31, 2014 7:11 am

Ah, you want rolling regression. Wasn't clear (at least to me) from the original posting. There are lots of posts in the forum on rolling regression. Just do a quick search.

Fregensburg
Posts: 38
Joined: Tue Jan 21, 2014 4:04 am

Re: a quick question

Postby Fregensburg » Tue Jun 03, 2014 8:14 am

Thanks, I've had a crack at this, trying to replicate some of the results in exhibit 4, p.9 following what I think the authors of the research note did, but I get error messages stating that "Unable to compute due to missing data in "DO_ EQFR.FORECAST(F=NA) YF"
I'm nowhere near the level of proficiency to see what I'm doing wrong, and I'm hoping you'd be so kind to point me in the right direction. Here is the code (please find the workfile attached at the bottom of this email):

'change path to program path
%path = @runpath
cd %path
'create workfile

wfcreate misalignment D(1,5) 01/29/2009 12/31/2015
read(a2,s=Sheet2) H:\misalignment\eurusd.xls 34
read(a2,s=Sheet3) H:\misalignment\eurusd.xls 14

smpl @all

equation eqlevel2.ls(cov=hac) log(eurusd) c _2yrspread log(sp500) log(eurstoxx50-sp500) vix relativeyieldcurve cdsperifcorespread cdsitspcentrespread cdsportugirelndcentrespr

eqlevel2.forecast fittedeurusd

equation eqjpyusd.ls(cov=hac) log(jpyusd) c _2yspreadjpyusd log(sp500) log(Nikkei-sp500) vix relycurvejpyusd

eqjpyusd.fit fittedjpyusd

series seurjpy = log(eurusd)-log(jpyusd)
series sfveurjpy = log(fittedeurusd)-log(fittedjpyusd)

series miseurusd = log(eurusd)-log(fittedeurusd)
series miseurjpy = log(eurjpy)-sfveurjpy

series fullsamplesigma = @stdev(miseurjpy)

!maxerr = @maxerrcount
setmaxerrs !maxerr+5000

' set window size
!window = 1000
' set step size
!step = 1
' get size of workfile
!length = @obsrange
'declare equation for estimation
equation eqfr
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'matrix to store coefficient estimates
matrix(2,!nrolls) coefmat ' where 2 is the number of coefficients
'series to store forecast estimates
series fcast
'catching start and end points
%start = "@first" '@otod(@ifirst(ser))
%end = "@last" '@otod(@ilast(ser))
'variable keeping track of how many rolls we've done
!j=0
' move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
' set sample for estimation period
%first = @otod(@dtoo(%start)+!i)
%last = @otod(@dtoo(%start)+!i+!window-1)
smpl {%first} {%last}
' estimate equation
eqfr.ls dlog(seurjpy,5) c miseurjpy
' store coefficients
colplace(coefmat,eqfr.@coefs,!j)
' 1-period-ahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window-1) 'start point
%1pere = @otod(@dtoo(%start)+!i+!window) 'end point
if @dtoo(%end) < @dtoo(%1pere) then
'check whether the forecast end point is greater than the workfile end point
exitloop
endif
' set smpl for forecasting period
smpl {%1pers} {%1pere}
' forecast with command *forecast* (see also *fit*)
eqfr.forecast(f=na) yf
' set sampl to obtain the 1 period observation
smpl {%1pere} {%1pere}
' store forecasts
fcast = yf
next
Attachments
misalignment.wf1
(668.84 KiB) Downloaded 230 times

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

Re: a quick question

Postby EViews Gareth » Tue Jun 03, 2014 8:23 am

You're forecasting over a period for which you do not have values for miseurjpy. Thus the equation cannot be forecasted.
Follow us on Twitter @IHSEViews

Fregensburg
Posts: 38
Joined: Tue Jan 21, 2014 4:04 am

Re: a quick question

Postby Fregensburg » Tue Jun 03, 2014 8:47 am

I have 1394 observations for miseurjpy
I must be wrong but, isn't this (the point where the program starts forecasting) : %1pers = @otod(@dtoo(%start)+!i+!window-1),
the 1000th data point? If not, what is?

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

Re: a quick question

Postby EViews Gareth » Tue Jun 03, 2014 9:05 am

The first time through the loop, yes the forecast starts at 1000. The 2nd time through the loop it starts at 1001. The 395th time through the loop it starts at 1394. That's when you get an error.
Follow us on Twitter @IHSEViews

Fregensburg
Posts: 38
Joined: Tue Jan 21, 2014 4:04 am

Re: a quick question

Postby Fregensburg » Tue Jun 03, 2014 9:35 am

Ok, thanks.

To other users: I found that this, as the end point of the forecast sample, seems to work:

!date = @ilast(miseurjpy)
%pere = @otod(!date)

Gareth,
is there a quick way to get seurjpy from "dlog(seurjpy,5)"? Correct me if I'm wrong, but if I used dlog(seurjpy) I would get seurjpy. Obviously eviews does its job in giving 5 days currency appreciation if what I ask for is 5 days currency appreciation. Just wondering if there's a way to ondo that expression to seurjpy.

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

Re: a quick question

Postby EViews Gareth » Tue Jun 03, 2014 9:37 am

I have no idea what that question is asking me.
Follow us on Twitter @IHSEViews

trubador
Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: a quick question

Postby trubador » Tue Jun 03, 2014 1:54 pm

The easiest way to do is using the genr function:

Code: Select all

'Suppose dy represents dlog(seurjpy,5)
smpl @first @first+4
series y = seurjpy
smpl @first+5 @last
genr dlog(m,5) = dy
smpl @all


Please note that five days change in the currency would equal to:

Code: Select all

dlog(seurjpy,0,5) = log(seurjpy) - log(seurjpy(-5))

The formula you used represents the fifth-order difference:

Code: Select all

dlog(seurjpy,5) = d(d(d(d(dlog(seurjpy)))))

So, in the first case the following formula will give you the original series:

Code: Select all

@first @first+4
series y = seurjpy
smpl @first+5 @last
series y = exp(log(y(-5)) + dlog(seurjpy,0,5))

In the second case:

Code: Select all

@first @first+4
series y = seurjpy
smpl @first+5 @last
series y = exp(5*log(y(-1)) - 10*log(y(-2)) + 10*log(y(-3)) - 5*log(y(-4)) + log(y(-5)) + dlog(seurjpy,5))

Fregensburg
Posts: 38
Joined: Tue Jan 21, 2014 4:04 am

Re: a quick question

Postby Fregensburg » Thu Jun 05, 2014 5:31 am

Trubador,

As usual, your answers are exhaustive and to the point. Many thanks


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 23 guests