Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
DynareJulia
Dynare.jl
Commits
17ead971
Commit
17ead971
authored
Jul 28, 2020
by
MichelJuillard
Browse files
adding deteministic trends
parent
f4066cfb
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/parser/DynareParser.jl
View file @
17ead971
...
...
@@ -182,7 +182,6 @@ function parser(modfilename)
elseif
field
[
"statementName"
]
==
"initval"
initval!
(
field
)
elseif
field
[
"statementName"
]
==
"native"
@show
field
[
"string"
]
expr
=
Meta
.
parse
(
field
[
"string"
])
eval
(
expr
)
native_statement
(
field
)
...
...
@@ -269,9 +268,7 @@ function histval!(context, field, symboltable)
l
=
m
.
orig_maximum_lag
-
v
[
"lag"
]
histval
[
l
,
k
]
=
Meta
.
parse
(
v
[
"value"
])
end
@show
histval
context
.
work
.
histval
=
histval
@show
context
.
work
.
histval
end
function
initval!
(
field
)
...
...
@@ -368,9 +365,11 @@ function stoch_simul!(context, field)
B
=
zeros
(
model
.
endogenous_nbr
,
model
.
exogenous_nbr
)
make_A_B!
(
A
,
B
,
model
,
results
)
simul_first_order!
(
simulresults
,
y0
,
x
,
c
,
A
,
B
,
periods
)
@show
simulresults
if
work
.
model_has_trend
simulresults
.+=
transpose
(
results
.
endogenous_trend
[
:
,
1
])
.+
collect
(
0
:
size
(
simulresults
,
1
)
-
1
)
*
transpose
(
results
.
endogenous_trend
[
:
,
2
])
end
@show
simulresults
first_period
=
get
(
options
[
"stoch_simul"
],
"first_periods"
,
1
)
endogenous_names
=
[
Symbol
(
n
)
for
n
in
get_endogenous_longname
(
context
.
symboltable
)]
data
=
TimeDataFrame
(
simulresults
,
Periods
.
Undated
,
first_period
,
endogenous_names
)
...
...
@@ -554,7 +553,7 @@ function calib_smoother!(context, field, varobs, varobs_ids)
copy!
(
options
[
"calib_smoother"
],
field
[
"options"
])
file
=
get
(
options
[
"calib_smoother"
],
"datafile"
,
""
)
if
(
filename
=
get
(
options
[
"calib_smoother"
],
"datafile"
,
""
))
!=
""
Yorig
=
get_data
(
filename
,
varobs
)
Yorig
=
get_data
(
filename
,
varobs
,
options
[
"calib_smoother"
]
)
else
error
(
"calib_smoother needs a data file or a TimeDataFrame!"
)
end
...
...
@@ -599,7 +598,7 @@ function calib_smoother!(context, field, varobs, varobs_ids)
for
i
=
1
:
nobs
push!
(
data_pattern
,
findall
(
Y
[
:
,
i
]
.!=
NaN
))
end
if
count
(
results
.
stationary_variables
)
==
0
if
count
(
results
.
stationary_variables
)
==
model
.
endogenous_nbr
kws
=
KalmanSmootherWs
{
Float64
,
Int64
}(
ny
,
ns
,
model
.
exogenous_nbr
,
nobs
)
kalman_smoother!
(
Y
,
c
,
Z
,
H
,
d
,
T
,
R
,
Q
,
a0
,
att
,
P
,
Ptt
,
alphah
,
epsilonh
,
etah
,
Valpha
,
Vepsilon
,
Veta
,
start
,
last
,
presample
,
...
...
@@ -666,23 +665,23 @@ function deterministic_trends!(context, field)
end
end
function
get_data
(
filename
,
variables
)
function
get_data
(
filename
,
variables
,
options
)
df
=
DataFrame
(
CSV
.
File
(
filename
))
if
uppercase
(
names
(
df
)[
1
])
in
[
"COLUMN1"
,
"DATE"
,
"DATES"
,
"PERIOD"
,
"PERIODS"
]
frequency
=
identify_period_frequency
(
uppercase
(
df
[
1
,
1
]))
else
frequency
=
Periods
.
Undated
firstperiod
=
1
end
ny
=
length
(
variables
)
nobs
=
size
(
df
,
1
)
-
1
start
=
1
last
=
nobs
start
=
get
(
options
,
"first_obs"
,
1
)
last
=
get
(
options
,
"last_obs"
,
size
(
df
,
1
)
-
start
+
1
)
nobs
=
last
-
start
+
1
Y
=
Matrix
{
Float64
}(
undef
,
ny
,
nobs
)
for
(
i
,
v
)
in
enumerate
(
variables
)
Y
[
i
,
:
]
.=
df
[
start
+
1
:
last
+
1
,
v
]
Y
[
i
,
:
]
.=
df
[
start
:
last
,
v
]
end
return
Y
end
src/parser/deterministic_trends.jl
0 → 100644
View file @
17ead971
struct
Trends
endogenous_steady_state
::
Vector
{
Float64
}
endogenous_linear_trend
::
Vector
{
Float64
}
endogenous_quadratic_trend
::
Vector
{
Float64
}
exogenous_steady_state
::
Vector
{
Float64
}
exogenous_linear_trend
::
Vector
{
Float64
}
exogenous_quadratic_trend
::
Vector
{
Float64
}
exogenous_det_steady_state
::
Vector
{
Float64
}
exogenous_det_linear_trend
::
Vector
{
Float64
}
exogenous_det_quadratic_trend
::
Vector
{
Float64
}
function
Trends
(
ny
,
nx
,
nxd
)
endogenous_steady_state
=
Vector
{
Float64
}(
undef
,
ny
)
endogenous_linear_trend
=
Vector
{
Float64
}(
undef
,
ny
)
endogenous_quadratic_trend
=
Vector
{
Float64
}(
undef
,
ny
)
exogenous_steady_state
=
Vector
{
Float64
}(
undef
,
nx
)
exogenous_linear_trend
=
Vector
{
Float64
}(
undef
,
nx
)
exogenous_quadratic_trend
=
Vector
{
Float64
}(
undef
,
nx
)
exogenous_det_steady_state
=
Vector
{
Float64
}(
undef
,
nxd
)
exogenous_det_linear_trend
=
Vector
{
Float64
}(
undef
,
nxd
)
exogenous_det_quadratic_trend
=
Vector
{
Float64
}(
undef
,
nxd
)
new
(
endogenous_steady_state
,
endogenous_linear_trend
,
endogenous_quadratic_trend
,
exogenous_steady_state
,
exogenous_linear_trend
,
exogenous_quadratic_trend
,
exogenous_det_steady_state
,
exogenous_det_linear_trend
,
exogenous_det_quadratic_trend
)
end
end
function
remove_linear_trend!
(
data_out
,
data_in
,
steady_state
,
linear_trend_coeffs
;
row
=
1
)
n
=
size
(
data_in
,
2
)
linear_trend
=
collect
(
row
-
1
.+
(
1
:
n
))
data_out
.=
data_in
.-
steady_state
.-
linear_trend_coeffs
.*
transpose
(
linear_trend
)
end
function
add_linear_trend!
(
data_out
,
data_in
,
steady_state
,
linear_trend_coeffs
;
row
=
1
)
n
=
size
(
data_in
,
2
)
linear_trend
=
collect
(
row
-
1
.+
(
1
:
n
))
data_out
=
data_in
.+
steady_state
.+
linear_trend_coeffs
.*
transpose
(
linear_trend
)
end
function
remove_quadratic_trend!
(
data_out
,
data_in
,
steady_state
,
linear_trend_coeffs
,
quadratic_trend_coeffs
;
row
=
1
)
n
=
size
(
data_in
,
2
)
linear_trend
=
collect
(
row
-
1
.+
(
1
:
n
))
quadratic_trend
=
collect
(
row
-
1
.+
(
1
:
n
))
.^
2
data_out
=
(
data_in
.-
steady_state
.-
linear_trend_coeffs
.*
transpose
(
linear_trend
)
.-
quadratic_trend_coeffs
.*
transpose
(
quadratic_trend
))
end
function
add_quadratic_trend!
(
data_out
,
data_in
,
steady_state
,
linear_trend_coeffs
,
quadratic_trend_coeffs
;
row
=
1
)
n
=
size
(
data_in
,
2
)
linear_trend
=
collect
(
row
-
1
.+
(
1
:
n
))
quadratic_trend
=
collect
(
row
-
1
.+
(
1
:
n
))
.^
2
data_out
=
(
data_in
.+
steady_state
.+
linear_trend_coeffs
.*
transpose
(
linear_trend
)
.+
quadratic_trend_coeffs
.*
transpose
(
quadratic_trend
))
end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment