Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/fametrano/quantlib
Browse files Browse the repository at this point in the history
  • Loading branch information
gfacchinetti committed Oct 17, 2014
2 parents 5336e52 + 55595bf commit 52ee8d6
Show file tree
Hide file tree
Showing 280 changed files with 34,363 additions and 3,697 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Makefile.in
*.exp
*.lib
*.pdb
*.ilk
*.class
*~
*.ncb
Expand All @@ -128,6 +129,7 @@ Makefile.in
*.sdf

# Outputs
QuantLib/Examples/BasketLosses/BasketLosses
QuantLib/Examples/BermudanSwaption/BermudanSwaption
QuantLib/Examples/Bonds/Bonds
QuantLib/Examples/CDS/CDS
Expand All @@ -137,7 +139,9 @@ QuantLib/Examples/DiscreteHedging/DiscreteHedging
QuantLib/Examples/EquityOption/EquityOption
QuantLib/Examples/FRA/FRA
QuantLib/Examples/FittedBondCurve/FittedBondCurve
QuantLib/Examples/LatentModel/LatentModel
QuantLib/Examples/MarketModels/MarketModels
QuantLib/Examples/MultidimIntegral/MultidimIntegral
QuantLib/Examples/Gaussian1dModels/Gaussian1dModels
QuantLib/Examples/Replication/Replication
QuantLib/Examples/Repo/Repo
Expand Down Expand Up @@ -174,3 +178,4 @@ QuantLibAddin/Docs/*.chm
QuantLibAddin/Docs/doxywarnings.txt
QuantLibXL/Docs/*.chm
QuantLibXL/Docs/doxywarnings.txt

11 changes: 3 additions & 8 deletions QuantLib-SWIG/Python/examples/bonds.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,9 @@
libor3m,
Actual360(),
ModifiedFollowing,
2,
[1.0], # Gearings
[0.001], # Spreads
[], # Caps
[], # Floors
True, # Fixing in arrears
100.0,
Date(21, October, 2005))
spreads=[0.001],
inArrears=True,
issueDate=Date(21, October, 2005))

floatingRateBond.setPricingEngine(bondEngine);

Expand Down
86 changes: 86 additions & 0 deletions QuantLib-SWIG/Python/examples/cds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# -*- mode: python; tab-width: 4;

# Copyright (C) 2014 Thema Consulting
#
# 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
# <quantlib-dev@lists.sf.net>. The license is also available online at
# <http://quantlib.org/license.shtml>.
#
# 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.

from QuantLib import *

calendar = TARGET()

# set evaluation date
todaysDate = Date(15,May,2007);
todaysDate = calendar.adjust(todaysDate)
Settings.instance().evaluationDate = todaysDate

risk_free_rate = YieldTermStructureHandle(
FlatForward(todaysDate, 0.01, Actual365Fixed()))

# CDS parameters
recovery_rate = 0.5
quoted_spreads = [ 0.0150, 0.0150, 0.0150, 0.0150 ]
tenors = [ Period(3, Months), Period(6, Months),
Period(1, Years), Period(2, Years) ]
maturities = [ calendar.adjust(todaysDate + x, Following) for x in tenors]

instruments = [
SpreadCdsHelper(QuoteHandle(SimpleQuote(s)),
tenor,
0,
calendar,
Quarterly,
Following,
DateGeneration.TwentiethIMM,
Actual365Fixed(),
recovery_rate,
risk_free_rate)
for s,tenor in zip(quoted_spreads, tenors) ]

hazard_curve = PiecewiseFlatHazardRate(todaysDate, instruments,
Actual365Fixed())
print "Calibrated hazard rate values: "
for x in hazard_curve.nodes():
print "hazard rate on %s is %.7f" % x

print "Some survival probability values: "
print "1Y survival probability: %.4g, \n\t\texpected %.4g" % (
hazard_curve.survivalProbability(todaysDate + Period("1Y")),
0.9704)
print "2Y survival probability: %.4g, \n\t\texpected %.4g" % (
hazard_curve.survivalProbability(todaysDate + Period("2Y")),
0.9418)

# reprice instruments
nominal = 1000000.0
probability = DefaultProbabilityTermStructureHandle(hazard_curve)

# create a cds for every maturity
all_cds = []
for maturity, s in zip(maturities, quoted_spreads):
schedule = Schedule(todaysDate, maturity, Period(Quarterly),
calendar, Following, Unadjusted,
DateGeneration.TwentiethIMM, False)
cds = CreditDefaultSwap(Protection.Seller, nominal, s,
schedule, Following, Actual365Fixed())
engine = MidPointCdsEngine(probability, recovery_rate, risk_free_rate)
cds.setPricingEngine(engine)
all_cds.append(cds)

print "Repricing of quoted CDSs employed for calibration: "
for i in range(len(tenors)):
print "%s fair spread: %.7g" % (tenors[i], all_cds[i].fairSpread())
print " NPV: %g" % all_cds[i].NPV()
print " default leg: %.7g" % all_cds[i].defaultLegNPV()
print " coupon leg: %.7g" % all_cds[i].couponLegNPV()
print
8 changes: 8 additions & 0 deletions QuantLib-SWIG/SWIG/basketoptions.i
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ typedef boost::shared_ptr<PricingEngine> MCEuropeanBasketEnginePtr;

%rename(MCEuropeanBasketEngine) MCEuropeanBasketEnginePtr;
class MCEuropeanBasketEnginePtr : public boost::shared_ptr<PricingEngine> {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") MCEuropeanBasketEnginePtr;
#endif
public:
%extend {
MCEuropeanBasketEnginePtr(const StochasticProcessArrayPtr& process,
Expand Down Expand Up @@ -153,7 +155,9 @@ typedef boost::shared_ptr<PricingEngine> MCAmericanBasketEnginePtr;

%rename(MCAmericanBasketEngine) MCAmericanBasketEnginePtr;
class MCAmericanBasketEnginePtr : public boost::shared_ptr<PricingEngine> {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") MCAmericanBasketEnginePtr;
#endif
public:
%extend {
MCAmericanBasketEnginePtr(const StochasticProcessArrayPtr& process,
Expand Down Expand Up @@ -249,7 +253,9 @@ class EverestOptionPtr : public MultiAssetOptionPtr {

%rename(MCEverestEngine) MCEverestEnginePtr;
class MCEverestEnginePtr : public boost::shared_ptr<PricingEngine> {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") MCEverestEnginePtr;
#endif
public:
%extend {
MCEverestEnginePtr(const StochasticProcessArrayPtr& process,
Expand Down Expand Up @@ -316,7 +322,9 @@ class HimalayaOptionPtr : public MultiAssetOptionPtr {

%rename(MCHimalayaEngine) MCHimalayaEnginePtr;
class MCHimalayaEnginePtr : public boost::shared_ptr<PricingEngine> {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") MCHimalayaEnginePtr;
#endif
public:
%extend {
MCHimalayaEnginePtr(const StochasticProcessArrayPtr& process,
Expand Down
3 changes: 2 additions & 1 deletion QuantLib-SWIG/SWIG/bondfunctions.i
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,13 @@ class BondFunctions {
Frequency frequency,
Duration::Type type = Duration::Modified,
Date settlementDate = Date()) {
return QuantLib::BondFunctions::yield(
return QuantLib::BondFunctions::duration(
*(boost::dynamic_pointer_cast<Bond>(bond)),
yield,
dayCounter,
compounding,
frequency,
type,
settlementDate);
}
static Real convexity(const BondPtr& bond,
Expand Down
41 changes: 27 additions & 14 deletions QuantLib-SWIG/SWIG/bonds.i
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ class BondPtr : public boost::shared_ptr<Instrument> {

%rename(ZeroCouponBond) ZeroCouponBondPtr;
class ZeroCouponBondPtr : public BondPtr {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") ZeroCouponBondPtr;
#endif
public:
%extend {
ZeroCouponBondPtr(
Expand All @@ -230,7 +232,9 @@ class ZeroCouponBondPtr : public BondPtr {

%rename(FixedRateBond) FixedRateBondPtr;
class FixedRateBondPtr : public BondPtr {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") FixedRateBondPtr;
#endif
public:
%extend {
FixedRateBondPtr(
Expand Down Expand Up @@ -268,23 +272,26 @@ class FixedRateBondPtr : public BondPtr {

%rename(FloatingRateBond) FloatingRateBondPtr;
class FloatingRateBondPtr : public BondPtr {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") FloatingRateBondPtr;
#endif
public:
%extend {
FloatingRateBondPtr(Size settlementDays,
Real faceAmount,
const Schedule& schedule,
const IborIndexPtr& index,
const DayCounter& paymentDayCounter,
BusinessDayConvention paymentConvention,
Size fixingDays,
const std::vector<Real>& gearings,
const std::vector<Spread>& spreads,
const std::vector<Rate>& caps,
const std::vector<Rate>& floors,
bool inArrears,
Real redemption,
const Date& issueDate) {
FloatingRateBondPtr(
Size settlementDays,
Real faceAmount,
const Schedule& schedule,
const IborIndexPtr& index,
const DayCounter& paymentDayCounter,
BusinessDayConvention paymentConvention = Following,
Size fixingDays = Null<Size>(),
const std::vector<Real>& gearings = std::vector<Real>(),
const std::vector<Spread>& spreads = std::vector<Spread>(),
const std::vector<Rate>& caps = std::vector<Rate>(),
const std::vector<Rate>& floors = std::vector<Rate>(),
bool inArrears = false,
Real redemption = 100.0,
const Date& issueDate = Date()) {
boost::shared_ptr<IborIndex> libor =
boost::dynamic_pointer_cast<IborIndex>(index);
return new FloatingRateBondPtr(
Expand Down Expand Up @@ -314,7 +321,9 @@ typedef boost::shared_ptr<Instrument> CmsRateBondPtr;

%rename(CmsRateBond) CmsRateBondPtr;
class CmsRateBondPtr : public BondPtr {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") CmsRateBondPtr;
#endif
public:
%extend {
CmsRateBondPtr(Size settlementDays,
Expand Down Expand Up @@ -375,7 +384,9 @@ typedef boost::shared_ptr<PricingEngine> TreeCallableFixedRateBondEnginePtr;

%rename(CallableFixedRateBond) CallableFixedRateBondPtr;
class CallableFixedRateBondPtr : public BondPtr {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") CallableFixedRateBondPtr;
#endif
public:
%extend {
CallableFixedRateBondPtr(
Expand Down Expand Up @@ -430,7 +441,9 @@ typedef boost::shared_ptr<Instrument> CPIBondPtr;

%rename(CPIBond) CPIBondPtr;
class CPIBondPtr : public BondPtr {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") CPIBondPtr;
#endif
public:
%extend {
CPIBondPtr(
Expand Down
Loading

0 comments on commit 52ee8d6

Please sign in to comment.