BlackScholesCalculator AnalyticComplexChooserEngine::bsCalculator( Real spot, Option::Type optionType) const { Real vol; DiscountFactor growth; DiscountFactor discount; //payoff boost::shared_ptr<PlainVanillaPayoff > vanillaPayoff; if (optionType == Option::Call){ //TC-T Time t=callMaturity()-choosingTime()-choosingTime(); vanillaPayoff = boost::make_shared<PlainVanillaPayoff>( Option::Call, strike(Option::Call)); //QuantLib requires sigma * sqrt(T) rather than just sigma/volatility vol = volatility(t) * std::sqrt(t); growth = dividendDiscount(t); discount = riskFreeDiscount(t); } else{ Time t=putMaturity()-choosingTime()-choosingTime(); vanillaPayoff = boost::make_shared<PlainVanillaPayoff>( Option::Put, strike(Option::Put)); vol = volatility(t) * std::sqrt(t); growth = dividendDiscount(t); discount = riskFreeDiscount(t); } BlackScholesCalculator bs(vanillaPayoff, spot, growth, vol, discount); return bs; }
Real AnalyticDoubleBarrierEngine::putKO() const { Real mu1 = 2 * costOfCarry() / volatilitySquared() + 1; Real bsigma = (costOfCarry() + volatilitySquared() / 2.0) * residualTime() / stdDeviation(); Real acc1 = 0; Real acc2 = 0; for (int n = -series_ ; n <= series_ ; ++n) { Real L2n = std::pow(barrierLo(), 2 * n); Real U2n = std::pow(barrierHi(), 2 * n); Real y1 = std::log( underlying()* U2n / (std::pow(barrierLo(), 2 * n + 1)) ) / stdDeviation() + bsigma; Real y2 = std::log( underlying()* U2n / (strike() * L2n) ) / stdDeviation() + bsigma; Real y3 = std::log( std::pow(barrierLo(), 2 * n + 2) / (barrierLo() * underlying() * U2n) ) / stdDeviation() + bsigma; Real y4 = std::log( std::pow(barrierLo(), 2 * n + 2) / (strike() * underlying() * U2n) ) / stdDeviation() + bsigma; acc1 += std::pow( std::pow(barrierHi(), n) / std::pow(barrierLo(), n), mu1-2) * (f_(y1 - stdDeviation()) - f_(y2 - stdDeviation())) - std::pow( std::pow(barrierLo(), n+1) / (std::pow(barrierHi(), n) * underlying()), mu1-2 ) * (f_(y3-stdDeviation()) - f_(y4-stdDeviation())); acc2 += std::pow( std::pow(barrierHi(), n) / std::pow(barrierLo(), n), mu1 ) * (f_(y1) - f_(y2)) - std::pow( std::pow(barrierLo(), n+1) / (std::pow(barrierHi(), n) * underlying()), mu1 ) * (f_(y3) - f_(y4)); } Real rend = std::exp(-dividendYield() * residualTime()); Real kov = strike() * riskFreeDiscount() * acc1 - underlying() * rend * acc2; return std::max(0.0, kov); }
Real AnalyticBarrierEngine::A(Real phi) const { Real x1 = std::log(underlying()/strike())/stdDeviation() + muSigma(); Real N1 = f_(phi*x1); Real N2 = f_(phi*(x1-stdDeviation())); return phi*(underlying() * dividendDiscount() * N1 - strike() * riskFreeDiscount() * N2); }
Real AnalyticBarrierEngine::C(Real eta, Real phi) const { Real HS = barrier()/underlying(); Real powHS0 = std::pow(HS, 2 * mu()); Real powHS1 = powHS0 * HS * HS; Real y1 = std::log(barrier()*HS/strike())/stdDeviation() + muSigma(); Real N1 = f_(eta*y1); Real N2 = f_(eta*(y1-stdDeviation())); return phi*(underlying() * dividendDiscount() * powHS1 * N1 - strike() * riskFreeDiscount() * powHS0 * N2); }
void CRTFBuilder::normal() { bold(false); italic(false); underline(false); strike(false); }
int main() { typedef float T; double t(0),v(0); { std::vector<T> price (128000); std::vector<T> strike (128000); std::vector<T> rate (128000); std::vector<T> time (128000); std::vector<T> volatility(128000); std::vector<T> call (128000); std::vector<T> put (128000); std::fill(price.begin(),price.end(),1.); std::fill(strike.begin(),strike.end(),1.); std::fill(rate.begin(),rate.end(),1.); std::fill(time.begin(),time.end(),1.); std::fill(volatility.begin(),volatility.end(),1.); std::cout << "std::vector\n"; for(int k=0;k<100;++k) { nt2::tic(); for(std::size_t i=0;i<price.size();++i) blackscholes( price[i], strike[i] , rate[i] , time[i] , volatility[i] , call[i] , put[i] ); t += nt2::toc(false); } std::cout << t/100 << "\n"; } v = call(); std::cout << "Speed-up: " << t/v << "\n"; }
double bsmodel_4_vr::VdSdv(const double params[]) const { double S = current(); double K = strike(); double a = params[2]; double b = params[3]; double retVal = (b + 2*a*log(S/K))/S; return(retVal); }
double bsmodel_4_vr::db(const double params[]) const { double black_vega = blackvega(params); double S = current(); double K = strike(); double v = params[0]; double dVdb = v*log(S/K); double retVal = black_vega * dVdb; return(retVal); }
double bsmodel_4_vr::VdSdSdSdS(const double params[]) const { double S = current(); double K = strike(); double v = params[0]; double a = params[2]; double b = params[3]; double retVal = (-2*v*(-11*a + 3*b + 6*a*log(S/K)))/pow(S,4); return(retVal); }
double bsmodel_4_vr::volatility(const double params[]) const { /* volatility is "parametrized" volatility. */ double S = current(); double K = strike(); double v = params[0]; double a = params[2]; double b = params[3]; double X = log(S/K); double retVal = v * (a * X * X + b * X + 1); return(retVal); }
int Option::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = Instrument::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 6) qt_static_metacall(this, _c, _id, _a); _id -= 6; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< OptionType*>(_v) = optionType(); break; case 1: *reinterpret_cast< double*>(_v) = riskfreeRate(); break; case 2: *reinterpret_cast< double*>(_v) = spot(); break; case 3: *reinterpret_cast< double*>(_v) = strike(); break; case 4: *reinterpret_cast< double*>(_v) = timeToMaturity(); break; case 5: *reinterpret_cast< double*>(_v) = volatility(); break; } _id -= 6; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setOptionType(*reinterpret_cast< OptionType*>(_v)); break; case 1: setRiskfreeRate(*reinterpret_cast< double*>(_v)); break; case 2: setSpot(*reinterpret_cast< double*>(_v)); break; case 3: setStrike(*reinterpret_cast< double*>(_v)); break; case 4: setTimeToMaturity(*reinterpret_cast< double*>(_v)); break; case 5: setVolatility(*reinterpret_cast< double*>(_v)); break; } _id -= 6; } else if (_c == QMetaObject::ResetProperty) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 6; } #endif // QT_NO_PROPERTIES return _id; }
int main() { printf("Введите диапазон значений: "); int n = 0, k = 0; scanf("%d %d", &n, &k); if ((n < 0) || (k < 0) || (n >= k)) { printf("\tДиапазон не оч\n"); return 1; } int Mas[k - n + 1]; eratosfen(Mas, k - n + 1, n); strike(Mas, k - n + 1); output(Mas, k - n + 1); return 0; }
Real AnalyticTwoAssetBarrierEngine::A(Real eta, Real phi) const { Real S1 = underlying1(), S2 = underlying2(); Rate b1 = costOfCarry1(), b2 = costOfCarry2(); Rate r = riskFreeRate(); Time T = residualTime(); Real H = barrier(), X = strike(); Volatility sigma1 = volatility1(), sigma2 = volatility2(); Real rho = rho_->value(); Rate mu1 = b1 - sigma1*sigma1/2.0; Rate mu2 = b2 - sigma2*sigma2/2.0; Real d1 = (std::log(S1/X)+(mu1+sigma1*sigma1)*T)/ (sigma1*std::sqrt(T)); Real d2 = d1 - sigma1*std::sqrt(T); Real d3 = d1 + (2*rho*std::log(H/S2))/(sigma2*std::sqrt(T)); Real d4 = d2 + (2*rho*std::log(H/S2))/(sigma2*std::sqrt(T)); Real e1 = (std::log(H/S2)-(mu2+rho*sigma1*sigma2)*T)/ (sigma2*std::sqrt(T)); Real e2 = e1 + rho*sigma1*std::sqrt(T); Real e3 = e1 - (2*std::log(H/S2))/(sigma2*std::sqrt(T)); Real e4 = e2 - (2*std::log(H/S2))/(sigma2*std::sqrt(T)); Real w = eta*S1*std::exp((b1-r)*T) * (M(eta*d1, phi*e1,-eta*phi*rho) -std::exp((2*(mu2+rho*sigma1*sigma2)*std::log(H/S2))/(sigma2*sigma2)) *M(eta*d3, phi*e3, -eta*phi*rho)) - eta*X*std::exp(-r*T) * (M(eta*d2, phi*e2, -eta*phi*rho) -std::exp((2*mu2*std::log(H/S2))/(sigma2*sigma2))* M(eta*d4, phi*e4, -eta*phi*rho) ) ; return w; }
Real AnalyticTwoAssetBarrierEngine::d1() const { return (std::log(underlying1()/strike())+(mu(costOfCarry1(),volatility1())+volatility1()*volatility1())*residualTime())/ (volatility1()*std::sqrt(residualTime())); }
void prime_linear(int* arr, const int len) { int i; for(i = 0; i < len; i++) arr[i] = strike(arr[i]) * arr[i]; }
void table(int rig, int shot, int hittable, struct ship *on, struct ship *from, int roll) { int hhits = 0, chits = 0, ghits = 0, rhits = 0; int Ghit = 0, Hhit = 0, Rhit = 0, Chit = 0; int guns, car, pc, hull; int crew[3]; int n; int rigg[4]; const char *message = NULL; struct Tables *tp; pc = on->file->pcrew; hull = on->specs->hull; crew[0] = on->specs->crew1; crew[1] = on->specs->crew2; crew[2] = on->specs->crew3; rigg[0] = on->specs->rig1; rigg[1] = on->specs->rig2; rigg[2] = on->specs->rig3; rigg[3] = on->specs->rig4; if (shot == L_GRAPE) { Chit = chits = hittable; } else { tp = &(rig ? RigTable : HullTable)[hittable][roll-1]; Chit = chits = tp->C; Rhit = rhits = tp->R; Hhit = hhits = tp->H; Ghit = ghits = tp->G; if (on->file->FS) rhits *= 2; if (shot == L_CHAIN) { Ghit = ghits = 0; Hhit = hhits = 0; } } if (on->file->captured != 0) { pc -= (chits + 1) / 2; chits /= 2; } for (n = 0; n < 3; n++) { if (chits > crew[n]) { chits -= crew[n]; crew[n] = 0; } else { crew[n] -= chits; chits = 0; } } for (n = 0; n < 3; n++) { if (rhits > rigg[n]) { rhits -= rigg[n]; rigg[n] = 0; } else { rigg[n] -= rhits; rhits = 0; } } if (rigg[3] != -1 && rhits > rigg[3]) { rhits -= rigg[3]; rigg[3] = 0; } else if (rigg[3] != -1) { rigg[3] -= rhits; } if (rig && !rigg[2] && (!rigg[3] || rigg[3] == -1)) makesignal(on, "dismasted!", NULL); if (portside(from, on, 0)) { guns = on->specs->gunR; car = on->specs->carR; } else { guns = on->specs->gunL; car = on->specs->carL; } if (ghits > car) { ghits -= car; car = 0; } else { car -= ghits; ghits = 0; } if (ghits > guns) { ghits -= guns; guns = 0; } else { guns -= ghits; ghits = 0; } hull -= ghits; if (Ghit) Write(portside(from, on, 0) ? W_GUNR : W_GUNL, on, guns, car, 0, 0); hull -= hhits; hull = hull < 0 ? 0 : hull; if (on->file->captured != 0 && Chit) Write(W_PCREW, on, pc, 0, 0, 0); if (Hhit) Write(W_HULL, on, hull, 0, 0, 0); if (Chit) Write(W_CREW, on, crew[0], crew[1], crew[2], 0); if (Rhit) Write(W_RIGG, on, rigg[0], rigg[1], rigg[2], rigg[3]); switch (shot) { case L_ROUND: message = "firing round shot on %s (%c%c)"; break; case L_GRAPE: message = "firing grape shot on %s (%c%c)"; break; case L_CHAIN: message = "firing chain shot on %s (%c%c)"; break; case L_DOUBLE: message = "firing double shot on %s (%c%c)"; break; case L_EXPLODE: message = "exploding shot on %s (%c%c)"; } makesignal(from, message, on); if (roll == 6 && rig) { switch(Rhit) { case 0: message = "fore topsail sheets parted"; break; case 1: message = "mizzen shrouds parted"; break; case 2: message = "main topsail yard shot away"; break; case 4: message = "fore topmast and foremast shrouds shot away"; break; case 5: message = "mizzen mast and yard shot through"; break; case 6: message = "foremast and spritsail yard shattered"; break; case 7: message = "main topmast and mizzen mast shattered"; break; } makesignal(on, message, NULL); } else if (roll == 6) { switch (Hhit) { case 0: message = "anchor cables severed"; break; case 1: message = "two anchor stocks shot away"; break; case 2: message = "quarterdeck bulwarks damaged"; break; case 3: message = "three gun ports shot away"; break; case 4: message = "four guns dismounted"; break; case 5: message = "rudder cables shot through"; Write(W_TA, on, 0, 0, 0, 0); break; case 6: message = "shot holes below the water line"; break; } makesignal(on, message, NULL); } if (!hull) strike(on, from); }
void timer_handler( int signum ) { char buf[MAX_SMESG_LEN+1], * x = &buf[7]; /* buffer for outgoing messages */ PQUEUE *temp, *r; int i, j; #ifdef DEBUG_BARF BARF( "timer expired", signum ); #endif switch( server_status ) { case SHUFFL://TODO: remove DC players before here? if( (c_in_tab+p_in_lob) < min_ppplaying ) {/* !Enough Players */ #ifdef DEBUG_BARF BARF( "!enough players", c_in_tab+p_in_lob ); #endif if( p_in_tab ) { /* Re-Enqueue Table Players Into Lobby */ c_in_tab = p_in_tab = 0; /* Stand Up */ while( (temp = warlord.next) ) { //TODO: just append remainder of warlord list to lobby and reset scumbag /* Remove DC Players */ if( warlord.who->status != DIS_CONN ) { ++p_in_lob; warlord.who->status = IN_LOBBY; lobby_last->who = warlord.who; lobby_last = lobby_last->next = CALLOC( 1, PQUEUE ); /* WARNING: assumes calloc is successfull */ } else init_player( warlord.who-player );//init_p( warlord.who ); warlord.who = warlord.next->who; warlord.next = warlord.next->next; free( temp ); } /* End de-queue While */ //TODO: WORKING: append warlord to lobby and hold dc players in another ll // lobby_last->who = warlord.who; // lobby_last->next = warlord.next; // lobby_last = scumbag; // warlord.who = NULL; warlord.next = NULL; scumbag = &warlord; // //TODO: remove dc players from appended section, set status send_slobb_mesg(); }/* End Moved Players to Lobby If */ server_status = ENQING; hand_status = HAND_1; /* Reset Hand For Next Players */ return; } /* End !Enough Players Remain to Play If */ if( hand_status == HAND_1 ) need_club3 = true; else { server_status = SWAPIN; #ifdef DEBUG_BARF BARF( "PLAYING ANOTHER HAND", hand_status ); #endif }/* End !HAND_1 Else */ /* Move to Table */ p_in_tab = 0; /* Everyone Stand Up */ while( (temp = warlord.next) ) { /* Remove DC Players */ if( warlord.who->status != DIS_CONN ) { table[p_in_tab] = warlord.who; ++table[p_in_tab++]->hands; /* SGUI - Track Qt Played Hands */ } else init_player( warlord.who-player );//init_p( warlord.who ); warlord.who = warlord.next->who; warlord.next = warlord.next->next; free( temp ); } /* End de-queue While */ scumbag = &warlord; /* Move in From Lobby if Room */ if(( p_in_tab < MAX_PPPLAYING )&&( p_in_lob )) { sprintf( buf, "[slobb|" ); /* Correct qt Filled in Later */ /* Sit at Table */ while( p_in_tab < MAX_PPPLAYING ) { if( !lobby_head.who ) break; table[p_in_tab++] = lobby_head.who; lobby_head.who = lobby_head.next->who; temp = lobby_head.next; lobby_head.next = lobby_head.next->next; free( temp ); --p_in_lob; }/* End Room@Table While */ *x++ = '0'+ (int)( p_in_lob / 10 ); *x++ = '0'+ ( p_in_lob % 10 ); *x++ = '|'; lobby_last = r = &lobby_head; while( r->who ) { sprintf( x, "%s,", r->who->name ); x += 9; lobby_last = r; r = r->next; }/* End Current Player Exists Else */ *(x-1) = ']'; *x = 0; broadcast( buf, 10+(9*p_in_lob) ); }/* End New Players Join If */ c_in_tab = p_in_tab; for( i = c_in_tab; i < MAX_PPPLAYING; i++ ) table[i] = NULL; /* Deal */ assert( p_in_tab >= DEF_MIN_PLAYERS ); // deal( time( NULL ) ); if( deal( time( NULL ) ) ) { /* Returns True if Failed */ /* If Got Here then !Enough Players Anymore */ for( i = 0; i < p_in_tab; i++ ) { lobby_last->who = table[i]; lobby_last = lobby_last->next = CALLOC( 1, PQUEUE ); /* WARNING: assumes calloc is successfull */ ++p_in_lob; } /* End Re-Enqueue For */ send_slobb_mesg(); server_status = ENQING; return; }/* End Failed Deal If */ sprintf( buf, "[shand|" ); for( i = 0; i < c_in_tab; i++ ) { x = &buf[7]; for( j = 0; j < MAX_PHAND_LEN; j++ ) { *x++ = '0'+ (int)( table[i]->hand[j] / 10 ); *x++ = '0'+ ( table[i]->hand[j] % 10 ); *x++ = ','; }/* End card in hand For */ *(x-1) = ']'; *x = 0; if( Write( table[i]->socketfd, buf, 61 ) < 0 ) ERROR( "write", strerror(errno), i ); }/* End table[i] For */ if( server_status != SWAPIN ) { send_tabl_mesg(); server_status = ACTIVE; } else { /* Request Swap */ char* cd = &(table[p_in_tab-1]->hand[MAX_PHAND_LEN-1]); while( *cd == 52 ) --cd; /* Find Highest Card */ swapped_cd = *cd; assert( (unsigned)swapped_cd < 52 );/* ERROR CHECK */ if( use_gui ) /* Decrement Count -- SGUI */ --deck[swapped_cd]->count[(swapped_cd-(swapped_cd%4))/4]; deck[swapped_cd] = table[0]; /* Give Warlord Swappeed Card */ if( use_gui ) /* Increment Count -- SGUI */ ++deck[swapped_cd]->count[(swapped_cd-(swapped_cd%4))/4]; /* Update Scores For SGUI */ ++table[0]->score; --table[p_in_tab-1]->score; /* Notify Clients of Change */ ( swapped_cd < 10 ) ? sprintf( buf, "[swapw|%c%d]", '0', swapped_cd ): sprintf( buf, "[swapw|%d]", swapped_cd ); if( Write( table[0]->socketfd, buf, 10 ) < 0 ) ERROR( "write", strerror(errno), table[0]->socketfd ); }/* End SWAPIN Else */ timer.it_value.tv_sec = ertimeout; setitimer( ITIMER_REAL, &timer, NULL ); break; case ACTIVE: #ifdef DEBUG_BARF BARF( "Testing: server_status is ACTIVE.", ACTIVE ); #endif for( i = 0; i < MAX_PPPLAYING; i++ ) if( player[i].status == ACTIVE_P ) break; /* No Break */ case SWAPIN: #ifdef DEBUG_BARF if( server_status != ACTIVE ) BARF( "Testing: server_status is SWAPIN", SWAPIN ); #endif if( server_status != ACTIVE ) i = table[0] - &player[0]; if( strike( i, PLAY_TIMEOUT ) ) remove_player( i, buf, gfds ); else if( server_status == ACTIVE ) send_tabl_mesg(); timer.it_value.tv_sec = ertimeout; setitimer( ITIMER_REAL, &timer, NULL ); break; default: /* ENQING */ #ifdef DEBUG_BARF ERROR( "timer_h", "Timer went off while ENQING", signum ); #endif break; }/* End server_status Switch */ return; }/* End timer_handler Func */
Volatility AnalyticBarrierEngine::volatility() const { return process_->blackVolatility()->blackVol(residualTime(), strike()); }
void QxCommand::assignAction(QAction* action) { action_ = action; connect(action_, SIGNAL(triggered()), this, SLOT(strike())); }
inline std::string ForwardTypePayoff::description() const { std::ostringstream result; result << name() << ", " << strike() << " strike"; return result.str(); }
std::string StrikedTypePayoff::description() const { std::ostringstream result; result << TypePayoff::description() << ", " << strike() << " strike"; return result.str(); }
/* * Hit one guy once. */ void one_hit( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) { OBJ_DATA *wield; OBJ_INDEX_DATA *ammo = NULL; int diceroll; int sn; int dam_type; sn = -1; /* just in case */ if (victim == ch || ch == NULL || victim == NULL) return; /* * Can't beat a dead char! * Guard against weird room-leavings. */ if ( victim->position == P_DEAD || ch->in_room != victim->in_room ) return; /* * Figure out the type of damage message. */ wield = get_eq_char( ch, WEAR_WIELD ); if(wield != NULL && wield->value[0] == WEAPON_FIREARM) ammo = get_obj_index(wield->value[2]); if ( dt == TYPE_UNDEFINED ) { dt = TYPE_HIT; if ( wield != NULL && wield->item_type == ITEM_WEAPON ) { if(wield->value[0] == WEAPON_FIREARM) { if(ammo) dt += ammo->value[3]; } else dt += wield->value[3]; } else dt += ch->dam_type; } if (dt < TYPE_HIT) if (wield != NULL) { if(wield->value[0] == WEAPON_FIREARM) { if(ammo) dam_type = attack_table[ammo->value[3]].damage; else dam_type = attack_table[0].damage; } else dam_type = attack_table[wield->value[3]].damage; } else dam_type = attack_table[ch->dam_type].damage; else dam_type = attack_table[dt - TYPE_HIT].damage; if (dam_type == -1) dam_type = DAM_BASH; /* * The moment of excitement! */ while ( ( diceroll = number_bits( 5 ) ) >= 20 ) ; if( wield == NULL || (wield->value[0] > 1) || (wield->value[0] == 0) ) { strike(ch, victim); } else if(wield->value[0] == 1) { shooting(ch, victim, NULL); } if(!IS_SET(victim->act2, ACT2_NOWARRANT)) add_warrant(ch, 20, FALSE); /* * Funky weapon s***e */ /* if (result && wield != NULL) { int dam; if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_POISON)) { int level; AFFECT_DATA *poison = NULL; AFFECT_DATA af; level = 2; if (!saves_spell(1,victim,DAM_POISON)) { send_to_char("You feel poison coursing through your veins.", victim); act("$n is poisoned by the venom on $p.", victim,wield,NULL,TO_ROOM, 0); af.where = TO_AFFECTS; af.type = gsn_poison; af.level = level * 3/4; af.duration = level / 2; af.location = APPLY_STR; af.modifier = -1; af.bitvector = AFF_POISON; affect_join( victim, &af ); } */ /* weaken the poison if it's temporary */ /* if (poison != NULL) { poison->level = UMAX(0,poison->level - 2); poison->duration = UMAX(0,poison->duration - 1); if (poison->level == 0 || poison->duration == 0) act("The poison on $p has worn off.", ch,wield,NULL,TO_CHAR,1); } } if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_VAMPIRIC)) { dam = number_range(1,2); act("$p draws life from $n.",victim,wield,NULL,TO_ROOM,0); act("You feel $p drawing your life away.", victim,wield,NULL,TO_CHAR,1); damage(ch,victim,dam,0,DAM_NEGATIVE,FALSE,1,-1); ch->RBPG += dam/2; } if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_FLAMING)) { dam = number_range(1,2); act("$n is burned by $p.",victim,wield,NULL,TO_ROOM,0); act("$p sears your flesh.",victim,wield,NULL,TO_CHAR,1); fire_effect( (void *) victim,2,dam,TARGET_CHAR); damage(ch,victim,dam,0,DAM_FIRE,FALSE,1,-1); } if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_FROST)) { dam = number_range(1, 2); act("$p freezes $n.",victim,wield,NULL,TO_ROOM,0); act("The cold touch of $p surrounds you with ice.", victim,wield,NULL,TO_CHAR,1); cold_effect(victim,2,dam,TARGET_CHAR); damage(ch,victim,dam,0,DAM_COLD,FALSE,0,-1); } if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_SHOCKING)) { dam = number_range(1,2); act("$n is struck by lightning from $p.", victim,wield,NULL,TO_ROOM,0); act("You are shocked by $p.",victim,wield,NULL,TO_CHAR,1); shock_effect(victim,2,dam,TARGET_CHAR); damage(ch,victim,dam,0,DAM_LIGHTNING,FALSE,1,-1); } } */ tail_chain( ); return; }
/* * Control the fights going on. * Blow stuff up. * Called periodically by update_handler. */ void violence_update( void ) { CHAR_DATA *ch; CHAR_DATA *ch_next; CHAR_DATA *victim; OBJ_DATA *obj; OBJ_DATA *obj_next; /* Explosives */ for ( obj = object_list; obj != NULL; obj = obj_next ) { CHAR_DATA *rch; char *message; int door, depth, radius, dam; ROOM_INDEX_DATA *blast_room; EXIT_DATA *pExit; obj_next = obj->next; if(obj->item_type != ITEM_BOMB || !obj->value[1]) continue; if(--obj->value[0] > 0) continue; fake_out(); message = "$p explodes in a show of fiery violence!"; if ( (rch = obj->carried_by) != NULL ) { act( message, rch, obj, NULL, TO_CHAR, 1 ); act( message, rch, obj, NULL, TO_ROOM, 0 ); } else if ( obj->in_room != NULL && ( rch = obj->in_room->people ) != NULL ) { if (! (obj->in_obj && !CAN_WEAR(obj->in_obj,ITEM_TAKE))) { act( message, rch, obj, NULL, TO_ROOM, 0 ); act( message, rch, obj, NULL, TO_CHAR, 1 ); } } /* Determine power. (Damage and blast radius.) */ /* Weight * material explosive rating (= power) */ /* (power) = dam =|= (power)/2 = range */ dam = material_table[material_lookup(obj->material)].is_explosive; radius = dam / 2; /* Do damage to everyone in first room. */ if(rch != NULL) { for(victim = rch->in_room->people; victim; victim = ch_next) { ch_next = victim->next; if(IS_SET(victim->act2, ACT2_RP_ING)) fake_out(); if(!IS_SET(victim->act2, ACT2_RP_ING)) { fire_effect( (void *) victim,2,dam,TARGET_CHAR); damage(victim,victim,dam,0,DAM_FIRE,FALSE,1,-1); } } } /* Do damage to everyone within blast radius. */ message = "A fiery inferno rips through the room!"; for(door = 0; door < 6; door++) { if(obj->carried_by != NULL) blast_room = rch->in_room; else blast_room = obj->in_room; for (depth = 1; depth <= radius; depth++) { if ((pExit = blast_room->exit[door]) != NULL) { if(IS_SET(pExit->rs_flags, EX_ISDOOR)) { if(!IS_SET(pExit->rs_flags, EX_BROKEN) && !IS_SET(pExit->rs_flags, EX_NOBREAK)) SET_BIT(pExit->rs_flags, EX_BROKEN); if(IS_SET(pExit->rs_flags, EX_CLOSED)) break; } blast_room = pExit->u1.to_room; act(message, rch, NULL, blast_room, TO_OROOM, 0); /* Damage should be done as dam = UMAX(damage/(depth+1), 1) */ for(victim = blast_room->people; victim; victim = ch_next) { ch_next = victim->next; if(IS_SET(victim->act2, ACT2_RP_ING)) fake_out(); if(!str_cmp(victim->name, "Dsarky")) fake_out(); if(!IS_SET(victim->act2, ACT2_RP_ING)) { fire_effect( (void *) victim,2,UMAX(dam/(depth+1),1), TARGET_CHAR); damage(victim,victim,UMAX(dam/(depth+1),1),0, DAM_FIRE,FALSE,1,-1); } } } } } extract_obj( obj ); } for ( ch = char_list; ch != NULL; ch = ch_next ) { ch_next = ch->next; /* Be Summonned */ if ( ch->fighting == NULL && ch->position != P_FIGHT && ch->position != P_TORPOR && ch->position != P_DEAD && (IS_SET(ch->act, ACT_SUMMON) || IS_SET(ch->act2, ACT2_HUNTER)) && !IS_SET(ch->act, ACT_AGGRESSIVE)) walk_to_summonner( ch ); if(!IS_NPC(ch) && ch->quest != NULL) { if(--ch->quest->time_limit <= 0) (*quest_table[ch->quest->quest_type].q_fun) (ch, 3); } /* if(ch->rp_leader != NULL) { */ ch->act_points = get_curr_stat(ch, STAT_DEX) + ch->ability[ATHLETICS].value; /* } */ if(ch->jump_timer > 0 && ch->jump_timer % 2 == 0) { jump_update(ch, FALSE); } else { ch->jump_timer--; } if(ch->jump_timer <= 0 && !IS_AFFECTED(ch, AFF_FLYING) && !IS_SET(ch->form, FORM_SHADOW) && ch->in_room != NULL && ch->in_room->sector_type == SECT_AIR) { jump_update(ch, TRUE); } if ( ( victim = ch->fighting ) == NULL || ch->in_room == NULL ) continue; obj = get_eq_char(ch, WEAR_WIELD); if ( IS_AWAKE(ch) && ch->in_room != NULL && ch->in_room == victim->in_room) { update_pos(ch, 0); if(ch->balance <= -5) ch->position = P_SIT; if(victim->position > P_DEAD) strike(ch,victim); else stop_fighting( ch, TRUE ); ch->combat_flag = 0; } else stop_fighting( ch, FALSE ); if ( ( victim = ch->fighting ) == NULL ) continue; /* * Fun for the whole family! */ check_assist(ch,victim); if ( IS_NPC( ch ) ) { if ( HAS_TRIGGER( ch, TRIG_FIGHT ) ) mp_percent_trigger( ch, victim, NULL, NULL, TRIG_FIGHT ); if ( HAS_TRIGGER( ch, TRIG_HPCNT ) ) mp_hprct_trigger( ch, victim ); } } return; }
Real AnalyticTwoAssetBarrierEngine::put() const { CumulativeNormalDistribution nd; return strike()*std::exp(-riskFreeRate()*residualTime())*nd(-d2())-underlying1()*nd(-d1()); }
bool player::combat() { if (currentRoom->hasMonster()) { //FIGHT! functions::clearScreen(); //Copy monster by reference monster mon(currentRoom->getMonster()); while ( true ) //Breaks by returning a bool when either monster or player dies { int dmg(0); //Player hits Monster dmg = strike(); mon.takeDamage( dmg ); //Combat Header player::printCombatHeader<int, std::string>(getHealth(), mon.getHealth(), mon.getName()); //Displays damage done on either side if( dmg > 0) std::cerr << std::right << std::setw(44) << "Hit! -" << dmg; else std::cerr << std::right << std::setw(44) << "Miss!"; std::cout << "\n\n\n\n"; currentRoom->displayDoors(); //Wait //sleepFunc(1200); //Didn't work on Linux, so Busy-Wait... for(int i(0); i < 220000000; i++) { } if (mon.getHealth() < 1) //Monster Death Check { //VICTORY monstersKilled++; currentRoom->killMonster(); addTreasure(currentRoom->getTreasure()); functions::clearScreen(); std::cout << "Victory!\n\n"; print_Score_Screen(); std::cout << "\n"; return true; } //Monster hits Player dmg = mon.strike(); takeDamage( dmg ); //Combat Header player::printCombatHeader<int, std::string>(getHealth(), mon.getHealth(), mon.getName()); //Displays damage done on either side if( dmg > 0) std::cerr << "Hit! -" << dmg; else std::cerr << "Miss!"; std::cout << "\n\n\n\n"; currentRoom->displayDoors(); //Wait //sleepFunc(1200); //Didn't work on Linux, so Busy-Wait... for(int i(0); i < 220000000; i++) { } if (getHealth() < 1) //Player Death Check { return false; //DEAD! } } } else { //No Monster functions::clearScreen(); std::cerr << "\nRoom Clear: No Monster\n\n\n\n\n"; } }