*
* @HJBounds( options ) start end mbar bounds
* # list of (gross) returns
*
* HJBounds computes the Hansen-Jagannathan bounds for a set of returns,
* as a function of the unobserved mean of a riskfree asset. Note that
* this computes uncentered second moment bounds.
*
* Parameters:
* start end = range over which to estimate the bounds
* mbar = test values of the mean (input or output)
* bounds = lower bound for second moment as a function of mbar (output)
*
* Options:
* GRID=[AUTOMATIC]/INPUT
* If AUTOMATIC, the mbar series is created by HJBOUNDS for a typical range
* of values (.80 to 1.20). If INPUT, you should define mbar in advance.
* GRAPH/[NOGRAPH]
* Does a graph of the mbar vs bounds
* POSITIVE/[NOPOSITIVE]
* Indicates whether positivity is imposed in the stochastic discount factor
*
* Reference:
* Hansen and Jagannathan(1991), "Implications of Security Market Data for Models
* of Dynamic Economics", JPE, vol 99, pp 225-262.
*
* Revision Schedule:
* 09/2003 Written by Tom Doan, Estima
*
procedure HJBounds start end mbar bounds
type integer start end
type series *mbar *bounds
*
option choice grid 1 automatic input
option switch positive 0
option switch graph 0
*
local series plus
local vect[integer] rlist
local equation retl
local vector v lopphi
*
local vector phi
local parmset naparms
*
local real hjb
local integer mstart mend nlist
local frml nafrml
*
* Get the list of returns
*
enter(varying) rlist
*
* Create the mbar grid
*
if grid==1 {
set mbar 1 101 = .80+.004*(t-1)
compute mstart=1,mend=101
}
else {
inquire(series=mbar) mstart mend
}
*
* Generate an "equation" with 1 and the returns as the explanatory
* variables. We do this so we can use %eqnxvector to pull a time t
* sample of these.
*
equation retl *
# constant rlist
compute nlist=%rows(rlist)
*
* Compute the (inverse of the) cross product of the constant and the
* return vector.
*
cmom start end
# constant rlist
compute %cmom=inv(%cmom)
nonlin(parmset=naparms) phi
*
* The positive solution is obtained by using GMM to solve for phi in
* +
* E (1,R)[(1,R)'phi] = (mbar,ones)
*
* where R is the vector of returns, mbar is the assumed mean, and ones a
* vector of 1's with dimensions the same as R. If we write Z=(1,R), the
* sample moment condition can be written as
*
* (1/T) sum {Z(t)' f(Z(t),phi)} = (mbar,ones)'
*
* We can get this into the proper form for GMM by
*
* (1/T) sum {Z(t)' (f(Z(t),phi) - Z(t) T x inv(Z'Z)(mbar,ones)')}
*
* The term on the right is Z(t) x the law of one price solution for phi,
* which we'll use as the initial guess for the positive solution if
* that's what was requested.
*
clear plus
dim v(%ncmom)
compute v=%const(1.0)
instruments constant rlist
frml nafrml = %max(0,%dot(phi,%eqnxvector(retl,t)))-%dot(lopphi,%eqnxvector(retl,t))
do i=mstart,mend
compute v(1)=mbar(i)
compute phi=lopphi=%nobs*%cmom*v
if .not.positive
compute hjb=%nobs*%qform(%cmom,v)
else {
nlls(frml=nafrml,parmset=naparms,instruments,noprint,iters=100) * start end
*
* The function value should be effectively zero if we had a
* positive solution. If it is, compute the bound. If not, set it
* to NA.
*
if abs(%funcval)<1.e-12 {
set plus start end = %max(0,%dot(phi,%eqnxvector(retl,t)))
compute hjb=%normsqr(plus)/%nobs
}
else
compute hjb=%na
}
set bounds i i = hjb
end do i
*
if graph {
scatter(style=lines,header="Hansen-Jagannathan Bounds")
# mbar bounds mstart mend
}
end