Real GaussianLHPLossModel::expectedTrancheLossImpl( Real remainingNot, // << at the given date 'd' Real prob, // << at the given date 'd' Real averageRR, // << at the given date 'd' // these are percentual values: Real attachLimit, Real detachLimit) const { if (attachLimit >= detachLimit) return 0.;// or is it an error? // expected remaining notional: if (remainingNot == 0.) return 0.; const Real one = 1.0 - 1.0e-12; // FIXME DUE TO THE INV CUMUL AT 1 const Real k1 = std::min(one, attachLimit /(1.0 - averageRR) ) + QL_EPSILON; const Real k2 = std::min(one, detachLimit /(1.0 - averageRR) ) + QL_EPSILON; if (prob > 0) { const Real ip = InverseCumulativeNormal::standard_value(prob); const Real invFlightK1 = (ip-sqrt1minuscorrel_ * InverseCumulativeNormal::standard_value(k1))/beta_; const Real invFlightK2 = (ip-sqrt1minuscorrel_* InverseCumulativeNormal::standard_value(k2))/beta_; return remainingNot * (detachLimit * phi_(invFlightK2) - attachLimit * phi_(invFlightK1) + (1.-averageRR) * (biphi_(ip, -invFlightK2) - biphi_(ip, -invFlightK1)) ); } else return 0.0; }
void courantIncompressiblePluginFunction::doEvaluation() { autoPtr<volScalarField> pCo( new volScalarField( IOobject( "Co", mesh().time().timeName(), mesh(), IOobject::NO_READ, IOobject::NO_WRITE ), mesh(), dimensionedScalar("nonOr",dimless,0), "zeroGradient" ) ); volScalarField &Co=pCo(); #ifdef FOAM_NO_DIMENSIONEDINTERNAL_IN_GEOMETRIC const_cast<scalarField&>(Co.internalField().field()) = #else Co.internalField() = #endif (0.5*mesh().time().deltaT().value()) *fvc::surfaceSum(mag(phi_()))().internalField() /mesh().V(); Co.correctBoundaryConditions(); result().setObjectResult(pCo); }
Real GaussianLHPLossModel::percentilePortfolioLossFraction( const Date& d, Real perctl) const { // this test goes into basket<<<<<<<<<<<<<<<<<<<<<<<<< QL_REQUIRE(perctl >= 0. && perctl <=1., "Percentile argument out of bounds."); if(perctl==0.) return 0.;// portfl == attach if(perctl==1.) perctl = 1. - QL_EPSILON; // portfl == detach return (1.-averageRecovery(d)) * phi_( ( InverseCumulativeNormal::standard_value(averageProb(d)) + beta_ * InverseCumulativeNormal::standard_value(perctl) ) /sqrt1minuscorrel_); }
void Phi<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { // current time const RealType t = workset.current_time; if (t > 0.0) { // defining phi. Note that phi = 0 if T < Tm and phi = 1 if T > Tm for (std::size_t cell = 0; cell < workset.numCells; ++cell) { for (std::size_t qp = 0; qp < num_qps_; ++qp) { // Compute phi - hyperbolic function of temperature phi_(cell, qp) = 0.5 * (std::tanh((T_(cell, qp) - MeltingTemperature_) / deltaTemperature_) + 1.0); //Compute Phi - linear function of temperature /* if (T_(cell, qp) <= MeltingTemperature_ - deltaTemperature_) phi_(cell, qp) = 0.0; else if (T_(cell, qp) >= MeltingTemperature_ + deltaTemperature_) phi_(cell, qp) = 1.0; else phi_(cell, qp) = (T_(cell, qp) - MeltingTemperature_ + deltaTemperature_)/(2*deltaTemperature_); */ //Compute Phi - cubic function of temperature //define some variables: /* ScalarT detA = 8.0*pow(deltaTemperature_,5.0); ScalarT a = -2.0*pow(deltaTemperature_,2.0)/detA; ScalarT b = 6.0*pow(deltaTemperature_,2.0)*MeltingTemperature_/detA; ScalarT c = -3.0*a*pow((MeltingTemperature_ + deltaTemperature_),2) - 2*b*(MeltingTemperature_ + deltaTemperature_); ScalarT d = -a*pow((MeltingTemperature_ - deltaTemperature_),3) - b*pow((MeltingTemperature_ - deltaTemperature_),2) - c*(MeltingTemperature_ - deltaTemperature_); if (T_(cell, qp) <= MeltingTemperature_ - deltaTemperature_) phi_(cell, qp) = 0.0; else if (T_(cell, qp) >= MeltingTemperature_ + deltaTemperature_) phi_(cell, qp) = 1.0; else phi_(cell, qp) = a*pow(T_(cell, qp),3) + b*pow(T_(cell, qp),2) + c*T_(cell, qp) + d; */ } } } }
Real GaussianLHPLossModel::probOverLoss(const Date& d, Real remainingLossFraction) const { // these test goes into basket<<<<<<<<<<<<<<<<<<<<<<<<< QL_REQUIRE(remainingLossFraction >=0., "Incorrect loss fraction."); QL_REQUIRE(remainingLossFraction <=1., "Incorrect loss fraction."); Real remainingAttachAmount = basket_->remainingAttachmentAmount(); Real remainingDetachAmount = basket_->remainingDetachmentAmount(); // live unerlying portfolio loss fraction (remaining portf fraction) const Real remainingBasktNot = basket_->remainingNotional(d); const Real attach = std::min(remainingAttachAmount / remainingBasktNot, 1.); const Real detach = std::min(remainingDetachAmount / remainingBasktNot, 1.); Real portfFract = attach + remainingLossFraction * (detach - attach); Real averageRR = averageRecovery(d); Real maxAttLossFract = (1.-averageRR); if(portfFract > maxAttLossFract) return 0.; // for non-equity losses add the probability jump at zero tranche // losses (since this method returns prob of losing more or // equal to) if(portfFract <= QL_EPSILON) return 1.; Probability prob = averageProb(d); Real ip = InverseCumulativeNormal::standard_value(prob); Real invFlightK = (ip-sqrt1minuscorrel_* InverseCumulativeNormal::standard_value(portfFract /(1.-averageRR)))/beta_; return phi_(invFlightK);//probOver }
void Psi<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { //grab old phi value Albany::MDArray phi_old = (*workset.stateArrayPtr)[phi_Name_]; //grab old psi value Albany::MDArray psi_old = (*workset.stateArrayPtr)[psi_Name_]; // current time const RealType t = workset.current_time; // // do this only at the beginning if (t == 0.0) { // // initializing psi_ values: for (std::size_t cell = 0; cell < workset.numCells; ++cell) { for (std::size_t qp = 0; qp < num_qps_; ++qp) { psi_(cell, qp) = constant_value_; } } } else { // defining psi_ for (std::size_t cell = 0; cell < workset.numCells; ++cell) { for (std::size_t qp = 0; qp < num_qps_; ++qp) { ScalarT phi_bar = std::max(phi_old(cell, qp), phi_(cell, qp)); psi_(cell, qp) = std::max(psi_old(cell, qp), phi_bar); } } } }
PlasmaModel *WorkThread::updatePlasmaModel() { int size = nc*3/4; //Copy values from array to QVector. Required by QCustomPlot QVector<double> r(size),phi_(size),ne(size),ni(size),npe(size),npi(size); for(int i=0; i<size;i++){ r[i] = r_array[i]; phi_[i] = phi[i]; ne[i] = srho[0][i]; ni[i] = srho[1][i]; npe[i] = np_hist[0][i]; npi[i] = np_hist[1][i]; } //Set the vectors into model plasma->setR(r); plasma->setPhiDistribution(phi_); plasma->setElectronConcDistribution(ne); plasma->setIonConcDistribution(ni); plasma->setElectronsNumber(npe); plasma->setIonsNumber(npi); return plasma; }
virtual Real shortRate(Time t, Real y) const { return y*y + phi_(t); }
virtual Real variable(Time t, Rate r) const { return std::sqrt(r - phi_(t)); }
Real Generalized_HullWhite::expectation(Time s, Time t, Rate x) { Real temp = ( x - phi_(s) ) * std::exp(- a0_ * (t-s) ); temp += phi_(t); return temp; }