forked from lballabio/QuantLib-SWIG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcashflows.i
882 lines (811 loc) · 32.1 KB
/
cashflows.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
/*
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 StatPro Italia srl
Copyright (C) 2005 Dominic Thuillier
Copyright (C) 2010, 2011 Lluis Pujol Bajador
Copyright (C) 2017 Matthias Lungwitz
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
<[email protected]>. 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.
*/
#ifndef quantlib_cash_flows_i
#define quantlib_cash_flows_i
%include date.i
%include types.i
%include calendars.i
%include daycounters.i
%include indexes.i
%include termstructures.i
%include scheduler.i
%include vectors.i
%include volatilities.i
%{
using QuantLib::CashFlow;
%}
%ignore CashFlow;
class CashFlow {
public:
Real amount() const;
Date date() const;
};
%template(CashFlow) boost::shared_ptr<CashFlow>;
IsObservable(boost::shared_ptr<CashFlow>);
#if defined(SWIGCSHARP)
SWIG_STD_VECTOR_ENHANCED( boost::shared_ptr<CashFlow> )
#endif
%template(Leg) std::vector<boost::shared_ptr<CashFlow> >;
typedef std::vector<boost::shared_ptr<CashFlow> > Leg;
// implementations
%{
using QuantLib::SimpleCashFlow;
using QuantLib::Redemption;
using QuantLib::AmortizingPayment;
using QuantLib::Coupon;
using QuantLib::FixedRateCoupon;
using QuantLib::IborCoupon;
using QuantLib::Leg;
using QuantLib::FloatingRateCoupon;
typedef boost::shared_ptr<CashFlow> SimpleCashFlowPtr;
typedef boost::shared_ptr<CashFlow> RedemptionPtr;
typedef boost::shared_ptr<CashFlow> AmortizingPaymentPtr;
typedef boost::shared_ptr<CashFlow> CouponPtr;
typedef boost::shared_ptr<CashFlow> IborCouponPtr;
typedef boost::shared_ptr<CashFlow> FixedRateCouponPtr;
typedef boost::shared_ptr<CashFlow> FloatingRateCouponPtr;
%}
%rename(SimpleCashFlow) SimpleCashFlowPtr;
class SimpleCashFlowPtr : public boost::shared_ptr<CashFlow> {
public:
%extend {
SimpleCashFlowPtr(Real amount, const Date& date) {
return new SimpleCashFlowPtr(new SimpleCashFlow(amount,date));
}
}
};
%rename(Redemption) RedemptionPtr;
class RedemptionPtr : public boost::shared_ptr<CashFlow> {
public:
%extend {
RedemptionPtr(Real amount, const Date& date) {
return new RedemptionPtr(new Redemption(amount,date));
}
}
};
%rename(AmortizingPayment) AmortizingPaymentPtr;
class AmortizingPaymentPtr : public boost::shared_ptr<CashFlow> {
public:
%extend {
AmortizingPaymentPtr(Real amount, const Date& date) {
return new AmortizingPaymentPtr(new AmortizingPayment(amount,date));
}
}
};
%rename(Coupon) CouponPtr;
class CouponPtr : public boost::shared_ptr<CashFlow> {
private:
CouponPtr();
public:
%extend {
Real nominal() {
return boost::dynamic_pointer_cast<Coupon>(*self)->nominal();
}
Date accrualStartDate() {
return boost::dynamic_pointer_cast<Coupon>(*self)
->accrualStartDate();
}
Date accrualEndDate() {
return boost::dynamic_pointer_cast<Coupon>(*self)
->accrualEndDate();
}
Date referencePeriodStart() {
return boost::dynamic_pointer_cast<Coupon>(*self)
->referencePeriodStart();
}
Date referencePeriodEnd() {
return boost::dynamic_pointer_cast<Coupon>(*self)
->referencePeriodEnd();
}
Date exCouponDate() {
return boost::dynamic_pointer_cast<Coupon>(*self)
->exCouponDate();
}
Real rate() {
return boost::dynamic_pointer_cast<Coupon>(*self)->rate();
}
Time accrualPeriod() {
return boost::dynamic_pointer_cast<Coupon>(*self)
->accrualPeriod();
}
BigInteger accrualDays() {
return boost::dynamic_pointer_cast<Coupon>(*self)
->accrualDays();
}
DayCounter dayCounter() const {
return boost::dynamic_pointer_cast<Coupon>(*self)
->dayCounter();
}
Real accruedAmount(const Date& date) {
return boost::dynamic_pointer_cast<Coupon>(*self)
->accruedAmount(date);
}
}
};
%inline %{
CouponPtr as_coupon(const boost::shared_ptr<CashFlow>& cf) {
return boost::dynamic_pointer_cast<Coupon>(cf);
}
%}
%rename(FixedRateCoupon) FixedRateCouponPtr;
class FixedRateCouponPtr : public CouponPtr {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") FixedRateCouponPtr;
#endif
public:
%extend {
FixedRateCouponPtr(const Date& paymentDate, Real nominal,
Rate rate, const DayCounter& dayCounter,
const Date& startDate, const Date& endDate,
const Date& refPeriodStart = Date(),
const Date& refPeriodEnd = Date(),
const Date& exCouponDate = Date()) {
return new FixedRateCouponPtr(
new FixedRateCoupon(paymentDate, nominal, rate,
dayCounter, startDate, endDate,
refPeriodStart, refPeriodEnd,
exCouponDate));
}
InterestRate interestRate() {
return boost::dynamic_pointer_cast<FixedRateCoupon>(*self)
->interestRate();
}
}
};
%inline %{
FixedRateCouponPtr as_fixed_rate_coupon(
const boost::shared_ptr<CashFlow>& cf) {
return boost::dynamic_pointer_cast<FixedRateCoupon>(cf);
}
%}
%{
using QuantLib::FloatingRateCouponPricer;
%}
%ignore FloatingRateCouponPricer;
class FloatingRateCouponPricer {};
%template(FloatingRateCouponPricer) boost::shared_ptr<FloatingRateCouponPricer>;
void setCouponPricer(const Leg&,
const boost::shared_ptr<FloatingRateCouponPricer>&);
%rename(FloatingRateCoupon) FloatingRateCouponPtr;
class FloatingRateCouponPtr : public CouponPtr {
private:
FloatingRateCouponPtr();
public:
%extend {
Date fixingDate() {
return boost::dynamic_pointer_cast<FloatingRateCoupon>(*self)
->fixingDate();
}
Integer fixingDays() {
return boost::dynamic_pointer_cast<FloatingRateCoupon>(*self)
->fixingDays();
}
bool isInArrears() {
return boost::dynamic_pointer_cast<FloatingRateCoupon>(*self)
->isInArrears();
}
Real gearing() {
return boost::dynamic_pointer_cast<FloatingRateCoupon>(*self)
->gearing();
}
Rate spread() {
return boost::dynamic_pointer_cast<FloatingRateCoupon>(*self)
->spread();
}
Rate indexFixing() {
return boost::dynamic_pointer_cast<FloatingRateCoupon>(*self)
->indexFixing();
}
Rate adjustedFixing() {
return boost::dynamic_pointer_cast<FloatingRateCoupon>(*self)
->adjustedFixing();
}
Rate convexityAdjustment() {
return boost::dynamic_pointer_cast<FloatingRateCoupon>(*self)
->convexityAdjustment();
}
Real price(const Handle<YieldTermStructure>& discountCurve) {
return boost::dynamic_pointer_cast<FloatingRateCoupon>(*self)
->price(discountCurve);
}
InterestRateIndexPtr index() const {
return boost::dynamic_pointer_cast<FloatingRateCoupon>(*self)
->index();
}
void setPricer(const boost::shared_ptr<FloatingRateCouponPricer>& p) {
boost::dynamic_pointer_cast<FloatingRateCoupon>(*self)
->setPricer(p);
}
}
};
%inline %{
FloatingRateCouponPtr as_floating_rate_coupon(
const boost::shared_ptr<CashFlow>& cf) {
return boost::dynamic_pointer_cast<FloatingRateCoupon>(cf);
}
%}
%{
using QuantLib::CappedFlooredCoupon;
typedef boost::shared_ptr<CashFlow> CappedFlooredCouponPtr;
%}
%rename(CappedFlooredCoupon) CappedFlooredCouponPtr;
class CappedFlooredCouponPtr : public FloatingRateCouponPtr {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") CappedFlooredCouponPtr;
#endif
public:
%extend {
CappedFlooredCouponPtr(const FloatingRateCouponPtr& underlying,
Rate cap = Null<Rate>(),
Rate floor = Null<Rate>()) {
boost::shared_ptr<FloatingRateCoupon> u =
boost::dynamic_pointer_cast<FloatingRateCoupon>(underlying);
return new CappedFlooredCouponPtr(
new CappedFlooredCoupon(u,cap,floor));
}
Rate cap() {
return boost::dynamic_pointer_cast<CappedFlooredCoupon>(*self)
->cap();
}
Rate floor() {
return boost::dynamic_pointer_cast<CappedFlooredCoupon>(*self)
->floor();
}
Rate effectiveCap() {
return boost::dynamic_pointer_cast<CappedFlooredCoupon>(*self)
->effectiveCap();
}
Rate effectiveFloor() {
return boost::dynamic_pointer_cast<CappedFlooredCoupon>(*self)
->effectiveFloor();
}
bool isCapped() {
return boost::dynamic_pointer_cast<CappedFlooredCoupon>(*self)
->isCapped();
}
bool isFloored() {
return boost::dynamic_pointer_cast<CappedFlooredCoupon>(*self)
->isFloored();
}
void setPricer(const boost::shared_ptr<FloatingRateCouponPricer>& p) {
boost::dynamic_pointer_cast<CappedFlooredCoupon>(*self)
->setPricer(p);
}
}
};
// specialized floating-rate coupons
%rename(IborCoupon) IborCouponPtr;
class IborCouponPtr : public FloatingRateCouponPtr {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") IborCouponPtr;
#endif
public:
%extend {
IborCouponPtr(const Date& paymentDate, Real nominal,
const Date& startDate, const Date& endDate,
Integer fixingDays, InterestRateIndexPtr& index,
Real gearing = 1.0, Spread spread = 0.0,
const Date& refPeriodStart = Date(),
const Date& refPeriodEnd = Date(),
const DayCounter& dayCounter = DayCounter()) {
const boost::shared_ptr<IborIndex> iri =
boost::dynamic_pointer_cast<IborIndex>(index);
return new IborCouponPtr(
new IborCoupon(paymentDate, nominal, startDate, endDate,
fixingDays, iri, gearing, spread,
refPeriodStart, refPeriodEnd, dayCounter));
}
}
};
%{
using QuantLib::IborCouponPricer;
using QuantLib::BlackIborCouponPricer;
typedef boost::shared_ptr<FloatingRateCouponPricer> IborCouponPricerPtr;
typedef boost::shared_ptr<FloatingRateCouponPricer> BlackIborCouponPricerPtr;
%}
%rename(IborCouponPricer) IborCouponPricerPtr;
class IborCouponPricerPtr : public boost::shared_ptr<FloatingRateCouponPricer> {
private:
IborCouponPricerPtr();
public:
%extend {
Handle<OptionletVolatilityStructure> capletVolatility() {
return boost::dynamic_pointer_cast<IborCouponPricer>(*self)
->capletVolatility();
}
void setCapletVolatility(const Handle<OptionletVolatilityStructure>& v =
Handle<OptionletVolatilityStructure>()) {
boost::dynamic_pointer_cast<IborCouponPricer>(*self)
->setCapletVolatility(v);
}
}
};
%rename(BlackIborCouponPricer) BlackIborCouponPricerPtr;
class BlackIborCouponPricerPtr : public IborCouponPricerPtr {
public:
%extend {
BlackIborCouponPricerPtr(const Handle<OptionletVolatilityStructure>& v =
Handle<OptionletVolatilityStructure>()) {
return new BlackIborCouponPricerPtr(new BlackIborCouponPricer(v));
}
}
};
%{
using QuantLib::CmsCoupon;
using QuantLib::CappedFlooredCmsCoupon;
typedef boost::shared_ptr<CashFlow> CmsCouponPtr;
typedef boost::shared_ptr<CashFlow> CappedFlooredCmsCouponPtr;
%}
%rename(CmsCoupon) CmsCouponPtr;
class CmsCouponPtr : public FloatingRateCouponPtr {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") CmsCouponPtr;
#endif
public:
%extend {
CmsCouponPtr(const Date& paymentDate, Real nominal,
const Date& startDate, const Date& endDate,
Integer fixingDays, const SwapIndexPtr& index,
Real gearing = 1.0, Spread spread = 0.0,
const Date& refPeriodStart = Date(),
const Date& refPeriodEnd = Date(),
const DayCounter& dayCounter = DayCounter(),
bool isInArrears = false) {
const boost::shared_ptr<SwapIndex> swi =
boost::dynamic_pointer_cast<SwapIndex>(index);
return new CmsCouponPtr(
new CmsCoupon(paymentDate,nominal,startDate,endDate,
fixingDays,swi,gearing,spread,
refPeriodStart,refPeriodEnd,
dayCounter,isInArrears));
}
}
};
%{
using QuantLib::CmsCouponPricer;
using QuantLib::AnalyticHaganPricer;
using QuantLib::NumericHaganPricer;
using QuantLib::GFunctionFactory;
using QuantLib::LinearTsrPricer;
typedef boost::shared_ptr<FloatingRateCouponPricer> CmsCouponPricerPtr;
typedef boost::shared_ptr<FloatingRateCouponPricer> AnalyticHaganPricerPtr;
typedef boost::shared_ptr<FloatingRateCouponPricer> NumericHaganPricerPtr;
typedef boost::shared_ptr<FloatingRateCouponPricer> LinearTsrPricerPtr;
%}
%rename(CmsCouponPricer) CmsCouponPricerPtr;
class CmsCouponPricerPtr : public boost::shared_ptr<FloatingRateCouponPricer> {
private:
CmsCouponPricerPtr();
public:
%extend {
Handle<SwaptionVolatilityStructure> swaptionVolatility() {
return boost::dynamic_pointer_cast<CmsCouponPricer>(*self)
->swaptionVolatility();
}
void setSwaptionVolatility(
const Handle<SwaptionVolatilityStructure>& v =
Handle<SwaptionVolatilityStructure>()) {
boost::dynamic_pointer_cast<CmsCouponPricer>(*self)
->setSwaptionVolatility(v);
}
}
};
class GFunctionFactory {
private:
GFunctionFactory();
public:
enum YieldCurveModel { Standard,
ExactYield,
ParallelShifts,
NonParallelShifts };
};
%rename(AnalyticHaganPricer) AnalyticHaganPricerPtr;
class AnalyticHaganPricerPtr : public CmsCouponPricerPtr {
public:
%extend {
AnalyticHaganPricerPtr(const Handle<SwaptionVolatilityStructure>& v,
GFunctionFactory::YieldCurveModel model,
const Handle<Quote>& meanReversion) {
return new AnalyticHaganPricerPtr(
new AnalyticHaganPricer(v, model, meanReversion));
}
}
};
%rename(NumericHaganPricer) NumericHaganPricerPtr;
class NumericHaganPricerPtr : public CmsCouponPricerPtr {
public:
%extend {
NumericHaganPricerPtr(const Handle<SwaptionVolatilityStructure>& v,
GFunctionFactory::YieldCurveModel model,
const Handle<Quote>& meanReversion,
Rate lowerLimit = 0.0,
Rate upperLimit = 1.0,
Real precision = 1.0e-6) {
return new NumericHaganPricerPtr(
new NumericHaganPricer(v, model, meanReversion,
lowerLimit, upperLimit, precision));
}
}
};
%rename(CappedFlooredCmsCoupon) CappedFlooredCmsCouponPtr;
class CappedFlooredCmsCouponPtr: public CappedFlooredCouponPtr {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") CappedFlooredCouponPtr;
#endif
public:
%extend {
CappedFlooredCmsCouponPtr(
const Date& paymentDate, Real nominal,
const Date& startDate, const Date& endDate,
Natural fixingDays, const SwapIndexPtr& index,
Real gearing = 1.0, Spread spread = 0.0,
const Rate cap = Null<Rate>(),
const Rate floor = Null<Rate>(),
const Date& refPeriodStart = Date(),
const Date& refPeriodEnd = Date(),
const DayCounter& dayCounter = DayCounter(),
bool isInArrears = false) {
const boost::shared_ptr<SwapIndex> swi =
boost::dynamic_pointer_cast<SwapIndex>(index);
return new CappedFlooredCmsCouponPtr(
new CappedFlooredCmsCoupon(
paymentDate, nominal, startDate, endDate, fixingDays,
swi, gearing, spread, cap, floor, refPeriodStart,
refPeriodEnd, dayCounter, isInArrears));
}
}
};
%rename(LinearTsrPricer) LinearTsrPricerPtr;
class LinearTsrPricerPtr : public CmsCouponPricerPtr {
public:
%extend {
LinearTsrPricerPtr(
const Handle<SwaptionVolatilityStructure> &swaptionVol,
const Handle<Quote> &meanReversion,
const Handle<YieldTermStructure> &couponDiscountCurve =
Handle<YieldTermStructure>(),
const LinearTsrPricer::Settings &settings =
LinearTsrPricer::Settings()) {
return new LinearTsrPricerPtr(
new LinearTsrPricer(swaptionVol, meanReversion,
couponDiscountCurve, settings));
}
}
};
// cash flow vector builders
%{
Leg _FixedRateLeg(const Schedule& schedule,
const DayCounter& dayCount,
const std::vector<Real>& nominals,
const std::vector<Rate>& couponRates,
BusinessDayConvention paymentAdjustment = Following,
const DayCounter& firstPeriodDayCount = DayCounter()) {
return QuantLib::FixedRateLeg(schedule)
.withNotionals(nominals)
.withCouponRates(couponRates,dayCount)
.withPaymentAdjustment(paymentAdjustment)
.withFirstPeriodDayCounter(firstPeriodDayCount);
}
%}
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") _FixedRateLeg;
#endif
%rename(FixedRateLeg) _FixedRateLeg;
Leg _FixedRateLeg(const Schedule& schedule,
const DayCounter& dayCount,
const std::vector<Real>& nominals,
const std::vector<Rate>& couponRates,
BusinessDayConvention paymentAdjustment = Following,
const DayCounter& firstPeriodDayCount = DayCounter());
%{
Leg _IborLeg(const std::vector<Real>& nominals,
const Schedule& schedule,
const boost::shared_ptr<Index>& index,
const DayCounter& paymentDayCounter = DayCounter(),
const BusinessDayConvention paymentConvention = Following,
const std::vector<Natural>& fixingDays = std::vector<Natural>(),
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 isInArrears = false) {
boost::shared_ptr<IborIndex> libor =
boost::dynamic_pointer_cast<IborIndex>(index);
return QuantLib::IborLeg(schedule, libor)
.withNotionals(nominals)
.withPaymentDayCounter(paymentDayCounter)
.withPaymentAdjustment(paymentConvention)
.withFixingDays(fixingDays)
.withGearings(gearings)
.withSpreads(spreads)
.withCaps(caps)
.withFloors(floors)
.inArrears(isInArrears);
}
%}
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") _IborLeg;
#endif
%rename(IborLeg) _IborLeg;
Leg _IborLeg(const std::vector<Real>& nominals,
const Schedule& schedule,
const IborIndexPtr& index,
const DayCounter& paymentDayCounter = DayCounter(),
const BusinessDayConvention paymentConvention = Following,
const std::vector<Natural>& fixingDays = std::vector<Natural>(),
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 isInArrears = false);
%{
Leg _CmsLeg(const std::vector<Real>& nominals,
const Schedule& schedule,
const boost::shared_ptr<Index>& index,
const DayCounter& paymentDayCounter = DayCounter(),
const BusinessDayConvention paymentConvention = Following,
const std::vector<Natural>& fixingDays = std::vector<Natural>(),
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 isInArrears = false) {
boost::shared_ptr<SwapIndex> swapIndex =
boost::dynamic_pointer_cast<SwapIndex>(index);
return QuantLib::CmsLeg(schedule, swapIndex)
.withNotionals(nominals)
.withPaymentDayCounter(paymentDayCounter)
.withPaymentAdjustment(paymentConvention)
.withFixingDays(fixingDays)
.withGearings(gearings)
.withSpreads(spreads)
.withCaps(caps)
.withFloors(floors)
.inArrears(isInArrears);
}
%}
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") _CmsLeg;
#endif
%rename(CmsLeg) _CmsLeg;
Leg _CmsLeg(const std::vector<Real>& nominals,
const Schedule& schedule,
const SwapIndexPtr& index,
const DayCounter& paymentDayCounter = DayCounter(),
const BusinessDayConvention paymentConvention = Following,
const std::vector<Natural>& fixingDays = std::vector<Natural>(),
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 isInArrears = false);
%{
Leg _CmsZeroLeg(const std::vector<Real>& nominals,
const Schedule& schedule,
const boost::shared_ptr<Index>& index,
const DayCounter& paymentDayCounter = DayCounter(),
const BusinessDayConvention paymentConvention = Following,
const std::vector<Natural>& fixingDays = std::vector<Natural>(),
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>()) {
boost::shared_ptr<SwapIndex> swapIndex =
boost::dynamic_pointer_cast<SwapIndex>(index);
return QuantLib::CmsLeg(schedule, swapIndex)
.withNotionals(nominals)
.withPaymentDayCounter(paymentDayCounter)
.withPaymentAdjustment(paymentConvention)
.withFixingDays(fixingDays)
.withGearings(gearings)
.withSpreads(spreads)
.withCaps(caps)
.withFloors(floors)
.withZeroPayments();
}
%}
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") _CmsZeroLeg;
#endif
%rename(CmsZeroLeg) _CmsZeroLeg;
Leg _CmsZeroLeg(const std::vector<Real>& nominals,
const Schedule& schedule,
const SwapIndexPtr& index,
const DayCounter& paymentDayCounter = DayCounter(),
const BusinessDayConvention paymentConvention = Following,
const std::vector<Natural>& fixingDays = std::vector<Natural>(),
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>());
// cash-flow analysis
%{
using QuantLib::CashFlows;
using QuantLib::Duration;
%}
struct Duration {
enum Type { Simple, Macaulay, Modified };
};
class CashFlows {
#if defined(SWIGPYTHON)
%rename("yieldRate") yield;
#endif
private:
CashFlows();
CashFlows(const CashFlows&);
public:
static Date startDate(const Leg &);
static Date maturityDate(const Leg &);
%extend {
static Real npv(
const Leg& leg,
const boost::shared_ptr<YieldTermStructure>& discountCurve,
Spread zSpread,
const DayCounter &dayCounter,
Compounding compounding,
Frequency frequency,
bool includeSettlementDateFlows,
const Date& settlementDate = Date(),
const Date& npvDate = Date()) {
return QuantLib::CashFlows::npv(leg, discountCurve,
zSpread,
dayCounter,
compounding,
frequency,
includeSettlementDateFlows,
settlementDate,
npvDate);
}
static Real npv(
const Leg& leg,
const Handle<YieldTermStructure>& discountCurve,
bool includeSettlementDateFlows,
const Date& settlementDate = Date(),
const Date& npvDate = Date()) {
return QuantLib::CashFlows::npv(leg, **discountCurve,
includeSettlementDateFlows,
settlementDate, npvDate);
}
}
static Real npv(const Leg&,
const InterestRate&,
bool includeSettlementDateFlows,
Date settlementDate = Date(),
Date npvDate = Date());
static Real npv(const Leg&,
Rate yield,
const DayCounter&dayCounter,
Compounding compounding,
Frequency frequency,
bool includeSettlementDateFlows,
Date settlementDate = Date(),
Date npvDate = Date());
%extend {
static Real bps(
const Leg& leg,
const boost::shared_ptr<YieldTermStructure>& discountCurve,
bool includeSettlementDateFlows,
const Date& settlementDate = Date(),
const Date& npvDate = Date()) {
return QuantLib::CashFlows::bps(leg, *discountCurve,
includeSettlementDateFlows,
settlementDate, npvDate);
}
static Real bps(
const Leg& leg,
const Handle<YieldTermStructure>& discountCurve,
bool includeSettlementDateFlows,
const Date& settlementDate = Date(),
const Date& npvDate = Date()) {
return QuantLib::CashFlows::bps(leg, **discountCurve,
includeSettlementDateFlows,
settlementDate, npvDate);
}
}
static Real bps(const Leg&,
const InterestRate &,
bool includeSettlementDateFlows,
Date settlementDate = Date(),
Date npvDate = Date());
static Real bps(const Leg&,
Rate yield,
const DayCounter&dayCounter,
Compounding compounding,
Frequency frequency,
bool includeSettlementDateFlows,
Date settlementDate = Date(),
Date npvDate = Date());
%extend {
static Rate atmRate(
const Leg& leg,
const boost::shared_ptr<YieldTermStructure>& discountCurve,
bool includeSettlementDateFlows,
const Date& settlementDate = Date(),
const Date& npvDate = Date(),
Real npv = Null<Real>()) {
return QuantLib::CashFlows::atmRate(leg, *discountCurve,
includeSettlementDateFlows,
settlementDate, npvDate,
npv);
}
}
static Rate yield(const Leg&,
Real npv,
const DayCounter& dayCounter,
Compounding compounding,
Frequency frequency,
bool includeSettlementDateFlows,
Date settlementDate = Date(),
Date npvDate = Date(),
Real accuracy = 1.0e-10,
Size maxIterations = 10000,
Rate guess = 0.05);
static Time duration(const Leg&,
const InterestRate&,
Duration::Type type,
bool includeSettlementDateFlows,
Date settlementDate = Date());
static Time duration(const Leg&,
Rate yield,
const DayCounter& dayCounter,
Compounding compounding,
Frequency frequency,
Duration::Type type,
bool includeSettlementDateFlows,
Date settlementDate = Date(),
Date npvDate = Date());
static Real convexity(const Leg&,
const InterestRate&,
bool includeSettlementDateFlows,
Date settlementDate = Date(),
Date npvDate = Date());
static Real convexity(const Leg&,
Rate yield,
const DayCounter& dayCounter,
Compounding compounding,
Frequency frequency,
bool includeSettlementDateFlows,
Date settlementDate = Date(),
Date npvDate = Date());
static Real basisPointValue(const Leg& leg,
const InterestRate& yield,
bool includeSettlementDateFlows,
Date settlementDate = Date(),
Date npvDate = Date());
static Real basisPointValue(const Leg& leg,
Rate yield,
const DayCounter& dayCounter,
Compounding compounding,
Frequency frequency,
bool includeSettlementDateFlows,
Date settlementDate = Date(),
Date npvDate = Date());
static Spread zSpread(const Leg& leg,
Real npv,
const boost::shared_ptr<YieldTermStructure>&,
const DayCounter& dayCounter,
Compounding compounding,
Frequency frequency,
bool includeSettlementDateFlows,
Date settlementDate = Date(),
Date npvDate = Date(),
Real accuracy = 1.0e-10,
Size maxIterations = 100,
Rate guess = 0.0);
};
#endif