oct-file and cell

Michael Creel michael.creel at uab.es
Mon Mar 30 11:37:51 CDT 2009




Bertrand Roessli wrote:
> 
> Hello,
> 
> I am trying to learn how to write oct-files and I need to extract the
> content of the cell array shown below. 
> I just do not find the proper way to extract the information contained
> in the cell and put that in arrays or matrices, etc. 
> 
> If somebody could help, I would greatly appreciate.
> 
> Thank You, Bertrand Roessli
> 
> ion_cell =
> 
> {
>   [1,1] =  7
>   [1,2] =
>   {
>     as =  7.2207
>     bs =  8.4610
>     cs =  5.6609
>   }
>   [1,3] =
>   {
>     ion = ER
>     bd =  0.77900
>     x =  0.13658
>     y =  0.17096
>     z = 0
>     B =  0.36700
>     occ =  0.50000
>     x_par = N3
>     y_par = N4
>     z_par = 0.00000
>     B_par = N16
>     occ_par = 0.50000
>   }
> 
>   [1,4] =
>   {
>     ion = MN
>     bd = -0.37300
>     x = 0
>     y =  0.50000
>     z =  0.26053
>     B =  0.36300
>     occ =  0.50000
>     x_par = 0.00000
>     y_par = 0.50000
>     z_par = N5
>     B_par = N17
>     occ_par = 0.50000
>   }
> ...
> 
> 
> 
> _______________________________________________
> Help-octave mailing list
> Help-octave at octave.org
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> 
> 

Here's an example of a .oct file that uses cells. 

// logarithmic stochastic volatility model
// used by Andersen et al., Chumacero, Takeda, etc.
// y(t) = exp(ystar(t)/2) * e1
// ystar(t) = a + b  ystar(t-1) + sig*e2
//
// a different parameterization (e.g., Fermanian and Salanie, Altissimo and
Mele) is
// y(t) = exp(a/2)*exp(ystar(t)/2) * e1
// ystar(t) = b*ystar(t-1) + sig*e2
//
// the difference is whether a or exp(a) is estimated. Other than that, they
are equivalent

#include <oct.h>
#include <octave/Cell.h>

DEFUN_DLD(sv, args, ,"sv")
{
	// parameter of model
	ColumnVector model_params (args(0).column_vector_value());
	double phi = model_params(0);
	double sigb = model_params(1);
	double sige = model_params(2);

	// other args
	Cell modelargs (args(1).cell_value());
	Matrix randdraws (modelargs(0).matrix_value()); // random numbers, passed
this way to keep fixed
	int n (modelargs(1).int_value());
	int burnin (modelargs(2).int_value()); // number of burnin periods to
eliminate startup effects

	int t;
	double y, ystar;
	double ystarlag = 0.0;

	ColumnVector ys(n);
	ys.fill(0.0);
	octave_value_list f_return;

	// main loop, first burnin, then keepers
	for (t=0; t < (n + burnin); t++) { // loop over time
		ystar = phi*ystarlag + sige*randdraws(t,1);
		y = sigb*exp(ystar / 2.0) * randdraws(t, 0);
		if (t >= burnin) {
			ys(t-burnin) +=  y;
		}
		ystarlag = ystar;
	}
	f_return(0) = ys;
	return f_return;
}


-- 
View this message in context: http://www.nabble.com/oct-file-and-cell-tp22780278p22787322.html
Sent from the Octave - General mailing list archive at Nabble.com.



More information about the Help-octave mailing list