void SymbolTable::bind(const std::string& name, Expr obj, bool levelZero) throw() { PrettyCheckArgument(!obj.isNull(), obj, "cannot bind to a null Expr"); ExprManagerScope ems(obj); if(levelZero) d_exprMap->insertAtContextLevelZero(name, obj); else d_exprMap->insert(name, obj); }
void Pickler::debugPickleTest(Expr e) { //ExprManager *em = e.getExprManager(); //Expr e1 = mkVar("x", makeType()); //return ; Pickler pickler(e.getExprManager()); Pickle p; pickler.toPickle(e, p); uint32_t size = p.d_data->size(); std::string str = p.d_data->toString(); Expr from = pickler.fromPickle(p); ExprManagerScope ems(e); Debug("pickle") << "before: " << e << std::endl; Debug("pickle") << "after: " << from.getNode() << std::endl; Debug("pickle") << "pickle: (oct) "<< size << " " << str.length() << " " << str << std::endl; Assert(p.d_data->empty()); Assert(e == from); }
/** * Computes garch price for GARCH model * @param[in] today_price taday price * @param[in] alpha_zero garch parameter * @param[in] alpha_one garch parameter * @param[in] lambda the constant unit risk premium * @param[in] beta_one garch parameter * @param[in] interest the annulized interest * @param[in] K exercise price * @param[in] frequency frequency * @param[in] T time to mutrity * @param[in] choice emscorrection(ems_on or ems_off) * @param[in] type_generator the type of generator for random number * @param[out] garch option price * garch->call obtains call option price * garch->put obtains put option price * @return OK if ok otherwise return FAIL */ static int garch_price(NumFunc_1 *p,double today_price,double alpha_zero,double alpha_one,double beta_one,double lambda,double interest,int frequency,double K,int T,int N,int choice,int type_generator,double *price,double *delta) { double sum_callorput; double sum_delta; double s_T; double garch_delta; int i; PnlMat *path_ems, *path, *path1D; PnlVect *h; path=pnl_mat_create(T,N); h=pnl_vect_create (1); sum_callorput=0; sum_delta=0; pnl_vect_set(h,0,today_price); if (calculate_path(h,path,interest,frequency,N,T,alpha_zero,alpha_one,lambda,beta_one,type_generator)==FAIL) { pnl_vect_free(&h); pnl_mat_free(&path); return FAIL; } //if we choose ems option switch (choice) { case 1: pnl_vect_free(&h); pnl_rand_init(type_generator,N,T); path_ems=pnl_mat_create(T,N); if(ems(path,interest,frequency,path_ems)==FAIL) { pnl_mat_free(&path); pnl_mat_free(&path_ems); return FAIL; } pnl_mat_clone(path, path_ems); for(i=0;i<N;i++) { s_T=pnl_mat_get(path,T-1,i); sum_callorput=sum_callorput+(p->Compute)(p->Par,pnl_mat_get(path,T-1,i)); if(s_T>K) garch_delta=1.; sum_delta=sum_delta+(s_T/today_price)*garch_delta; } pnl_mat_free(&path_ems); break; case 2: path1D=pnl_mat_create(T,1); pnl_rand_init(type_generator,1,T); for(i=0;i<N;i++) { calculate_path(h,path1D,interest,frequency,1,T,alpha_zero,alpha_one,lambda,beta_one,type_generator); s_T=pnl_mat_get(path1D,T-1,0); sum_callorput=sum_callorput+(p->Compute)(p->Par,pnl_mat_get(path,T-1,i)); if(s_T>K) garch_delta=1.; sum_delta=sum_delta+(s_T/today_price)*garch_delta; } pnl_vect_free(&h); pnl_mat_free(&path1D); break; default: printf ("Wrong value for parameter EMS\n"); return FAIL; } interest=(interest*frequency)/252.; //Price *price=sum_callorput/(N*pow(M_E,(interest*T))); *delta=sum_delta/(N*pow(M_E,(T*interest))); if ((p->Compute)==&Put) *delta=*delta-1; pnl_mat_free(&path); return OK ; }