double uo_put_ql(const Date& todaysDate_, const Date& settlementDate_, const Date& maturity_, Real spot_, Real strike, Real barrier_, Real rebate_, Spread dividendYield, Rate riskFreeRate, Volatility volatility ) { // set up dates Calendar calendar = TARGET(); Date todaysDate = todaysDate_; Date settlementDate = settlementDate_; Date maturity = maturity_; Settings::instance().evaluationDate() = todaysDate_; DayCounter dc = Actual360(); Real barrier = barrier_; Real rebate = rebate_; Handle <Quote > spot(boost::shared_ptr<SimpleQuote>(new SimpleQuote(spot_))); Handle<YieldTermStructure> qTS(boost::shared_ptr<YieldTermStructure>( new FlatForward(settlementDate, dividendYield, dc))); Handle<YieldTermStructure> rTS(boost::shared_ptr<YieldTermStructure>( new FlatForward(settlementDate, riskFreeRate, dc))); Handle<BlackVolTermStructure> volTS(boost::shared_ptr<BlackVolTermStructure>( new BlackConstantVol(settlementDate, calendar, volatility, dc))); boost::shared_ptr<BlackScholesMertonProcess> stochProcess(new BlackScholesMertonProcess(spot, qTS, rTS, volTS)); boost::shared_ptr<PricingEngine> engine( new AnalyticBarrierEngine(stochProcess)); Option::Type type = Option::Put; boost::shared_ptr<StrikedTypePayoff> payoff(new PlainVanillaPayoff(type, strike)); boost::shared_ptr<Exercise> exercise(new EuropeanExercise(maturity)); BarrierOption option( Barrier::UpOut, barrier, rebate, payoff, exercise); option.setPricingEngine(engine); return option.NPV(); }
static int target_stop(Unit *u) { Target *t = TARGET(u); assert(t); assert(t->state == TARGET_ACTIVE); target_set_state(t, TARGET_DEAD); return 0; }
POS BRAIN::genmove () { tgsearch.numb = 0; ___.tic ("search by minmax ..."); RESULT rslt = tgsearch.minmax (this, TARGETS (TARGET (ROOT, 2))); ___.toc (); ___ASSERT (rslt.move.second == turn ()); return rslt.move.first; }
static int target_serialize(Unit *u, FILE *f, FDSet *fds) { Target *s = TARGET(u); assert(s); assert(f); assert(fds); unit_serialize_item(u, f, "state", target_state_to_string(s->state)); return 0; }
static void target_dump(Unit *u, FILE *f, const char *prefix) { Target *t = TARGET(u); assert(t); assert(f); fprintf(f, "%sTarget State: %s\n", prefix, target_state_to_string(t->state)); }
static int target_coldplug(Unit *u) { Target *t = TARGET(u); assert(t); assert(t->state == TARGET_DEAD); if (t->deserialized_state != t->state) target_set_state(t, t->deserialized_state); return 0; }
Euribor365::Euribor365(const Period& tenor, const Handle<YieldTermStructure>& h) : IborIndex("Euribor365", tenor, 2, // settlement days EURCurrency(), TARGET(), euriborConvention(tenor), euriborEOM(tenor), Actual365Fixed(), h) { QL_REQUIRE(this->tenor().units()!=Days, "for daily tenors (" << this->tenor() << ") dedicated DailyTenor constructor must be used"); }
UsdLiborSwapIsdaFixAm::UsdLiborSwapIsdaFixAm( const Period& tenor, const Handle<YieldTermStructure>& h) : SwapIndex("UsdLiborSwapIsdaFixAm", // familyName tenor, 2, // settlementDays USDCurrency(), TARGET(), 6*Months, // fixedLegTenor ModifiedFollowing, // fixedLegConvention Thirty360(Thirty360::BondBasis), // fixedLegDaycounter boost::shared_ptr<IborIndex>(new USDLibor(3*Months, h))) {}
JpyLiborSwapIsdaFixPm::JpyLiborSwapIsdaFixPm( const Period& tenor, const Handle<YieldTermStructure>& h) : SwapIndex("JpyLiborSwapIsdaFixPm", // familyName tenor, 2, // settlementDays JPYCurrency(), TARGET(), 6*Months, // fixedLegTenor ModifiedFollowing, // fixedLegConvention ActualActual(ActualActual::ISDA), // fixedLegDaycounter boost::shared_ptr<IborIndex>(new JPYLibor(6*Months, h))) {}
ChfLiborSwapIsdaFix::ChfLiborSwapIsdaFix(const Period& tenor, const Handle<YieldTermStructure>& h) : SwapIndex("ChfLiborSwapIsdaFix", // familyName tenor, 2, // settlementDays CHFCurrency(), TARGET(), 1*Years, // fixedLegTenor ModifiedFollowing, // fixedLegConvention Thirty360(Thirty360::BondBasis), // fixedLegDaycounter tenor > 1*Years ? boost::shared_ptr<IborIndex>(new CHFLibor(6*Months, h)) : boost::shared_ptr<IborIndex>(new CHFLibor(3*Months, h))) {}
VT BRAIN::top () const { VT vt; PBC smass = infop->area.getmass (infop->getlastpos (), infop->getlastclr ()); PBC smass_his = infop->area.getmass (smass.first, infop->turn ()); PBC fmass = infop->father->area.getmass (smass.first, infop->getlastclr ()); PBC fmass_his = infop->father->area.getmass (smass.first, infop->turn ()); // 断事件,必然有异块半联(即断)已块半联(即断),可能有已块联络(全联) BITB cut = infop->cutpos (infop->getlastclr ()).blockon (infop->getlastpos ()); if (cut[infop->getlastpos ()]) { PBC f_his = infop->father->area.getmass (cut, infop->turn ()); PBC s_my = infop->area.getmass (cut, infop->getlastclr ()); vt.push_back (TARGET (DUAN, INT_MAX, f_his, s_my)); //被断者,断者 } // 已块联络,落在父的什么色区都有可能 if (fmass.first.blockcount () > 1) vt.push_back (TARGET (LIANLUO, INT_MAX, fmass, smass)); //联络对象,联络效果 // 异块隔开,落在父的什么色区都有可能 if (fmass_his.first.blockcount () < smass_his.first.blockcount ()) vt.push_back (TARGET (GE, INT_MAX, fmass_his, smass)); //隔开对象,阻隔者 return vt; }
EurLiborSwapIsdaFixB::EurLiborSwapIsdaFixB( const Period& tenor, const Handle<YieldTermStructure>& forwarding, const Handle<YieldTermStructure>& discounting) : SwapIndex("EurLiborSwapIsdaFixB", // familyName tenor, 2, // settlementDays EURCurrency(), TARGET(), 1*Years, // fixedLegTenor ModifiedFollowing, // fixedLegConvention Thirty360(Thirty360::BondBasis), // fixedLegDaycounter tenor > 1*Years ? shared_ptr<IborIndex>(new EURLibor(6*Months, forwarding)) : shared_ptr<IborIndex>(new EURLibor(3*Months, forwarding)), discounting) {}
static int target_load(Unit *u) { Target *t = TARGET(u); int r; assert(t); if ((r = unit_load_fragment_and_dropin(u)) < 0) return r; /* This is a new unit? Then let's add in some extras */ if (u->load_state == UNIT_LOADED) { if (u->default_dependencies) if ((r = target_add_default_dependencies(t)) < 0) return r; } return 0; }
Real InterpolatedYoYOptionletStripper<Interpolator1D>:: ObjectiveFunction::operator()(Volatility guess) const { vvec_[1] = guess; vvec_[0] = guess - slope_ * (tvec_[1] - tvec_[0]) * guess; // could have Interpolator1D instead of Linear boost::shared_ptr<InterpolatedYoYOptionletVolatilityCurve<Linear> > vCurve( new InterpolatedYoYOptionletVolatilityCurve<Linear>( 0, TARGET(), ModifiedFollowing, Actual365Fixed(), lag_, frequency_, indexIsInterpolated_, dvec_, vvec_, -1.0, 3.0) ); // strike limits Handle<YoYOptionletVolatilitySurface> hCurve(vCurve); p_->setVolatility(hCurve); // hopefully this gets to the pricer ... then return priceToMatch_ - capfloor_.NPV(); }
SwapType(// Fixed Leg Frequency fixedLegFrequency = Semiannual, DayCounter fixedLegDayCounter = Thirty360(Thirty360::European), BusinessDayConvention fixedLegConvention = ModifiedFollowing, // floating leg Frequency floatingLegFrequency = Quarterly, DayCounter floatingLegDayCounter = Actual360(), BusinessDayConvention floatingLegConvention = ModifiedFollowing, Calendar calendar = TARGET() ) : _fixedLegFrequency(fixedLegFrequency), _fixedLegDayCounter(fixedLegDayCounter), _fixedLegConvention(fixedLegConvention), _floatingLegFrequency(floatingLegFrequency), _floatingLegDayCounter(floatingLegDayCounter), _floatingLegConvention(floatingLegConvention), _calendar(calendar) { _indexBase = IndexBase<T>(floatingLegFrequency); }
static int target_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { Target *s = TARGET(u); assert(u); assert(key); assert(value); assert(fds); if (streq(key, "state")) { TargetState state; if ((state = target_state_from_string(value)) < 0) log_debug("Failed to parse state value %s", value); else s->deserialized_state = state; } else log_debug("Unknown serialization key '%s'", key); return 0; }
static void inter_init(Display* dpy, Window win, struct inter_context* c) { XWindowAttributes xgwa; double H[3], S[3], V[3]; int i; int mono; int gray; XGCValues val; unsigned long valmask = 0; Bool dbuf = get_boolean_resource (dpy, "doubleBuffer", "Boolean"); # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ dbuf = False; # endif memset (c, 0, sizeof(*c)); c->dpy = dpy; c->win = win; c->delay = get_integer_resource(dpy, "delay", "Integer"); XGetWindowAttributes(c->dpy, c->win, &xgwa); c->w = xgwa.width; c->h = xgwa.height; c->cmap = xgwa.colormap; #ifdef HAVE_XSHM_EXTENSION c->use_shm = get_boolean_resource(dpy, "useSHM", "Boolean"); #endif /* HAVE_XSHM_EXTENSION */ if (dbuf) { #ifdef HAVE_DOUBLE_BUFFER_EXTENSION c->back_buf = xdbe_get_backbuffer (c->dpy, c->win, XdbeUndefined); #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ #ifdef HAVE_DOUBLE_BUFFER_EXTENSION if (!c->back_buf) #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ c->pix_buf = XCreatePixmap (dpy, win, xgwa.width, xgwa.height, xgwa.depth); } val.function = GXcopy; c->copy_gc = XCreateGC(c->dpy, TARGET(c), GCFunction, &val); c->count = get_integer_resource(dpy, "count", "Integer"); if(c->count < 1) c->count = 1; c->grid_size = get_integer_resource(dpy, "gridsize", "Integer"); if(c->grid_size < 1) c->grid_size = 1; mono = get_boolean_resource(dpy, "mono", "Boolean"); if(!mono) { c->colors = get_integer_resource(dpy, "ncolors", "Integer"); if(c->colors < 2) c->colors = 2; } c->hue = get_integer_resource(dpy, "hue", "Float"); while (c->hue < 0 || c->hue >= 360) c->hue = frand(360.0); c->speed = get_integer_resource(dpy, "speed", "Integer"); c->shift = get_float_resource(dpy, "color-shift", "Float"); while(c->shift >= 360.0) c->shift -= 360.0; while(c->shift <= -360.0) c->shift += 360.0; c->radius = get_integer_resource(dpy, "radius", "Integer");; if(c->radius < 1) c->radius = 1; #ifdef USE_XIMAGE c->ximage = 0; # ifdef HAVE_XSHM_EXTENSION if (c->use_shm) { c->ximage = create_xshm_image(dpy, xgwa.visual, xgwa.depth, ZPixmap, 0, &c->shm_info, xgwa.width, c->grid_size); if (!c->ximage) c->use_shm = False; } # endif /* HAVE_XSHM_EXTENSION */ if (!c->ximage) { c->ximage = XCreateImage (dpy, xgwa.visual, xgwa.depth, ZPixmap, 0, 0, /* depth, fmt, offset, data */ xgwa.width, c->grid_size, /* width, height */ 8, 0); /* pad, bpl */ c->ximage->data = (unsigned char *) calloc(c->ximage->height, c->ximage->bytes_per_line); } #endif /* USE_XIMAGE */ if(!mono) { c->pal = calloc(c->colors, sizeof(XColor)); gray = get_boolean_resource(dpy, "gray", "Boolean"); if(!gray) { H[0] = c->hue; H[1] = H[0] + c->shift < 360.0 ? H[0]+c->shift : H[0] + c->shift-360.0; H[2] = H[1] + c->shift < 360.0 ? H[1]+c->shift : H[1] + c->shift-360.0; S[0] = S[1] = S[2] = 1.0; V[0] = V[1] = V[2] = 1.0; } else { H[0] = H[1] = H[2] = 0.0; S[0] = S[1] = S[2] = 0.0; V[0] = 1.0; V[1] = 0.5; V[2] = 0.0; } make_color_loop(c->dpy, c->cmap, H[0], S[0], V[0], H[1], S[1], V[1], H[2], S[2], V[2], c->pal, &(c->colors), True, False); if(c->colors < 2) { /* color allocation failure */ mono = 1; free(c->pal); } } if(mono) { /* DON'T else this with the previous if! */ c->colors = 2; c->pal = calloc(2, sizeof(XColor)); c->pal[0].pixel = BlackPixel(c->dpy, DefaultScreen(c->dpy)); c->pal[1].pixel = WhitePixel(c->dpy, DefaultScreen(c->dpy)); } valmask = GCForeground; c->gcs = calloc(c->colors, sizeof(GC)); for(i = 0; i < c->colors; i++) { val.foreground = c->pal[i].pixel; c->gcs[i] = XCreateGC(c->dpy, TARGET(c), valmask, &val); } c->wave_height = calloc(c->radius, sizeof(int)); for(i = 0; i < c->radius; i++) { float max = ((float)c->colors) * ((float)c->radius - (float)i) / ((float)c->radius); c->wave_height[i] = (int) ((max + max*cos((double)i/50.0)) / 2.0); } c->source = calloc(c->count, sizeof(struct inter_source)); for(i = 0; i < c->count; i++) { c->source[i].x_theta = frand(2.0)*3.14159; c->source[i].y_theta = frand(2.0)*3.14159; } }
static void SE_process_effect(effect_t *effect) { switch(effect->edge_type) { case DEREF_ASSIGN: if (SE_reflect_effect(effect, 1) == ADD_EFFECT) { #if 1 if (effect->skew != 0) { IPA_cgraph_edge_data_t data; IPA_cgraph_node_t *tmp_node; tmp_node = new_temp_node(local_sum, IPA_CG_NODE_FLAGS_SUMMARY); /* SUMMARY: tmp(0) *=(z) src(s) */ TARGET(data) = 0; TGTSTR(data) = 0; SIZE(data) = SIZE(effect->edata); SRCSTR(data) = SRCSTR(effect->edata); SOURCE(data) = SOURCE(effect->edata); SE_addto_summary(effect->edge_type, effect->src, tmp_node, &data); /* EFFECT : tmp(0) =+(k) dst(t) */ TARGET(data) = 0; TGTSTR(data) = 0; SIZE(data) = effect->skew; SRCSTR(data) = TGTSTR(effect->edata); SOURCE(data) = TARGET(effect->edata); SE_addto_effectlist(SKEW, effect->dst, tmp_node, &data, 0); break; } #endif if (SE_reflect_effect(effect, 0) == ADD_EFFECT) { /* Effect not skipped */ SE_addto_summary(effect->edge_type, effect->src, effect->dst, &effect->edata); } } break; case ASSIGN_DEREF: #if 1 if (effect->skew != 0) { IPA_cgraph_edge_data_t data; IPA_cgraph_node_t *tmp_node; tmp_node = new_temp_node(local_sum, IPA_CG_NODE_FLAGS_SUMMARY); /* SUMMARY: dst(t) =*(z) tmp(0) */ TARGET(data) = TARGET(effect->edata); TGTSTR(data) = TGTSTR(effect->edata); SIZE(data) = SIZE(effect->edata); SRCSTR(data) = 0; SOURCE(data) = 0; SE_addto_summary(effect->edge_type, tmp_node, effect->dst, &data); /* EFFECT : tmp(0) =+(k) src(s) */ TARGET(data) = 0; TGTSTR(data) = 0; SIZE(data) = effect->skew; SRCSTR(data) = SRCSTR(effect->edata); SOURCE(data) = SOURCE(effect->edata); SE_addto_effectlist(SKEW, effect->src, tmp_node, &data, 0); break; } #endif case ASSIGN: case SKEW: if (SE_reflect_effect(effect, 1) == ADD_EFFECT) { /* Effect not skipped */ SE_addto_summary(effect->edge_type, effect->src, effect->dst, &effect->edata); } break; case ASSIGN_ADDR: SE_addto_summary(effect->edge_type, effect->src, effect->dst, &effect->edata); break; default: assert(0); } }
__WEAK void target_serialno(unsigned char *buf) { snprintf((char *) buf, 13, "%s",TARGET(BOARD)); }
static int compact_effect_edge(effect_t *effect, IPA_cgraph_edge_t *edge, IPA_cgraph_edgelist_e edge_type, int issrc, int retain_oldeffect, int update) { IPA_cgraph_node_t *n_src = NULL; IPA_cgraph_node_t *n_dst = NULL; IPA_cgraph_edgelist_e n_type = 0; IPA_cgraph_edge_data_t n_data; int n_skew; int t1, z1, s1, t2, z2, s2; int ts1, ss1, ts2, ss2; int compaction_action; compaction_action = NO_EFFECT; /* All addr effects are from initial effects and should be kept */ if (effect->edge_type == ASSIGN_ADDR) { /* This is not really an error but reaching this is an inefficiency */ assert(0); return 1; } /* AA and DA edges are added during initial effect generation only */ if ((edge_type == ASSIGN_ADDR /* FIXTEST */ && !(issrc && effect->edge_type == DEREF_ASSIGN) ) || edge_type == DEREF_ASSIGN) { /* do nothing */ #if DB_EFF > 1 printf("AD/AA : no action\n"); #endif return 0; } /* Override if src is PARAM and we're handling the * dst of an DEREF_ASSIGN */ if (!issrc && IPA_FLAG_ISSET(edge->src_elist->node->flags, IPA_CG_NODE_FLAGS_PARAM)) { #if DB_EFF > 1 printf("FORCE - "); #endif retain_oldeffect = 1; } t1 = TARGET(effect->edata); ts1 = TGTSTR(effect->edata); z1 = SIZE(effect->edata); ss1 = SRCSTR(effect->edata); s1 = SOURCE(effect->edata); n_skew = effect->skew; t2 = TARGET(edge->data); ts2 = TGTSTR(edge->data); z2 = SIZE(edge->data); ss2 = SRCSTR(edge->data); s2 = SOURCE(edge->data); switch(effect->edge_type) { /***************** ASSIGN ********************/ case ASSIGN: assert(issrc); n_src = edge->src_elist->node; n_dst = effect->dst; if (ss1 != 0 || ts2 != 0) { /* Meshing stride, retain effect */ compaction_action = HAS_EFFECT; retain_oldeffect = 1; break; } switch(edge_type) { case ASSIGN: n_type = ASSIGN; if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("A-A : new 1"); #endif compaction_action = HAS_EFFECT; TARGET(n_data) = t1; TGTSTR(n_data) = ts1; SIZE(n_data) = MIN(z1, z2 - (s1-t2)); SRCSTR(n_data) = ss2; SOURCE(n_data) = s2 + (s1-t2); } else if (BOUND(s1, t2, s1 + z1 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("A-A : new 2"); #endif compaction_action = HAS_EFFECT; TARGET(n_data) = t1 + (t2-s1); TGTSTR(n_data) = ts1; SIZE(n_data) = MIN(z2, z1 - (t2-s1)); SRCSTR(n_data) = ss2; SOURCE(n_data) = s2; } #if DB_EFF > 1 else printf("A-A : none"); #endif break; case SKEW: n_type = SKEW; if (BOUND(s1, t2, s1 + z1 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("A-K : new 1"); #endif compaction_action = HAS_EFFECT; TARGET(n_data) = t1 + (t2-s1); TGTSTR(n_data) = ts1; SIZE(n_data) = z2; SRCSTR(n_data) = ss2; SOURCE(n_data) = s2; } #if DB_EFF > 1 else printf("A-K : none"); #endif break; case ASSIGN_DEREF: n_type = ASSIGN_DEREF; if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("A-AD : new 1"); #endif compaction_action = HAS_EFFECT; TARGET(n_data) = t1; TGTSTR(n_data) = ts1; SIZE(n_data) = MIN(z1, z2-(s1-t2)); SRCSTR(n_data) = ss2; SOURCE(n_data) = s2; n_skew += (s1 - t2); } else if (BOUND(s1, t2, s1 + z1 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("A-AD : new 2"); #endif compaction_action = HAS_EFFECT; TARGET(n_data) = t1 + (t2-s1); TGTSTR(n_data) = ts1; SIZE(n_data) = MIN(z2, z1 - (t2-s1));; SRCSTR(n_data) = ss2; SOURCE(n_data) = s2; } #if DB_EFF > 1 else printf("A-AD : none"); #endif break; default: assert(0); } break; case SKEW: /***************** SKEW ********************/ assert(issrc); n_src = edge->src_elist->node; n_dst = effect->dst; if (ss1 != 0 || ts2 != 0) { /* Meshing stride, retain effect */ compaction_action = HAS_EFFECT; retain_oldeffect = 1; break; } switch(edge_type) { case ASSIGN: n_type = SKEW; if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("K-A : new 1"); #endif compaction_action = HAS_EFFECT; TARGET(n_data) = t1; TGTSTR(n_data) = ts1; SIZE(n_data) = z1; SRCSTR(n_data) = ss2; SOURCE(n_data) = s2 + (s1 - t2); } #if DB_EFF > 1 else printf("K-A : none"); #endif break; case SKEW: n_type = SKEW; if (s1 == t2) { #if DB_EFF > 1 printf("K-K : new 1"); #endif compaction_action = HAS_EFFECT; TARGET(n_data) = t1; TGTSTR(n_data) = ts1; SIZE(n_data) = (z1 + z2); SRCSTR(n_data) = ss2; SOURCE(n_data) = s2; } #if DB_EFF > 1 else printf("K-K : none"); #endif break; case ASSIGN_DEREF: if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("K-AD : retain 1"); #endif compaction_action = HAS_EFFECT; } #if DB_EFF > 1 else printf("K-AD : none"); #endif retain_oldeffect = 1; break; default: assert(0); } break; case ASSIGN_DEREF: /***************** ASSIGN_DEREF ********************/ assert(issrc); n_src = edge->src_elist->node; n_dst = effect->dst; if (ss1 != 0 || ts2 != 0) { /* Meshing stride, retain effect */ compaction_action = HAS_EFFECT; retain_oldeffect = 1; break; } switch(edge_type) { case ASSIGN: n_type = ASSIGN_DEREF; if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("AD-A : new 1"); #endif compaction_action = HAS_EFFECT; TARGET(n_data) = t1; TGTSTR(n_data) = ts1; SIZE(n_data) = z1; SRCSTR(n_data) = ss2; SOURCE(n_data) = s2 + (s1-t2); } #if DB_EFF > 1 else printf("AD-A : none"); #endif break; case SKEW: if (s1 == t2) { #if DB_EFF > 1 printf("AD-K : retain 1"); #endif compaction_action = HAS_EFFECT; } #if DB_EFF > 1 else printf("AD-K : none"); #endif retain_oldeffect = 1; break; case ASSIGN_DEREF: if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("AD-AD : retain 1"); #endif compaction_action = HAS_EFFECT; } #if DB_EFF > 1 else printf("AD-AD : none"); #endif retain_oldeffect = 1; break; default: assert(0); } break; case DEREF_ASSIGN: if (issrc) { /***************** (source) DEREF_ASSIGN ********************/ if (ss1 != 0 || ts2 != 0) { /* Meshing stride, retain effect */ compaction_action = HAS_EFFECT; retain_oldeffect = 1; break; } switch(edge_type) { case ASSIGN: n_type = DEREF_ASSIGN; n_src = edge->src_elist->node; n_dst = effect->dst; if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("DA-A : src new 1"); #endif compaction_action = HAS_EFFECT; TARGET(n_data) = t1; TGTSTR(n_data) = ts1; SIZE(n_data) = MIN(z1, z2-(s1-t2)); SRCSTR(n_data) = ss2; SOURCE(n_data) = s2 + (s1-t2); } else if (BOUND(s1, t2, s1 + z1 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("DA-A : src new 2"); #endif compaction_action = HAS_EFFECT; TARGET(n_data) = t1; TGTSTR(n_data) = ts1; SIZE(n_data) = MIN(z2, z1 - (t2-s1)); SRCSTR(n_data) = ss2; SOURCE(n_data) = s2; n_skew += (t2 - s1); } #if DB_EFF > 1 else printf("DA-A : src none"); #endif break; case SKEW: if (BOUND(s1, t2, s1 + z1 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("DA-K : src retain 1"); #endif compaction_action = HAS_EFFECT; } #if DB_EFF > 1 else printf("DA-K : src none"); #endif retain_oldeffect = 1; break; case ASSIGN_DEREF: if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE) || BOUND(s1, t2, s1 + z1 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("DA-K/AD : src retain 1"); #endif compaction_action = HAS_EFFECT; } #if DB_EFF > 1 else printf("DA-K/AD : src none"); #endif retain_oldeffect = 1; break; /* FIXTEST */ case ASSIGN_ADDR: if (s1 == t2) { #if DB_EFF > 1 printf("AD-ADDR : retain 1"); #endif compaction_action = HAS_EFFECT; } #if DB_EFF > 1 else printf("AD-ADDR : none"); #endif retain_oldeffect = 1; break; default: assert(0); } } else { /***************** (dest) DEREF_ASSIGN ********************/ if (ts1 != 0 || ts2 != 0) { /* Meshing stride, retain effect */ compaction_action = HAS_EFFECT; retain_oldeffect = 1; break; } switch(edge_type) { case ASSIGN: n_type = DEREF_ASSIGN; n_src = effect->src; n_dst = edge->src_elist->node; if (BOUND(t2, t1, t2 + z2 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("DA-A : dst new 1"); #endif compaction_action = HAS_EFFECT; TARGET(n_data) = s2 + (t1-t2); TGTSTR(n_data) = ss2; SIZE(n_data) = z1; SRCSTR(n_data) = ss1; SOURCE(n_data) = s1; } #if DB_EFF > 1 else printf("DA-A : dst none"); #endif break; case SKEW: if (t1 == t2) { #if DB_EFF > 1 printf("DA-K : dst retain 1"); #endif compaction_action = HAS_EFFECT; } #if DB_EFF > 1 else printf("DA-K : dst none"); #endif retain_oldeffect = 1; break; case ASSIGN_DEREF: if (BOUND(t2, t1, t2 + z2 - IPA_POINTER_SIZE)) { #if DB_EFF > 1 printf("DA-AD : dst retain 1"); #endif compaction_action = HAS_EFFECT; } #if DB_EFF > 1 else printf("DA-AD : dst none"); #endif retain_oldeffect = 1; break; default: assert(0); } } break; default: assert(0); } if (SRCSTR(n_data) != 0) { SOURCE(n_data) = 0; SIZE(n_data) = IPA_POINTER_SIZE; } if (TGTSTR(n_data) != 0) { TARGET(n_data) = 0; SIZE(n_data) = IPA_POINTER_SIZE; } if (compaction_action == HAS_EFFECT) { if (retain_oldeffect) { #if DB_EFF > 1 printf(" : has effect, retain old effect\n"); #endif if (update) SE_addedgeto_effectlist(edge); return 1; } else { #if DB_EFF > 1 printf(" : has effect, compact\n"); #endif if (update) SE_addto_effectlist(n_type, n_src, n_dst, &n_data, n_skew); return 0; } } #if DB_EFF > 1 printf(" : no effect\n"); #endif return 0; }
int fastboot_init(void *base, unsigned size) { thread_t *thr; dprintf(ALWAYS, "fastboot_init()\n"); download_base = base; download_max = size; //mtk_wdt_disable(); /*It will re-enable during continue boot*/ timer_initialize(&wdt_timer); timer_set_periodic(&wdt_timer, 5000, (timer_callback)mtk_wdt_restart, NULL); fastboot_register("getvar:", cmd_getvar, TRUE); fastboot_publish("version", "0.5"); #ifndef USER_BUILD fastboot_register("boot", cmd_boot, FALSE); #endif fastboot_register("signature", cmd_install_sig, FALSE); #ifdef USE_G_ORIGINAL_PROTOCOL fastboot_register("flash:", cmd_flash_mmc, TRUE); #ifndef USER_BUILD fastboot_register("erase:", cmd_erase_mmc, TRUE); #endif #else #ifdef MTK_EMMC_SUPPORT fastboot_register("flash:", cmd_flash_emmc, TRUE); #ifndef USER_BUILD fastboot_register("erase:", cmd_erase_emmc, TRUE); #endif #else fastboot_register("flash:", cmd_flash_nand, TRUE); #ifndef USER_BUILD fastboot_register("erase:", cmd_erase_nand, TRUE); #endif #endif #endif fastboot_register("continue", cmd_continue, FALSE); fastboot_register("reboot", cmd_reboot, FALSE); fastboot_register("reboot-bootloader", cmd_reboot_bootloader, FALSE); fastboot_publish("product", TARGET(BOARD)); fastboot_publish("kernel", "lk"); register_secure_unlocked_var(); #ifdef MTK_OFF_MODE_CHARGE_SUPPORT register_off_mode_charge_var(); #endif //fastboot_publish("serialno", sn_buf); register_parition_var(); /*LXO: Download related command*/ fastboot_register("download:", cmd_download, TRUE); fastboot_publish("max-download-size", "0x8000000"); //128M = 134217728 /*LXO: END!Download related command*/ fastboot_oem_register(); fastboot_register("oem p2u", cmd_oem_p2u, FALSE); fastboot_register("oem reboot-recovery",cmd_oem_reboot2recovery, FALSE); fastboot_register("oem append-cmdline",cmd_oem_append_cmdline,FALSE); #ifdef MTK_OFF_MODE_CHARGE_SUPPORT fastboot_register("oem off-mode-charge",cmd_oem_off_mode_charge,FALSE); #endif #ifdef MTK_TC7_COMMON_DEVICE_INTERFACE fastboot_register("oem auto-ADB",cmd_oem_ADB_Auto_Enable,FALSE); #endif #if defined(MTK_SECURITY_SW_SUPPORT) && defined(MTK_SEC_FASTBOOT_UNLOCK_SUPPORT) fastboot_register("oem unlock",fastboot_oem_unlock, TRUE); fastboot_register("oem lock",fastboot_oem_lock, TRUE); fastboot_register("oem key",fastboot_oem_key,TRUE); fastboot_register("oem lks",fastboot_oem_query_lock_state,TRUE); #endif event_init(&usb_online, 0, EVENT_FLAG_AUTOUNSIGNAL); event_init(&txn_done, 0, EVENT_FLAG_AUTOUNSIGNAL); in = udc_endpoint_alloc(UDC_TYPE_BULK_IN, 512); if (!in) goto fail_alloc_in; out = udc_endpoint_alloc(UDC_TYPE_BULK_OUT, 512); if (!out) goto fail_alloc_out; fastboot_endpoints[0] = in; fastboot_endpoints[1] = out; req = udc_request_alloc(); if (!req) goto fail_alloc_req; if (udc_register_gadget(&fastboot_gadget)) goto fail_udc_register; thr = thread_create("fastboot", fastboot_handler, 0, DEFAULT_PRIORITY, 4096); if (!thr) { goto fail_alloc_in; } thread_resume(thr); return 0; fail_udc_register: udc_request_free(req); fail_alloc_req: udc_endpoint_free(out); fail_alloc_out: udc_endpoint_free(in); fail_alloc_in: return -1; }
int SuFunction::disasm1(Ostream& out, int ci) { verify(locals); verify(literals); out << "\t\t\t\t\t" << setw(3) << ci << " "; short op = code[ci++]; // out << hex << setw(3) << op << " " << dec; out << opcodes[op] << " "; if (op == I_SUPER) { out << globals(TARGET(ci)); ci += 2; } else if (op == I_EACH) out << (int) code[ci++]; else if (op == I_BLOCK) { out << ci + 2 + TARGET(ci); ci += 2; int first = code[ci++]; int nargs = code[ci++]; for (int i = 0; i < nargs; ++i) out << " " << 1 + symstr(locals[first + i]); } else if (op == I_PUSH_INT) { out << TARGET(ci); ci += 2; } else if (op < 16 || op == I_BOOL) ; else if (op < I_PUSH) { switch (op & 0xf0) { case I_PUSH_LITERAL: out << literals[op & 15]; break; case I_PUSH_AUTO: out << symstr(locals[op & 15]); break; case I_EQ_AUTO: case I_EQ_AUTO_POP: out << symstr(locals[op & 7]); break; case I_CALL_GLOBAL: out << globals(TARGET(ci)) << " " << (op & 7); ci += 2; break; case I_CALL_MEM: case I_CALL_MEM_SELF: out << mem(ci) << " " << (op & 7); break; default: break; } } else if ((op & 0xf8) == I_PUSH) { switch (op & 7) { case LITERAL: out << literals[varint(code, ci)]; break; case AUTO: case DYNAMIC: out << symstr(locals[code[ci++]]); break; case MEM: case MEM_SELF: out << mem(ci); break; case GLOBAL: out << globals(TARGET(ci)); ci += 2; break; default: break; } } else if ((op & 0xf8) == I_CALL) { switch (op & 7) { case AUTO: case DYNAMIC: out << symstr(locals[code[ci++]]); break; case MEM: case MEM_SELF: out << mem(ci); ci += 2; break; case GLOBAL: out << globals(TARGET(ci)); ci += 2; break; default: break; } out << " " << (short) code[ci++]; short nargnames = code[ci++]; out << " " << nargnames; for (int i = 0; i < nargnames; ++i) { out << " " << symstr(TARGET(ci)); ci += 2; } } else if ((op & 0xf8) == I_JUMP || op == I_TRY || op == I_CATCH) { out << ci + 2 + TARGET(ci); ci += 2; if (op == I_TRY) out << " " << literals[varint(code, ci)]; } else if (I_ADDEQ <= op && op < I_ADD) { switch ((op & 0x70) >> 4) { case AUTO: case DYNAMIC: out << symstr(locals[code[ci++]]); break; case MEM: case MEM_SELF: out << mem(ci); break; default: break; } } out << "\n"; return ci; }
static UnitActiveState target_active_state(Unit *u) { assert(u); return state_translation_table[TARGET(u)->state]; }
static void do_inter(struct inter_context* c) { int i, j, k; int result; int dist; int g; int dx, dy; for(i = 0; i < c->count; i++) { c->source[i].x_theta += (c->speed/1000.0); if(c->source[i].x_theta > 2.0*3.14159) c->source[i].x_theta -= 2.0*3.14159; c->source[i].y_theta += (c->speed/1000.0); if(c->source[i].y_theta > 2.0*3.14159) c->source[i].y_theta -= 2.0*3.14159; c->source[i].x = source_x(c, i); c->source[i].y = source_y(c, i); } g = c->grid_size; for(j = 0; j < c->h/g; j++) { for(i = 0; i < c->w/g; i++) { result = 0; for(k = 0; k < c->count; k++) { dx = i*g + g/2 - c->source[k].x; dy = j*g + g/2 - c->source[k].y; dist = sqrt(dx*dx + dy*dy); /* what's the performance penalty here? */ result += (dist >= c->radius ? 0 : c->wave_height[dist]); } result %= c->colors; #ifdef USE_XIMAGE /* Fill in these `gridsize' horizontal bits in the scanline */ for(k = 0; k < g; k++) XPutPixel(c->ximage, (g*i)+k, 0, c->pal[result].pixel); #else /* !USE_XIMAGE */ XFillRectangle(c->dpy, TARGET(c), c->gcs[result], g*i, g*j, g, g); #endif /* !USE_XIMAGE */ } #ifdef USE_XIMAGE /* Only the first scanline of the image has been filled in; clone that scanline to the rest of the `gridsize' lines in the ximage */ for(k = 0; k < (g-1); k++) memcpy(c->ximage->data + (c->ximage->bytes_per_line * (k + 1)), c->ximage->data + (c->ximage->bytes_per_line * k), c->ximage->bytes_per_line); /* Move the bits for this horizontal stripe to the server. */ # ifdef HAVE_XSHM_EXTENSION if (c->use_shm) XShmPutImage(c->dpy, TARGET(c), c->copy_gc, c->ximage, 0, 0, 0, g*j, c->ximage->width, c->ximage->height, False); else # endif /* HAVE_XSHM_EXTENSION */ XPutImage(c->dpy, TARGET(c), c->copy_gc, c->ximage, 0, 0, 0, g*j, c->ximage->width, c->ximage->height); #endif /* USE_XIMAGE */ } #ifdef HAVE_DOUBLE_BUFFER_EXTENSION if (c->back_buf) { XdbeSwapInfo info[1]; info[0].swap_window = c->win; info[0].swap_action = XdbeUndefined; XdbeSwapBuffers(c->dpy, info, 1); } else #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ if (c->pix_buf) { XCopyArea (c->dpy, c->pix_buf, c->win, c->copy_gc, 0, 0, c->w, c->h, 0, 0); } }
static const char *target_sub_state_to_string(Unit *u) { assert(u); return target_state_to_string(TARGET(u)->state); }
int fastboot_init(void *base, unsigned size) { thread_t *thr; dprintf(ALWAYS, "fastboot_init()\n"); download_base = base; download_max = size; mtk_wdt_disable(); /*It will re-enable during continue boot*/ fastboot_register("getvar:", cmd_getvar, FALSE); fastboot_publish("version", "0.5"); #ifndef USER_BUILD fastboot_register("boot", cmd_boot, FALSE); #endif fastboot_register("signature", cmd_install_sig, FALSE); #ifdef MTK_EMMC_SUPPORT fastboot_register("flash:", cmd_flash_emmc, TRUE); #ifndef USER_BUILD fastboot_register("erase:", cmd_erase_emmc, FALSE); #endif #else fastboot_register("flash:", cmd_flash_nand, TRUE); #ifndef USER_BUILD fastboot_register("erase:", cmd_erase_nand, FALSE); #endif #endif fastboot_register("continue", cmd_continue, FALSE); fastboot_register("reboot", cmd_reboot, FALSE); fastboot_register("reboot-bootloader", cmd_reboot_bootloader, FALSE); fastboot_publish("product", TARGET(BOARD)); fastboot_publish("kernel", "lk"); //fastboot_publish("serialno", sn_buf); register_parition_var(); /*LXO: Download related command*/ fastboot_register("download:", cmd_download, TRUE); /*LXO: END!Download related command*/ fastboot_oem_register(); fastboot_register("oem p2u", cmd_oem_p2u, FALSE); fastboot_register("oem reboot-recovery",cmd_oem_reboot2recovery, FALSE); event_init(&usb_online, 0, EVENT_FLAG_AUTOUNSIGNAL); event_init(&txn_done, 0, EVENT_FLAG_AUTOUNSIGNAL); in = udc_endpoint_alloc(UDC_TYPE_BULK_IN, 512); if (!in) goto fail_alloc_in; out = udc_endpoint_alloc(UDC_TYPE_BULK_OUT, 512); if (!out) goto fail_alloc_out; fastboot_endpoints[0] = in; fastboot_endpoints[1] = out; req = udc_request_alloc(); if (!req) goto fail_alloc_req; if (udc_register_gadget(&fastboot_gadget)) goto fail_udc_register; thr = thread_create("fastboot", fastboot_handler, 0, DEFAULT_PRIORITY, 4096); if (!thr) { goto fail_alloc_in; } thread_resume(thr); return 0; fail_udc_register: udc_request_free(req); fail_alloc_req: udc_endpoint_free(out); fail_alloc_out: udc_endpoint_free(in); fail_alloc_in: return -1; }
void setConventions() { calendar = TARGET(); optionBdc = ModifiedFollowing; dayCounter = Actual365Fixed(); }
int TestFromQuantLib() { try { boost::timer timer; std::cout << std::endl; // set up dates Calendar calendar = TARGET(); Date todaysDate(15, May, 1998); Date settlementDate(17, May, 1998); Settings::instance().evaluationDate() = todaysDate; // our options Option::Type type(Option::Put); Real underlying = 36; Real strike = 40; Spread dividendYield = 0.00; Rate riskFreeRate = 0.06; Volatility volatility = 0.20; Date maturity(17, May, 1999); DayCounter dayCounter = Actual365Fixed(); std::cout << "Option type = " << type << std::endl; std::cout << "Maturity = " << maturity << std::endl; std::cout << "Underlying price = " << underlying << std::endl; std::cout << "Strike = " << strike << std::endl; std::cout << "Risk-free interest rate = " << io::rate(riskFreeRate) << std::endl; std::cout << "Dividend yield = " << io::rate(dividendYield) << std::endl; std::cout << "Volatility = " << io::volatility(volatility) << std::endl; std::cout << std::endl; std::string method; std::cout << std::endl; // write column headings Size widths[] = { 35, 14, 14, 14 }; std::cout << std::setw(widths[0]) << std::left << "Method" << std::setw(widths[1]) << std::left << "European" << std::setw(widths[2]) << std::left << "Bermudan" << std::setw(widths[3]) << std::left << "American" << std::endl; std::vector<Date> exerciseDates; for (Integer i = 1; i <= 4; i++) exerciseDates.push_back(settlementDate + 3 * i*Months); boost::shared_ptr<Exercise> europeanExercise( new EuropeanExercise(maturity)); boost::shared_ptr<Exercise> bermudanExercise( new BermudanExercise(exerciseDates)); boost::shared_ptr<Exercise> americanExercise( new AmericanExercise(settlementDate, maturity)); Handle<Quote> underlyingH( boost::shared_ptr<Quote>(new SimpleQuote(underlying))); // bootstrap the yield/dividend/vol curves Handle<YieldTermStructure> flatTermStructure( boost::shared_ptr<YieldTermStructure>( new FlatForward(settlementDate, riskFreeRate, dayCounter))); Handle<YieldTermStructure> flatDividendTS( boost::shared_ptr<YieldTermStructure>( new FlatForward(settlementDate, dividendYield, dayCounter))); Handle<BlackVolTermStructure> flatVolTS( boost::shared_ptr<BlackVolTermStructure>( new BlackConstantVol(settlementDate, calendar, volatility, dayCounter))); boost::shared_ptr<StrikedTypePayoff> payoff( new PlainVanillaPayoff(type, strike)); boost::shared_ptr<BlackScholesMertonProcess> bsmProcess( new BlackScholesMertonProcess(underlyingH, flatDividendTS, flatTermStructure, flatVolTS)); // options VanillaOption europeanOption(payoff, europeanExercise); VanillaOption bermudanOption(payoff, bermudanExercise); VanillaOption americanOption(payoff, americanExercise); // Analytic formulas: // Black-Scholes for European method = "Black-Scholes"; europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new AnalyticEuropeanEngine(bsmProcess))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << "N/A" << std::setw(widths[3]) << std::left << "N/A" << std::endl; // semi-analytic Heston for European method = "Heston semi-analytic"; boost::shared_ptr<HestonProcess> hestonProcess( new HestonProcess(flatTermStructure, flatDividendTS, underlyingH, volatility*volatility, 1.0, volatility*volatility, 0.001, 0.0)); boost::shared_ptr<HestonModel> hestonModel( new HestonModel(hestonProcess)); europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new AnalyticHestonEngine(hestonModel))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << "N/A" << std::setw(widths[3]) << std::left << "N/A" << std::endl; // semi-analytic Bates for European method = "Bates semi-analytic"; boost::shared_ptr<BatesProcess> batesProcess( new BatesProcess(flatTermStructure, flatDividendTS, underlyingH, volatility*volatility, 1.0, volatility*volatility, 0.001, 0.0, 1e-14, 1e-14, 1e-14)); boost::shared_ptr<BatesModel> batesModel(new BatesModel(batesProcess)); europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BatesEngine(batesModel))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << "N/A" << std::setw(widths[3]) << std::left << "N/A" << std::endl; // Barone-Adesi and Whaley approximation for American method = "Barone-Adesi/Whaley"; americanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BaroneAdesiWhaleyApproximationEngine(bsmProcess))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << "N/A" << std::setw(widths[2]) << std::left << "N/A" << std::setw(widths[3]) << std::left << americanOption.NPV() << std::endl; // Bjerksund and Stensland approximation for American method = "Bjerksund/Stensland"; americanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BjerksundStenslandApproximationEngine(bsmProcess))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << "N/A" << std::setw(widths[2]) << std::left << "N/A" << std::setw(widths[3]) << std::left << americanOption.NPV() << std::endl; // Integral method = "Integral"; europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new IntegralEngine(bsmProcess))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << "N/A" << std::setw(widths[3]) << std::left << "N/A" << std::endl; // Finite differences Size timeSteps = 801; method = "Finite differences"; europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new FDEuropeanEngine<CrankNicolson>(bsmProcess, timeSteps, timeSteps - 1))); bermudanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new FDBermudanEngine<CrankNicolson>(bsmProcess, timeSteps, timeSteps - 1))); americanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new FDAmericanEngine<CrankNicolson>(bsmProcess, timeSteps, timeSteps - 1))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << bermudanOption.NPV() << std::setw(widths[3]) << std::left << americanOption.NPV() << std::endl; // Binomial method: Jarrow-Rudd method = "Binomial Jarrow-Rudd"; europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<JarrowRudd>(bsmProcess, timeSteps))); bermudanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<JarrowRudd>(bsmProcess, timeSteps))); americanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<JarrowRudd>(bsmProcess, timeSteps))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << bermudanOption.NPV() << std::setw(widths[3]) << std::left << americanOption.NPV() << std::endl; method = "Binomial Cox-Ross-Rubinstein"; europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<CoxRossRubinstein>(bsmProcess, timeSteps))); bermudanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<CoxRossRubinstein>(bsmProcess, timeSteps))); americanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<CoxRossRubinstein>(bsmProcess, timeSteps))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << bermudanOption.NPV() << std::setw(widths[3]) << std::left << americanOption.NPV() << std::endl; // Binomial method: Additive equiprobabilities method = "Additive equiprobabilities"; europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<AdditiveEQPBinomialTree>(bsmProcess, timeSteps))); bermudanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<AdditiveEQPBinomialTree>(bsmProcess, timeSteps))); americanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<AdditiveEQPBinomialTree>(bsmProcess, timeSteps))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << bermudanOption.NPV() << std::setw(widths[3]) << std::left << americanOption.NPV() << std::endl; // Binomial method: Binomial Trigeorgis method = "Binomial Trigeorgis"; europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<Trigeorgis>(bsmProcess, timeSteps))); bermudanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<Trigeorgis>(bsmProcess, timeSteps))); americanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<Trigeorgis>(bsmProcess, timeSteps))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << bermudanOption.NPV() << std::setw(widths[3]) << std::left << americanOption.NPV() << std::endl; // Binomial method: Binomial Tian method = "Binomial Tian"; europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<Tian>(bsmProcess, timeSteps))); bermudanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<Tian>(bsmProcess, timeSteps))); americanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<Tian>(bsmProcess, timeSteps))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << bermudanOption.NPV() << std::setw(widths[3]) << std::left << americanOption.NPV() << std::endl; // Binomial method: Binomial Leisen-Reimer method = "Binomial Leisen-Reimer"; europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<LeisenReimer>(bsmProcess, timeSteps))); bermudanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<LeisenReimer>(bsmProcess, timeSteps))); americanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<LeisenReimer>(bsmProcess, timeSteps))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << bermudanOption.NPV() << std::setw(widths[3]) << std::left << americanOption.NPV() << std::endl; // Binomial method: Binomial Joshi method = "Binomial Joshi"; europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<Joshi4>(bsmProcess, timeSteps))); bermudanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<Joshi4>(bsmProcess, timeSteps))); americanOption.setPricingEngine(boost::shared_ptr<PricingEngine>( new BinomialVanillaEngine<Joshi4>(bsmProcess, timeSteps))); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << bermudanOption.NPV() << std::setw(widths[3]) << std::left << americanOption.NPV() << std::endl; // Monte Carlo Method: MC (crude) timeSteps = 1; method = "MC (crude)"; Size mcSeed = 42; boost::shared_ptr<PricingEngine> mcengine1; mcengine1 = MakeMCEuropeanEngine<PseudoRandom>(bsmProcess) .withSteps(timeSteps) .withAbsoluteTolerance(0.02) .withSeed(mcSeed); europeanOption.setPricingEngine(mcengine1); // Real errorEstimate = europeanOption.errorEstimate(); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << "N/A" << std::setw(widths[3]) << std::left << "N/A" << std::endl; // Monte Carlo Method: QMC (Sobol) method = "QMC (Sobol)"; Size nSamples = 32768; // 2^15 boost::shared_ptr<PricingEngine> mcengine2; mcengine2 = MakeMCEuropeanEngine<LowDiscrepancy>(bsmProcess) .withSteps(timeSteps) .withSamples(nSamples); europeanOption.setPricingEngine(mcengine2); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << europeanOption.NPV() << std::setw(widths[2]) << std::left << "N/A" << std::setw(widths[3]) << std::left << "N/A" << std::endl; // Monte Carlo Method: MC (Longstaff Schwartz) method = "MC (Longstaff Schwartz)"; boost::shared_ptr<PricingEngine> mcengine3; mcengine3 = MakeMCAmericanEngine<PseudoRandom>(bsmProcess) .withSteps(100) .withAntitheticVariate() .withCalibrationSamples(4096) .withAbsoluteTolerance(0.02) .withSeed(mcSeed); americanOption.setPricingEngine(mcengine3); std::cout << std::setw(widths[0]) << std::left << method << std::fixed << std::setw(widths[1]) << std::left << "N/A" << std::setw(widths[2]) << std::left << "N/A" << std::setw(widths[3]) << std::left << americanOption.NPV() << std::endl; // End test double seconds = timer.elapsed(); Integer hours = int(seconds / 3600); seconds -= hours * 3600; Integer minutes = int(seconds / 60); seconds -= minutes * 60; std::cout << " \nRun completed in "; if (hours > 0) std::cout << hours << " h "; if (hours > 0 || minutes > 0) std::cout << minutes << " m "; std::cout << std::fixed << std::setprecision(0) << seconds << " s\n" << std::endl; return 0; } catch (std::exception& e) { std::cerr << e.what() << std::endl; return 1; } catch (...) { std::cerr << "unknown error" << std::endl; return 1; } }