Hi
Is there an easy way to determine the floating rate of a swap instead of specifying an ibor Index? I try to make my computations with NullCalendar and SimpleDayCounter and I face the problems that often my settlement is on sunday => error.. What I tried (to give as input my floating rate) is the following, but I don't know if it is * efficient * robust I think my problem is in the 6 last lines of this code boost::shared_ptr<QuantLib::VanillaSwap> toVanillaSwap( char* type, double nominal, QuantLib::Date issueDate, QuantLib::Date maturityDate, QuantLib::Calendar calendar, QuantLib::DayCounter dayCounter, double spread, double fixRate, QuantLib::Frequency fixFrequency, QuantLib::Calendar fixCalendar, QuantLib::DayCounter fixDayCounter, double fltRate, int fltIndexTenor, QuantLib::Frequency fltFrequency, QuantLib::Calendar fltCalendar, QuantLib::DayCounter fltDayCounter, QuantLib::Handle<QuantLib::YieldTermStructure> yTS){ BusinessDayConvention fixConvention = Unadjusted; BusinessDayConvention fixTerminationDateConvention = Unadjusted; DateGeneration::Rule fixRule = DateGeneration::Backward; bool fixEndOfMonth = false; BusinessDayConvention fltConvention = Unadjusted; BusinessDayConvention fltTerminationDateConvention = Unadjusted; DateGeneration::Rule fltRule = DateGeneration::Backward; bool fltEndOfMonth = false; Schedule fixSchedule(issueDate, maturityDate, Period(fixFrequency), fixCalendar, fixConvention, fixTerminationDateConvention, fixRule, fixEndOfMonth); Schedule fltSchedule(issueDate, maturityDate, Period(fltFrequency), fltCalendar, fltConvention, fltTerminationDateConvention, fltRule, fltEndOfMonth); std::string familyName = ""; Period tenor (fltIndexTenor, Months); int settlementDays = 0; Currency currency = QuantLib::EURCurrency(); Calendar fixingCalendar = fltCalendar; BusinessDayConvention convention = Unadjusted; bool endOfMonth = false; boost::shared_ptr<IborIndex> iborIndex ; iborIndex = boost::shared_ptr<IborIndex>( new IborIndex(familyName, tenor, settlementDays, currency, fixingCalendar, convention, endOfMonth, fltDayCounter, yTS)); std::string s(type); s = s.substr(0,1); std::transform(s.begin(), s.end(), s.begin(), ::toupper); QuantLib::VanillaSwap::Type typ; if (s == "R") typ = QuantLib::VanillaSwap::Receiver; else if (s == "P") typ = QuantLib::VanillaSwap::Payer; else throw (std::string("unknwown type of Swap")); boost::shared_ptr<VanillaSwap>sw; sw = boost::shared_ptr<VanillaSwap>( new VanillaSwap(typ, nominal, fixSchedule, fixRate, fixDayCounter, fltSchedule, iborIndex, spread, fltDayCounter)); boost::shared_ptr<YieldTermStructure> yts =yTS.currentLink(); Date refDate = yts->referenceDate(); Date prevFixDate = (*(CashFlows::previousCashFlow(sw->floatingLeg(), refDate)))->date(); if(!iborIndex->isValidFixingDate(prevFixDate)) prevFixDate = fltCalendar.adjust(prevFixDate, Preceding); iborIndex->addFixing(prevFixDate, fltRate, true); return sw; } |
Actually my question is more general
Suppose I have to price a swap at 31/12/2008 The only informations I have are the yieldCurve at 31/12/2008 and the characteristics of the swap (notional, fixrate, index followed by floating leg, maturity (frequencies of both legs are annual)) How can be the floating rate used for next coupon be determined by these informations? My idea was "it must be an input".. but i"m not sure Tks David |
In reply to this post by dhoorens
I don't really understand the question but if you try to obtain next floating coupons in order to value a swap then:
Anyway I don't thing you need to do anyhing like that, just use built-in Quantlib functions. just look at the swap example. LluĂs On Wed 15/07/09 09:42 , dhoorens <[hidden email]> wrote:
------------------------------------------------------------------------------ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by dhoorens
On Wed, 2009-07-15 at 00:42 -0700, dhoorens wrote:
> Actually my question is more general > Suppose I have to price a swap at 31/12/2008 > The only informations I have are the yieldCurve at 31/12/2008 and the > characteristics of the swap (notional, fixrate, index followed by floating > leg, maturity (frequencies of both legs are annual)) > > How can be the floating rate used for next coupon be determined by these > informations? > My idea was "it must be an input".. but i"m not sure If the floating coupon already started, you're right---it's an input, since it can't be retrieved from today's curve. From your previous mail, I see you already figured that it should be stored with the Index::addFixing method. To get the correct date, I'd do something like: boost::shared_ptr<CashFlow> currentCoupon = ...; boost::shared_ptr<FloatingRateCoupon> flt = boost::dynamic_pointer_cast<FloatingRateCoupon>(currentCoupon); iborIndex->addFixing(flt->fixingDate(), ...); Luigi -- A programming language is low-level when its programs require attention to the irrelevant. -- Alan Perlis ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |