DayCounter ComponentMust::eff_convert_basis(std::string basis) const { //cette fonction fait la conversion //de la convention de calcul (basis) de type string lue de XML de MUST // daycounter; if (basis == "A360") return Actual360(); if (basis == "A365") return Actual365Fixed(); if (basis == "Actual") return ActualActual(); if (basis == "Daily Price") return OneDayCounter(); if (basis == "Business 252") return Business252(); if (basis == "JGB") return Actual365NoLeap(); if (basis == "30/360") return Thirty360(Thirty360::EurobondBasis); return Thirty360(); }
explicit CADLiborON(const Handle<YieldTermStructure>& h = Handle<YieldTermStructure>()) : DailyTenorLibor("CADLibor", 0, CADCurrency(), Canada(), Actual360(), h) {}
void SwaptionVolatilityHullWhite::performCalculations() const { SwaptionVolatilityDiscrete::performCalculations(); // we might use iterators here... for (Size i=0; i<volatilities_.rows(); ++i) for (Size j=0; j<volatilities_.columns(); ++j) volatilities_[i][j] = volHandles_[i][j]->value(); interpolation_.update(); //LevenbergMarquardt lm; Simplex sp(0.001); // we should use another optimizer here... EndCriteria ec(1000,500,1E-8,1E-8,1E-8); NoConstraint cons; Array val(1); for(Size i=0; i<optionTenors_.size() ; i++) { for(Size j=0; j<swapTenors_.size() ; j++) { boost::shared_ptr<SwaptionHelper> sh(new SwaptionHelper(optionTenors_[i],swapTenors_[j],Handle<Quote>(new SimpleQuote(volatilities_[i][j])),indexBase_->iborIndex(),indexBase_->fixedLegTenor(), indexBase_->dayCounter(),Actual360(),yts_)); // FIXME float leg day counter hardcoded ? boost::shared_ptr<HullWhite> hwTmp(new HullWhite(yts_,reversion_)); boost::shared_ptr<JamshidianSwaptionEngine> jamshidianEngine(new JamshidianSwaptionEngine(hwTmp,yts_)); sh->setPricingEngine(jamshidianEngine); calibrationFunction cfct(hwTmp,sh); val[0]=sqrt(0.01); Problem p(cfct,cons,val); sp.minimize(p,ec); hwsigmas_[i][j] = p.currentValue()[0]*p.currentValue()[0]; //std::cout << std::setprecision(8) << "calibration: " << optionTenors_[i] << "/" << swapTenors_[j] << " sigma=" << hwsigmas_[i][j] << " model=" << sh->modelValue() << " market=" << sh->marketValue() << std::endl; } } interpolationSigma_.update(); }
DailyTenorJPYLibor(Natural settlementDays, const Handle<YieldTermStructure>& h = Handle<YieldTermStructure>()) : DailyTenorLibor("JPYLibor", settlementDays, JPYCurrency(), Japan(), Actual360(), h) {}
MakeCms::MakeCms(const Period& swapTenor, const boost::shared_ptr<SwapIndex>& swapIndex, Spread iborSpread, const Period& forwardStart) : swapTenor_(swapTenor), swapIndex_(swapIndex), iborIndex_(swapIndex->iborIndex()), iborSpread_(iborSpread), useAtmSpread_(false), forwardStart_(forwardStart), cmsSpread_(0.0), cmsGearing_(1.0), cmsCap_(Null<Real>()), cmsFloor_(Null<Real>()), effectiveDate_(Date()), cmsCalendar_(swapIndex->fixingCalendar()), floatCalendar_(iborIndex_->fixingCalendar()), payCms_(true), nominal_(1.0), cmsTenor_(3*Months), floatTenor_(iborIndex_->tenor()), cmsConvention_(ModifiedFollowing), cmsTerminationDateConvention_(ModifiedFollowing), floatConvention_(iborIndex_->businessDayConvention()), floatTerminationDateConvention_(iborIndex_->businessDayConvention()), cmsRule_(DateGeneration::Backward), floatRule_(DateGeneration::Backward), cmsEndOfMonth_(false), floatEndOfMonth_(false), cmsFirstDate_(Date()), cmsNextToLastDate_(Date()), floatFirstDate_(Date()), floatNextToLastDate_(Date()), cmsDayCount_(Actual360()), floatDayCount_(iborIndex_->dayCounter()), engine_(new DiscountingSwapEngine(swapIndex->forwardingTermStructure())) {}
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(); }
CADLibor(const Period& tenor, const Handle<YieldTermStructure>& h = Handle<YieldTermStructure>()) : Libor("CADLibor", tenor, 2, CADCurrency(), Canada(), Actual360(), h) {}
SEKLibor(const Period& tenor, const Handle<YieldTermStructure>& h = Handle<YieldTermStructure>()) : Libor("SEKLibor", tenor, 2, SEKCurrency(), Sweden(), Actual360(), h) {}
AUDLibor(const Period& tenor, const Handle<YieldTermStructure>& h = Handle<YieldTermStructure>()) : Libor("AUDLibor", tenor, 2, AUDCurrency(), Australia(), Actual360(), h) {}
DKKLibor(const Period& tenor, const Handle<YieldTermStructure>& h = Handle<YieldTermStructure>()) : Libor("DKKLibor", tenor, 2, DKKCurrency(), Denmark(), Actual360(), h) {}
JPYLibor(const Period& tenor, const Handle<YieldTermStructure>& h = Handle<YieldTermStructure>()) : Libor("JPYLibor", tenor, 2, JPYCurrency(), Japan(), Actual360(), h) {}
Euribor::Euribor(const Period& tenor, const Handle<YieldTermStructure>& h) : IborIndex("Euribor", tenor, 2, // settlement days EURCurrency(), TARGET(), euriborConvention(tenor), euriborEOM(tenor), Actual360(), h) { QL_REQUIRE(this->tenor().units()!=Days, "for daily tenors (" << this->tenor() << ") dedicated DailyTenor constructor must be used"); }
IBFRSwap::IBFRSwap(Type type, Real nominal, Date startDate, Period swapTenor, Period paymentTenor, Rate fixedRate, Rate rateSpread, const boost::shared_ptr<RepoChina>& iborIndex) :RepoCompoundingSwap(type, nominal, Schedule(startDate, startDate + swapTenor, paymentTenor, China(), ModifiedFollowing, ModifiedFollowing, DateGeneration::Backward, false), fixedRate, Actual365Fixed(), Schedule(startDate, startDate + swapTenor, paymentTenor, China(), ModifiedFollowing, ModifiedFollowing, DateGeneration::Backward, false), iborIndex, rateSpread, 0.0, Actual360(), Following) {}
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); }
IntensityModel() { dc = Actual360(); }
FedFunds::FedFunds(const Handle<YieldTermStructure>& h) : OvernightIndex("FedFunds", 0, USDCurrency(), UnitedStates(UnitedStates::Settlement), Actual360(), h) {}
TRLibor(const Period& tenor, const Handle<YieldTermStructure>& h = Handle<YieldTermStructure>()) : IborIndex("TRLibor", tenor, 0, TRYCurrency(), Turkey(), ModifiedFollowing, false, Actual360(), h) {}
Shibor::Shibor(const Period& tenor, const Handle<YieldTermStructure>& h) : IborIndex("Shibor", tenor, (tenor == 1*Days? 0 : 1), CNYCurrency(), China(China::IB), shiborConvention(tenor), false, Actual360(), h) {}
MakeVanillaSwap::operator ext::shared_ptr<VanillaSwap>() const { Date startDate; if (effectiveDate_ != Date()) startDate = effectiveDate_; else { Date refDate = Settings::instance().evaluationDate(); // if the evaluation date is not a business day // then move to the next business day refDate = floatCalendar_.adjust(refDate); Date spotDate = floatCalendar_.advance(refDate, settlementDays_*Days); startDate = spotDate+forwardStart_; if (forwardStart_.length()<0) startDate = floatCalendar_.adjust(startDate, Preceding); else startDate = floatCalendar_.adjust(startDate, Following); } Date endDate = terminationDate_; if (endDate == Date()) { if (floatEndOfMonth_) endDate = floatCalendar_.advance(startDate, swapTenor_, ModifiedFollowing, floatEndOfMonth_); else endDate = startDate + swapTenor_; } const Currency& curr = iborIndex_->currency(); Period fixedTenor; if (fixedTenor_ != Period()) fixedTenor = fixedTenor_; else { if ((curr == EURCurrency()) || (curr == USDCurrency()) || (curr == CHFCurrency()) || (curr == SEKCurrency()) || (curr == GBPCurrency() && swapTenor_ <= 1 * Years)) fixedTenor = Period(1, Years); else if ((curr == GBPCurrency() && swapTenor_ > 1 * Years) || (curr == JPYCurrency()) || (curr == AUDCurrency() && swapTenor_ >= 4 * Years)) fixedTenor = Period(6, Months); else if ((curr == HKDCurrency() || (curr == AUDCurrency() && swapTenor_ < 4 * Years))) fixedTenor = Period(3, Months); else QL_FAIL("unknown fixed leg default tenor for " << curr); } Schedule fixedSchedule(startDate, endDate, fixedTenor, fixedCalendar_, fixedConvention_, fixedTerminationDateConvention_, fixedRule_, fixedEndOfMonth_, fixedFirstDate_, fixedNextToLastDate_); Schedule floatSchedule(startDate, endDate, floatTenor_, floatCalendar_, floatConvention_, floatTerminationDateConvention_, floatRule_, floatEndOfMonth_, floatFirstDate_, floatNextToLastDate_); DayCounter fixedDayCount; if (fixedDayCount_ != DayCounter()) fixedDayCount = fixedDayCount_; else { if (curr == USDCurrency()) fixedDayCount = Actual360(); else if (curr == EURCurrency() || curr == CHFCurrency() || curr == SEKCurrency()) fixedDayCount = Thirty360(Thirty360::BondBasis); else if (curr == GBPCurrency() || curr == JPYCurrency() || curr == AUDCurrency() || curr == HKDCurrency()) fixedDayCount = Actual365Fixed(); else QL_FAIL("unknown fixed leg day counter for " << curr); } Rate usedFixedRate = fixedRate_; if (fixedRate_ == Null<Rate>()) { VanillaSwap temp(type_, nominal_, fixedSchedule, 0.0, // fixed rate fixedDayCount, floatSchedule, iborIndex_, floatSpread_, floatDayCount_); if (engine_ == 0) { Handle<YieldTermStructure> disc = iborIndex_->forwardingTermStructure(); QL_REQUIRE(!disc.empty(), "null term structure set to this instance of " << iborIndex_->name()); bool includeSettlementDateFlows = false; ext::shared_ptr<PricingEngine> engine(new DiscountingSwapEngine(disc, includeSettlementDateFlows)); temp.setPricingEngine(engine); } else temp.setPricingEngine(engine_); usedFixedRate = temp.fairRate(); } ext::shared_ptr<VanillaSwap> swap(new VanillaSwap(type_, nominal_, fixedSchedule, usedFixedRate, fixedDayCount, floatSchedule, iborIndex_, floatSpread_, floatDayCount_)); if (engine_ == 0) { Handle<YieldTermStructure> disc = iborIndex_->forwardingTermStructure(); bool includeSettlementDateFlows = false; ext::shared_ptr<PricingEngine> engine(new DiscountingSwapEngine(disc, includeSettlementDateFlows)); swap->setPricingEngine(engine); } else swap->setPricingEngine(engine_); return swap; }