#Test script for Smolyak_grid

using CSV
using Distributions

include("Smolyak_Elem_isotrop.jl")
include("Smolyak_Grid.jl")
include("Gen_Smolyak.jl")
include("options.jl")
include("params.jl")

# Solution Options
options_int_use, options_float_use = options()

# Parameters

params_use = params()

Data=CSV.read("FunctionsSolutionSmolyak/COPF_Data.csv",datarow=1)

R_ss=params_use["R_ss"]
R_data=Data[:,4] ./ 400 .+ 1
R_min=log(1/R_ss)
R_max=log(quantile(R_data,0.90)/R_ss)

d=6
mu=2
sd=1.282

rho_z  = params_use["rho_z"];
rho_g  = params_use["rho_g"];
rho_r  = params_use["rho_r"];
rho_d  = params_use["rho_d"];

sig_z  = params_use["sig_z"];
sig_g  = params_use["sig_g"];
sig_r  = params_use["sig_r"];
sig_d  = params_use["sig_d"];

z_min=-sd*sig_z/sqrt(1-rho_z^2)
z_max=sd*sig_z/sqrt(1-rho_z^2)

d_min=-sd*sig_d/sqrt(1-rho_d^2)
d_max=sd*sig_d/sqrt(1-rho_d^2)

g_min=-sd*sig_g/sqrt(1-rho_g^2)
g_max=sd*sig_g/sqrt(1-rho_g^2)

er_min=-sd*sig_r
er_max=sd*sig_r

y_max=z_max;
y_min=z_min;

max_min=[R_max R_min ;y_max y_min; er_max er_min; g_max g_min; z_max  z_min; d_max  d_min]

Smol_grid,weights=Gen_Smolyak(d,mu,max_min,1,sd)
