Skip to content

Commit 0a9bacd

Browse files
author
Ferdinando Ametrano
committed
merged changeset up to Rev16952 from branches/R01000x-branch to trunk
1 parent e9efed0 commit 0a9bacd

File tree

146 files changed

+2803
-2759
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+2803
-2759
lines changed

ql/Makefile.am

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ libQuantLib_la_SOURCES = \
7575
timegrid.cpp
7676

7777
lib_LTLIBRARIES = libQuantLib.la
78-
libQuantLib_la_LDFLAGS = -release $(PACKAGE_VERSION)
78+
libQuantLib_la_LDFLAGS = -version-info 0:0:0
7979

8080
libQuantLib_la_LIBADD = \
8181
cashflows/libCashFlows.la \
@@ -136,11 +136,3 @@ install-data-hook:
136136
depend:
137137
makedepend $(INCLUDES) -- $(CFLAGS) -- $(SOURCES)
138138

139-
if ENABLE_STATIC
140-
141-
install-exec-hook:
142-
mv $(DESTDIR)$(libdir)/libQuantLib.a $(DESTDIR)$(libdir)/libQuantLib-$(PACKAGE_VERSION).a
143-
cd $(DESTDIR)$(libdir) && $(LN_S) libQuantLib-$(PACKAGE_VERSION).a libQuantLib.a
144-
endif
145-
146-

ql/auto_link.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
# endif
6666
#endif
6767

68-
#define QL_LIB_NAME "QuantLib-" QL_LIB_TOOLSET QL_LIB_THREAD_OPT QL_LIB_RT_OPT "-" QL_LIB_VERSION ".lib"
68+
#define QL_LIB_NAME "QuantLib-" QL_LIB_TOOLSET QL_LIB_THREAD_OPT QL_LIB_RT_OPT ".lib"
6969

7070
#pragma comment(lib, QL_LIB_NAME)
7171
#ifdef BOOST_LIB_DIAGNOSTIC

ql/cashflows/cashflows.cpp

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ namespace QuantLib {
6868
bool includeSettlementDateFlows,
6969
Date settlementDate)
7070
{
71-
QL_REQUIRE(!leg.empty(), "empty leg");
71+
if (leg.empty())
72+
return true;
7273

7374
if (settlementDate == Date())
7475
settlementDate = Settings::instance().evaluationDate();
@@ -84,7 +85,8 @@ namespace QuantLib {
8485
CashFlows::previousCashFlow(const Leg& leg,
8586
bool includeSettlementDateFlows,
8687
Date settlementDate) {
87-
QL_REQUIRE(!leg.empty(), "empty leg");
88+
if (leg.empty())
89+
return leg.end();
8890

8991
if (settlementDate == Date())
9092
settlementDate = Settings::instance().evaluationDate();
@@ -108,7 +110,8 @@ namespace QuantLib {
108110
CashFlows::nextCashFlow(const Leg& leg,
109111
bool includeSettlementDateFlows,
110112
Date settlementDate) {
111-
QL_REQUIRE(!leg.empty(), "empty leg");
113+
if (leg.empty())
114+
return leg.end();
112115

113116
if (settlementDate == Date())
114117
settlementDate = Settings::instance().evaluationDate();
@@ -217,6 +220,23 @@ namespace QuantLib {
217220
return aggregateRate(leg, cf);
218221
}
219222

223+
BigInteger CashFlows::accrualDays(const Leg& leg,
224+
bool includeSettlementDateFlows,
225+
Date settlementDate) {
226+
Leg::const_iterator cf = nextCashFlow(leg,
227+
includeSettlementDateFlows,
228+
settlementDate);
229+
if (cf==leg.end()) return 0;
230+
231+
Date paymentDate = (*cf)->date();
232+
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
233+
shared_ptr<Coupon> cp = dynamic_pointer_cast<Coupon>(*cf);
234+
if (cp)
235+
return cp->accrualDays();
236+
}
237+
return 0;
238+
}
239+
220240
Real CashFlows::accruedAmount(const Leg& leg,
221241
bool includeSettlementDateFlows,
222242
Date settlementDate) {
@@ -270,7 +290,9 @@ namespace QuantLib {
270290
bool includeSettlementDateFlows,
271291
Date settlementDate,
272292
Date npvDate) {
273-
QL_REQUIRE(!leg.empty(), "empty leg");
293+
294+
if (leg.empty())
295+
return 0.0;
274296

275297
if (settlementDate == Date())
276298
settlementDate = Settings::instance().evaluationDate();
@@ -294,7 +316,8 @@ namespace QuantLib {
294316
bool includeSettlementDateFlows,
295317
Date settlementDate,
296318
Date npvDate) {
297-
QL_REQUIRE(!leg.empty(), "empty leg");
319+
if (leg.empty())
320+
return 0.0;
298321

299322
if (settlementDate == Date())
300323
settlementDate = Settings::instance().evaluationDate();
@@ -354,7 +377,8 @@ namespace QuantLib {
354377
bool includeSettlementDateFlows,
355378
Date settlementDate,
356379
Date npvDate) {
357-
QL_REQUIRE(!leg.empty(), "empty leg");
380+
if (leg.empty())
381+
return 0.0;
358382

359383
if (settlementDate == Date())
360384
settlementDate = Settings::instance().evaluationDate();
@@ -386,7 +410,8 @@ namespace QuantLib {
386410
bool includeSettlementDateFlows,
387411
Date settlementDate,
388412
Date npvDate) {
389-
QL_REQUIRE(!leg.empty(), "empty leg");
413+
if (leg.empty())
414+
return 0.0;
390415

391416
QL_REQUIRE(settlementDate!=Date(), "null settlement date");
392417

@@ -549,7 +574,9 @@ namespace QuantLib {
549574
bool includeSettlementDateFlows,
550575
Date settlementDate,
551576
Date npvDate) {
552-
QL_REQUIRE(!leg.empty(), "empty leg");
577+
578+
if (leg.empty())
579+
return 0.0;
553580

554581
if (settlementDate == Date())
555582
settlementDate = Settings::instance().evaluationDate();
@@ -611,7 +638,9 @@ namespace QuantLib {
611638
bool includeSettlementDateFlows,
612639
Date settlementDate,
613640
Date npvDate) {
614-
QL_REQUIRE(!leg.empty(), "empty leg");
641+
642+
if (leg.empty())
643+
return 0.0;
615644

616645
if (settlementDate == Date())
617646
settlementDate = Settings::instance().evaluationDate();
@@ -667,7 +696,9 @@ namespace QuantLib {
667696
bool includeSettlementDateFlows,
668697
Date settlementDate,
669698
Date npvDate) {
670-
QL_REQUIRE(!leg.empty(), "empty leg");
699+
700+
if (leg.empty())
701+
return 0.0;
671702

672703
if (settlementDate == Date())
673704
settlementDate = Settings::instance().evaluationDate();
@@ -713,7 +744,8 @@ namespace QuantLib {
713744
bool includeSettlementDateFlows,
714745
Date settlementDate,
715746
Date npvDate) {
716-
QL_REQUIRE(!leg.empty(), "empty leg");
747+
if (leg.empty())
748+
return 0.0;
717749

718750
if (settlementDate == Date())
719751
settlementDate = Settings::instance().evaluationDate();
@@ -784,7 +816,8 @@ namespace QuantLib {
784816
bool includeSettlementDateFlows,
785817
Date settlementDate,
786818
Date npvDate) {
787-
QL_REQUIRE(!leg.empty(), "empty leg");
819+
if (leg.empty())
820+
return 0.0;
788821

789822
if (settlementDate == Date())
790823
settlementDate = Settings::instance().evaluationDate();
@@ -830,7 +863,8 @@ namespace QuantLib {
830863
bool includeSettlementDateFlows,
831864
Date settlementDate,
832865
Date npvDate) {
833-
QL_REQUIRE(!leg.empty(), "empty leg");
866+
if (leg.empty())
867+
return 0.0;
834868

835869
if (settlementDate == Date())
836870
settlementDate = Settings::instance().evaluationDate();
@@ -918,7 +952,9 @@ namespace QuantLib {
918952
bool includeSettlementDateFlows,
919953
Date settlementDate,
920954
Date npvDate) {
921-
QL_REQUIRE(!leg.empty(), "empty leg");
955+
956+
if (leg.empty())
957+
return 0.0;
922958

923959
if (settlementDate == Date())
924960
settlementDate = Settings::instance().evaluationDate();

ql/cashflows/cashflows.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ namespace QuantLib {
9292
nextCouponRate(const Leg& leg,
9393
bool includeSettlementDateFlows,
9494
Date settlementDate = Date());
95+
static BigInteger
96+
accrualDays(const Leg& leg,
97+
bool includeSettlementDateFlows,
98+
Date settlementDate = Date());
9599
static Real
96100
accruedAmount(const Leg& leg,
97101
bool includeSettlementDateFlows,

ql/cashflows/coupon.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,31 @@ namespace QuantLib {
4545
refPeriodEnd_);
4646
}
4747

48-
Integer Coupon::accrualDays() const {
48+
BigInteger Coupon::accrualDays() const {
4949
return dayCounter().dayCount(accrualStartDate_,
5050
accrualEndDate_);
5151
}
5252

53+
Time Coupon::accruedPeriod(const Date& d) const {
54+
if (d <= accrualStartDate_ || d > paymentDate_) {
55+
return 0.0;
56+
} else {
57+
return dayCounter().yearFraction(accrualStartDate_,
58+
std::min(d, accrualEndDate_),
59+
refPeriodStart_,
60+
refPeriodEnd_);
61+
}
62+
}
63+
64+
BigInteger Coupon::accruedDays(const Date& d) const {
65+
if (d <= accrualStartDate_ || d > paymentDate_) {
66+
return 0;
67+
} else {
68+
return dayCounter().dayCount(accrualStartDate_,
69+
std::min(d, accrualEndDate_));
70+
}
71+
}
72+
5373
void Coupon::accept(AcyclicVisitor& v) {
5474
Visitor<Coupon>* v1 = dynamic_cast<Visitor<Coupon>*>(&v);
5575
if (v1 != 0)

ql/cashflows/coupon.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ namespace QuantLib {
6565
//! accrual period as fraction of year
6666
Time accrualPeriod() const;
6767
//! accrual period in days
68-
Integer accrualDays() const;
68+
BigInteger accrualDays() const;
6969
//! accrued rate
7070
virtual Rate rate() const = 0;
7171
//! day counter for accrual calculation
7272
virtual DayCounter dayCounter() const = 0;
73+
//! accrued period as fraction of year at the given date
74+
Time accruedPeriod(const Date&) const;
75+
//! accrued days at the given date
76+
BigInteger accruedDays(const Date&) const;
7377
//! accrued amount at the given date
7478
virtual Real accruedAmount(const Date&) const = 0;
7579
//@}

ql/cashflows/indexedcashflow.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@
1717
FOR A PARTICULAR PURPOSE. See the license for more details.
1818
*/
1919

20-
21-
2220
#include <ql/cashflows/indexedcashflow.hpp>
2321
#include <ql/index.hpp>
2422

2523
namespace QuantLib {
2624

2725
Real IndexedCashFlow::amount() const {
28-
return notional_* (index_->fixing(fixingDate_) // usually by extrapolation
29-
/ index_->fixing(baseDate_) );
26+
Real I0 = index_->fixing(baseDate_);
27+
Real I1 = index_->fixing(fixingDate_);
28+
29+
if (growthOnly_)
30+
return notional_ * (I1 / I0 - 1.0);
31+
else
32+
return notional_ * (I1 / I0);
3033
}
3134

3235
}
33-
34-
35-
36-

ql/cashflows/indexedcashflow.hpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,28 @@ namespace QuantLib {
3030

3131
class Index;
3232

33-
//! Cash flow dependent on an index ratio (NOT a coupon, i.e. no accruals)
34-
/*! We expect this to be used inside an istrument that does all the date
33+
//! Cash flow dependent on an index ratio.
34+
35+
/*! This cash flow is not a coupon, i.e., there's no accrual. The
36+
amount is either i(T)/i(0) or i(T)/i(0) - 1, depending on the
37+
growthOnly parameter.
38+
39+
We expect this to be used inside an instrument that does all the date
3540
adjustment etc., so this takes just dates and does not change them.
36-
*/
41+
growthOnly = false means i(T)/i(0), which is a bond-type setting.
42+
growthOnly = true means i(T)/i(0) - 1, which is a swap-type setting.
43+
*/
3744
class IndexedCashFlow : public CashFlow {
3845
public:
3946
IndexedCashFlow(Real notional,
4047
const boost::shared_ptr<Index> &index,
4148
const Date& baseDate,
4249
const Date& fixingDate,
43-
const Date& paymentDate)
50+
const Date& paymentDate,
51+
bool growthOnly = false)
4452
: notional_(notional), index_(index),
4553
baseDate_(baseDate), fixingDate_(fixingDate),
46-
paymentDate_(paymentDate) {}
54+
paymentDate_(paymentDate), growthOnly_(growthOnly) {}
4755
//! \name Event interface
4856
//@{
4957
Date date() const { return paymentDate_; }
@@ -52,6 +60,7 @@ namespace QuantLib {
5260
virtual Date baseDate() const { return baseDate_; }
5361
virtual Date fixingDate() const { return fixingDate_; }
5462
virtual boost::shared_ptr<Index> index() const { return index_; }
63+
virtual bool growthOnly() const { return growthOnly_; }
5564
//! \name CashFlow interface
5665
//@{
5766
Real amount() const; // already virtual
@@ -60,10 +69,11 @@ namespace QuantLib {
6069
//@{
6170
virtual void accept(AcyclicVisitor&);
6271
//@}
63-
private:
72+
private:
6473
Real notional_;
6574
boost::shared_ptr<Index> index_;
6675
Date baseDate_, fixingDate_, paymentDate_;
76+
bool growthOnly_;
6777
};
6878

6979

@@ -78,13 +88,6 @@ namespace QuantLib {
7888
CashFlow::accept(v);
7989
}
8090

81-
8291
}
8392

84-
85-
86-
87-
88-
89-
9093
#endif

0 commit comments

Comments
 (0)