/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /*! Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl Copyright (C) 2003, 2004, 2005, 2006, 2007 StatPro Italia srl Copyright (C) 2004 Ferdinando Ametrano This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it under the terms of the QuantLib license. You should have received a copy of the license along with this program; if not, please email . The license is also available online at . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ /* This example shows how to set up a Term Structure and then price a simple swap. */ // the only header you need to use QuantLib #include #ifdef BOOST_MSVC /* Uncomment the following lines to unmask floating-point exceptions. Warning: unpredictable results can arise... See http://www.wilmott.com/messageview.cfm?catid=10&threadid=9481 Is there anyone with a definitive word about this? */ // #include // namespace { unsigned int u = _controlfp(_EM_INEXACT, _MCW_EM); } #endif #include #include #include //#include //#include //#include //#include //#include //#include //#include //#include //#include //#include //#include //#include using namespace QuantLib; #if defined(QL_ENABLE_SESSIONS) namespace QuantLib { Integer sessionId() { return 0; } } #endif //struct QuantoOptionData { // Option::Type type; // Real strike; // Real s; // spot // Rate q; // dividend // Rate r; // risk-free rate // Time t; // time to maturity // Volatility v; // volatility // Rate fxr; // fx risk-free rate // Volatility fxv; // fx volatility // Real corr; // correlation // Real result; // expected result // Real tol; // tolerance //}; int main(int, char* []) { try { SavedSettings backup; // set up dates Calendar calendar = TARGET(); DayCounter dayCounter = Actual365Fixed(); Date today = Date::todaysDate(); //Date settlementDate= today; Integer fixingDays = 0; // must be a business day //settlementDate = calendar.adjust(settlementDate); Date settlementDate(6, May, 2010); Settings::instance().evaluationDate() = settlementDate; BusinessDayConvention forwardbusinessDayConvention = ModifiedFollowing; // setup deposits // deposits Rate d1wQuote = 0.6; Rate d1mQuote = 0.6; Rate d3mQuote = 0.6; Rate d6mQuote = 0.6; Rate d9mQuote = 0.6; Rate d1yQuote = 0.6; Rate d2yQuote = 0.6; // deposits boost::shared_ptr d1wRate(new SimpleQuote(d1wQuote)); boost::shared_ptr d1mRate(new SimpleQuote(d1mQuote)); boost::shared_ptr d3mRate(new SimpleQuote(d3mQuote)); boost::shared_ptr d6mRate(new SimpleQuote(d6mQuote)); boost::shared_ptr d9mRate(new SimpleQuote(d9mQuote)); boost::shared_ptr d1yRate(new SimpleQuote(d1yQuote)); boost::shared_ptr d2yRate(new SimpleQuote(d2yQuote)); /********************* *** RATE HELPERS *** *********************/ // RateHelpers are built from the above quotes together with // other instrument dependant infos. Quotes are passed in // relinkable handles which could be relinked to some other // data source later. // deposits DayCounter depositDayCounter = dayCounter; boost::shared_ptr d1w(new DepositRateHelper( Handle(d1wRate), 1*Weeks, fixingDays, calendar, ModifiedFollowing, true, depositDayCounter)); boost::shared_ptr d1m(new DepositRateHelper( Handle(d1mRate), 1*Months, fixingDays, calendar, ModifiedFollowing, true, depositDayCounter)); boost::shared_ptr d3m(new DepositRateHelper( Handle(d3mRate), 3*Months, fixingDays, calendar, ModifiedFollowing, true, depositDayCounter)); boost::shared_ptr d6m(new DepositRateHelper( Handle(d6mRate), 6*Months, fixingDays, calendar, ModifiedFollowing, true, depositDayCounter)); boost::shared_ptr d9m(new DepositRateHelper( Handle(d9mRate), 9*Months, fixingDays, calendar, ModifiedFollowing, true, depositDayCounter)); boost::shared_ptr d1y(new DepositRateHelper( Handle(d1yRate), 1*Years, fixingDays, calendar, ModifiedFollowing, true, depositDayCounter)); boost::shared_ptr d2y(new DepositRateHelper( Handle(d1yRate), 2*Years, fixingDays, calendar, ModifiedFollowing, true, depositDayCounter)); /********************* ** CURVE BUILDING ** *********************/ // Any DayCounter would be fine. // ActualActual::ISDA ensures that 30 years is 30.0 DayCounter termStructureDayCounter =dayCounter; double tolerance = 1.0e-15; // A deposit rate curve std::vector > depoInstruments; depoInstruments.push_back(d1w); depoInstruments.push_back(d1m); depoInstruments.push_back(d3m); depoInstruments.push_back(d6m); depoInstruments.push_back(d9m); depoInstruments.push_back(d1y); depoInstruments.push_back(d2y); Handle DepoTermStructure(boost::shared_ptr( new PiecewiseYieldCurve( settlementDate, depoInstruments, termStructureDayCounter, std::vector >(), std::vector(), tolerance))); Date chekDate(6, September, 2010); double riskFreeDiscount = DepoTermStructure->zeroRate(chekDate,depositDayCounter,Simple,Once); double riskFreeDiscount1 = DepoTermStructure->zeroRate(chekDate,depositDayCounter,Simple); double riskFreeDiscountContinuous = DepoTermStructure->zeroRate(chekDate,depositDayCounter,Continuous); double riskFreeDiscountComp = DepoTermStructure->zeroRate(chekDate,depositDayCounter,Compounded); return 0; } catch (std::exception& e) { std::cout << e.what() << std::endl; return 1; } catch (...) { std::cout << "unknown error" << std::endl; return 1; } }