-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a73b3d3
commit 9a5433a
Showing
9 changed files
with
43 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
Package: Rtauchen | ||
Type: Package | ||
Title: Discretization of AR(1) processes using the method by Tauchen (1986) | ||
Title: Discretization of AR(1) Processes using the Method by Tauchen | ||
(1986) | ||
Version: 1.0 | ||
Date: 2016-08-01 | ||
Author: David Zarruk Valencia & Rodrigo Azuero Melo | ||
URL: https://github.com/rodazuero/Rtauchen | ||
URL: https://github.com/davidzarruk/Rtauchen | ||
Maintainer: David Zarruk Valencia <davidzarruk@gmail.com> | ||
Description: Method for discretizing AR(1) processes by choosing a finite set of points and transition probabilities, so the resulting finite-state Markov Chain mimics the original process. | ||
Description: Description: Discretize AR process. | ||
License: GPL (>= 2) | ||
Imports: stats, pnorm | ||
Packaged: 2016-08-04 21:56:05 UTC; rodrigoazuero | ||
Imports: stats | ||
Packaged: 2016-08-05 21:47:04 UTC; rodrigoazuero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
exportPattern("^[[:alpha:]]+") | ||
importFrom("stats", "pnorm") | ||
importFrom("stats","pnorm") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,41 @@ | ||
|
||
# Corro un archivo con los parametros | ||
|
||
Tgrid = function(n, ssigma, llambda, m){ | ||
Tgrid=function(ne, ssigma_eps, llambda_eps, m){ | ||
|
||
grid = array(0, dim = n) | ||
ssigma_y = sqrt(ssigma^2/(1-llambda^2)) | ||
grid = array(0, dim = ne) | ||
ssigma_y = sqrt(ssigma_eps^2/(1-llambda_eps^2)) | ||
|
||
estep = 2*ssigma_y*m / (n-1) | ||
for(ii in 1:1:n){ | ||
grid[ii] = -m*sqrt((ssigma^2)/(1-llambda^2)) + (ii-1)*estep | ||
estep = 2*ssigma_y*m / (ne-1) | ||
for(ii in 1:1:ne){ | ||
grid[ii] = -m*sqrt((ssigma_eps^2)/(1-llambda_eps^2)) + (ii-1)*estep | ||
} | ||
return(grid) | ||
return(grid) | ||
} | ||
|
||
Tmatrix = function(n, ssigma, llambda, m){ | ||
Rtauchen=function(ne, ssigma_eps, llambda_eps, m){ | ||
|
||
grid = Tgrid(n, ssigma, llambda, m) | ||
grid = Tgrid(ne, ssigma_eps, llambda_eps, m) | ||
|
||
if(n > 1){ | ||
if(ne > 1){ | ||
w = grid[2] - grid[1] | ||
P = array(0, dim = c(n,n)) | ||
P = array(0, dim = c(ne,ne)) | ||
|
||
for(jj in 1:n){ | ||
for(kk in 1:n){ | ||
for(jj in 1:ne){ | ||
for(kk in 1:ne){ | ||
if(kk == 1){ | ||
P[jj,kk] = pnorm((grid[kk] - llambda*grid[jj]+(w/2))/ssigma) | ||
P[jj,kk] = pnorm((grid[kk] - llambda_eps*grid[jj]+(w/2))/ssigma_eps) | ||
} | ||
else if(kk == n){ | ||
P[jj,kk] = 1- pnorm((grid[kk] - llambda*grid[jj]-(w/2))/ssigma) | ||
else if(kk == ne){ | ||
P[jj,kk] = 1- pnorm((grid[kk] - llambda_eps*grid[jj]-(w/2))/ssigma_eps) | ||
} | ||
else{ | ||
P[jj,kk] = pnorm((grid[kk] - llambda*grid[jj]+(w/2))/ssigma)-pnorm((grid[kk] - llambda*grid[jj]-(w/2))/ssigma) | ||
P[jj,kk] = pnorm((grid[kk] - llambda_eps*grid[jj]+(w/2))/ssigma_eps)-pnorm((grid[kk] - llambda_eps*grid[jj]-(w/2))/ssigma_eps) | ||
} | ||
} | ||
} | ||
} else{ | ||
P = 1 | ||
} | ||
return(P) | ||
} | ||
|
||
|
||
|
||
nTgrid = function(n, ssigma, llambda, m, dim){ | ||
|
||
n = 9 | ||
m = 3 | ||
dimension = dim(ssigma) | ||
grid = array(0, dim = c(dimension[1], n)) | ||
|
||
llambda = array(c(0.7, 0.2, 0.3, 0.5), dim = c(2,2)) | ||
ssigma = array(c(0.1, 0, 0, 0.1), dim = c(2,2)) | ||
|
||
ssigma_y = array(0, dim = c(dimension[1], dimension[1])) | ||
error = 1 | ||
tol = 10^-5 | ||
while(error > tol){ | ||
ssigma_y_p = llambda%*%ssigma_y%*%t(llambda) + ssigma | ||
error = norm(ssigma_y_p - ssigma_y) | ||
ssigma_y = ssigma_y_p | ||
} | ||
|
||
for(jj in 1:1:dimension[1]){ | ||
estep = 2*sqrt(ssigma_y[jj, jj])*m / (n-1) | ||
for(ii in 1:1:n){ | ||
grid[jj, ii] = -sqrt(ssigma_y[jj, jj])*m + (ii-1)*estep | ||
} | ||
} | ||
|
||
|
||
return(grid) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,4 @@ | ||
library(Rtauchen) | ||
|
||
# This example computes the grid of points of the finite-state Markov chain approximation of an AR(1) process with: | ||
# n = 5 points in the Markov chain | ||
# ssigma = 0.02 | ||
# lambda = 0.95 | ||
# m = 3 | ||
results = Tgrid(5, 0.02, 0.98, 3) | ||
|
||
results | ||
# [1] -0.3015113 -0.1507557 0.0000000 0.1507557 0.3015113 | ||
# Include description here | ||
results = Rtauchen(2, 1.0e-5, 0.1,0.4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters