-
Notifications
You must be signed in to change notification settings - Fork 74
/
Rcpp_main.R
77 lines (55 loc) · 1.49 KB
/
Rcpp_main.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#--------------------------------#
# House-keeping #
#--------------------------------#
.libPaths( c( .libPaths(), "~/R/x86_64-pc-linux-gnu-library/3.4/") )
library("Rcpp")
setwd("/home/david/Dropbox/Documents/Doctorado/Computation course/Codigos/Github Repository/Parallel_Computing_2/")
Sys.setenv("PKG_CXXFLAGS"=" -fopenmp")
# Number of workers
sourceCpp("Rcpp_main.cpp")
#--------------------------------#
# Initialization #
#--------------------------------#
# Grid for x
nx = 1500;
xmin = 0.1;
xmax = 4.0;
# Grid for e: parameters for Tauchen
ne = 15;
ssigma_eps = 0.02058;
llambda_eps = 0.99;
m = 1.5;
# Utility function
ssigma = 2;
bbeta = 0.97;
T = 10;
# Prices
r = 0.07;
w = 5;
#--------------------------------#
# Value function #
#--------------------------------#
V = value(nx, xmin, xmax,
ne, ssigma_eps, llambda_eps, m,
ssigma, bbeta, T, r, w);
# I recover the Policy Functions
Value = array(0,dim=c(T, nx, ne));
for (age in 1:T){
for (ix in 1:nx){
for(ie in 1:ne){
Value[age, ix, ie] = V[(age-1)*nx*ne + (ix-1)*ne + ie];
}
}
}
#---------------------#
# Some checks #
#---------------------#
print(" ")
print(" - - - - - - - - - - - - - - - - - - - - - ")
print(" ")
print("The first entries of the value function: ")
print(" ")
for(i in 1:3){
print(Value[1, 1, i])
}
print(" ")