File: swap.i

package info (click to toggle)
quantlib-swig 1.40-3
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 2,276 kB
  • sloc: python: 6,024; java: 1,552; cs: 774; makefile: 309; sh: 22
file content (710 lines) | stat: -rw-r--r-- 28,629 bytes parent folder | download | duplicates (2)
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
/*
 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
 Copyright (C) 2007 StatPro Italia srl
 Copyright (C) 2011 Lluis Pujol Bajador
 Copyright (C) 2015 Gouthaman Balaraman
 Copyright (C) 2016 Peter Caspers
 Copyright (C) 2017, 2018, 2019 Matthias Lungwitz
 Copyright (C) 2018 Matthias Groncki
 Copyright (C) 2023 Marcin Rybacki

 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
 <https://www.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_swap_i
#define quantlib_swap_i

%include instruments.i
%include termstructures.i
%include cashflows.i
%include timebasket.i
%include indexes.i
%include bonds.i

%{
using QuantLib::Swap;
using QuantLib::FixedVsFloatingSwap;
using QuantLib::VanillaSwap;
using QuantLib::MakeVanillaSwap;
using QuantLib::NonstandardSwap;
using QuantLib::DiscountingSwapEngine;
using QuantLib::FloatFloatSwap;
using QuantLib::OvernightIndexedSwap;
using QuantLib::MakeOIS;
using QuantLib::ZeroCouponSwap;
using QuantLib::EquityTotalReturnSwap;
using QuantLib::ArithmeticAverageOIS;
using QuantLib::simplifyNotificationGraph;
%}

%shared_ptr(Swap)
class Swap : public Instrument {
    %warnfilter(509) Swap;
  public:
    enum Type { Receiver = -1, Payer = 1 };
    Swap(const std::vector<ext::shared_ptr<CashFlow> >& firstLeg,
         const std::vector<ext::shared_ptr<CashFlow> >& secondLeg);
    Swap(const std::vector<Leg>& legs,
         const std::vector<bool>& payer);
    Size numberOfLegs() const;
    Date startDate() const;
    Date maturityDate() const;
    const Leg & leg(Size i);
    Real legNPV(Size j) const;
    Real legBPS(Size k) const;
    DiscountFactor startDiscounts(Size j) const;
    DiscountFactor endDiscounts(Size j) const;
    DiscountFactor npvDateDiscount() const;
    bool payer(Size j) const;
};

void simplifyNotificationGraph(Swap& swap, bool unregisterCoupons = false);


%shared_ptr(FixedVsFloatingSwap)
class FixedVsFloatingSwap : public Swap {
  private:
    FixedVsFloatingSwap();
  public:
    Type type();
    Real nominal();
    std::vector<Real> nominals();

    std::vector<Real> fixedNominals();
    const Schedule& fixedSchedule();
    Rate fixedRate();
    const DayCounter& fixedDayCount();

    std::vector<Real> floatingNominals();
    const Schedule& floatingSchedule();
    const ext::shared_ptr<IborIndex>& iborIndex();
    Spread spread();
    const DayCounter& floatingDayCount();

    BusinessDayConvention paymentConvention() const;

    const Leg& fixedLeg();
    const Leg& floatingLeg();

    Real fixedLegBPS();
    Real fixedLegNPV();
    Rate fairRate();

    Real floatingLegBPS();
    Real floatingLegNPV();
    Spread fairSpread();
};

%shared_ptr(VanillaSwap)
class VanillaSwap : public FixedVsFloatingSwap {
  public:
    #if defined(SWIGPYTHON)
    %feature("kwargs") VanillaSwap;
    VanillaSwap(Type type,
                Real nominal,
                const Schedule& fixedSchedule,
                Rate fixedRate,
                const DayCounter& fixedDayCount,
                const Schedule& floatSchedule,
                const ext::shared_ptr<IborIndex>& index,
                Spread spread,
                const DayCounter& floatingDayCount,
                ext::optional<BusinessDayConvention> paymentConvention = ext::nullopt,
                ext::optional<bool> withIndexedCoupons = ext::nullopt);
    #else
    %extend {
        VanillaSwap(Type type, Real nominal,
                    const Schedule& fixedSchedule, Rate fixedRate,
                    const DayCounter& fixedDayCount,
                    const Schedule& floatSchedule,
                    const ext::shared_ptr<IborIndex>& index,
                    Spread spread,
                    const DayCounter& floatingDayCount,
                    ext::optional<bool> withIndexedCoupons = ext::nullopt) {
            // work around the lack of typemap for this argument
            ext::optional<BusinessDayConvention> paymentConvention = ext::nullopt;

            return new VanillaSwap(type, nominal, fixedSchedule, fixedRate, fixedDayCount,
                                   floatSchedule, index, spread, floatingDayCount,
                                   paymentConvention, withIndexedCoupons);
        }
    }
    #endif
};

#if defined(SWIGPYTHON)
%rename (_MakeVanillaSwap) MakeVanillaSwap;
#endif
class MakeVanillaSwap {
        #if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
        %feature("kwargs") MakeVanillaSwap;
        #endif
      public:
        MakeVanillaSwap& receiveFixed(bool flag = true);
        MakeVanillaSwap& withType(Swap::Type type);
        MakeVanillaSwap& withNominal(Real n);

        MakeVanillaSwap& withSettlementDays(Natural settlementDays);
        MakeVanillaSwap& withEffectiveDate(const Date&);
        MakeVanillaSwap& withTerminationDate(const Date&);
        MakeVanillaSwap& withRule(DateGeneration::Rule r);
        MakeVanillaSwap& withPaymentConvention(BusinessDayConvention bdc);

        MakeVanillaSwap& withFixedLegTenor(const Period& t);
        MakeVanillaSwap& withFixedLegCalendar(const Calendar& cal);
        MakeVanillaSwap& withFixedLegConvention(BusinessDayConvention bdc);
        MakeVanillaSwap& withFixedLegTerminationDateConvention(
                                                   BusinessDayConvention bdc);
        MakeVanillaSwap& withFixedLegRule(DateGeneration::Rule r);
        MakeVanillaSwap& withFixedLegEndOfMonth(bool flag = true);
        MakeVanillaSwap& withFixedLegFirstDate(const Date& d);
        MakeVanillaSwap& withFixedLegNextToLastDate(const Date& d);
        MakeVanillaSwap& withFixedLegDayCount(const DayCounter& dc);

        MakeVanillaSwap& withFloatingLegTenor(const Period& t);
        MakeVanillaSwap& withFloatingLegCalendar(const Calendar& cal);
        MakeVanillaSwap& withFloatingLegConvention(BusinessDayConvention bdc);
        MakeVanillaSwap& withFloatingLegTerminationDateConvention(
                                                   BusinessDayConvention bdc);
        MakeVanillaSwap& withFloatingLegRule(DateGeneration::Rule r);
        MakeVanillaSwap& withFloatingLegEndOfMonth(bool flag = true);
        MakeVanillaSwap& withFloatingLegFirstDate(const Date& d);
        MakeVanillaSwap& withFloatingLegNextToLastDate(const Date& d);
        MakeVanillaSwap& withFloatingLegDayCount(const DayCounter& dc);
        MakeVanillaSwap& withFloatingLegSpread(Spread sp);

        MakeVanillaSwap& withDiscountingTermStructure(
                              const Handle<YieldTermStructure>& discountCurve);
        MakeVanillaSwap& withPricingEngine(
                              const ext::shared_ptr<PricingEngine>& engine);

        MakeVanillaSwap& withIndexedCoupons(bool flag = true);
        MakeVanillaSwap& withAtParCoupons(bool flag = true);

        MakeVanillaSwap(const Period& swapTenor,
                        const ext::shared_ptr<IborIndex>& index,
                        doubleOrNull fixedRate = Null<Rate>(),
                        const Period& forwardStart = 0*Days);
        
        %extend {
            ext::shared_ptr<VanillaSwap> makeVanillaSwap() {
                return (ext::shared_ptr<VanillaSwap>)(* $self);
            }
        }
};

#if defined(SWIGPYTHON)
%pythoncode {
_MAKEVANILLA_METHODS = {
    "receiveFixed": "receiveFixed",
    "swapType": "withType",
    "nominal": "withNominal",
    "settlementDays": "withSettlementDays",
    "effectiveDate": "withEffectiveDate",
    "terminationDate": "withTerminationDate",
    "dateGenerationRule": "withRule",
    "paymentConvention": "withPaymentConvention",
    "fixedLegTenor": "withFixedLegTenor",
    "fixedLegCalendar": "withFixedLegCalendar",
    "fixedLegConvention": "withFixedLegConvention",
    "fixedLegTerminationDateConvention": "withFixedLegTerminationDateConvention",
    "fixedLegDateGenRule": "withFixedLegRule",
    "fixedLegEndOfMonth": "withFixedLegEndOfMonth",
    "fixedLegFirstDate": "withFixedLegFirstDate",
    "fixedLegNextToLastDate": "withFixedLegNextToLastDate",
    "fixedLegDayCount": "withFixedLegDayCount",
    "floatingLegTenor": "withFloatingLegTenor",
    "floatingLegCalendar": "withFloatingLegCalendar",
    "floatingLegConvention": "withFloatingLegConvention",
    "floatingLegTerminationDateConvention": "withFloatingLegTerminationDateConvention",
    "floatingLegDateGenRule": "withFloatingLegRule",
    "floatingLegEndOfMonth": "withFloatingLegEndOfMonth",
    "floatingLegFirstDate": "withFloatingLegFirstDate",
    "floatingLegNextToLastDate": "withFloatingLegNextToLastDate",
    "floatingLegDayCount": "withFloatingLegDayCount",
    "floatingLegSpread": "withFloatingLegSpread",
    "discountingTermStructure": "withDiscountingTermStructure",
    "pricingEngine": "withPricingEngine",
    "withIndexedCoupons": "withIndexedCoupons",
    "atParCoupons": "withAtParCoupons",
}

def MakeVanillaSwap(swapTenor, iborIndex, fixedRate=None, forwardStart=Period(0, Days), **kwargs):
    mv = _MakeVanillaSwap(swapTenor, iborIndex, fixedRate, forwardStart)
    _apply_kwargs("MakeVanillaSwap", _MAKEVANILLA_METHODS, mv, kwargs)
    return mv.makeVanillaSwap()

def _apply_kwargs(func_name, method_map, mv, attrs):
    for name, value in attrs.items():
        try:
            method = method_map[name]
        except KeyError:
            raise TypeError(f"{func_name}() got an unexpected keyword argument {name!r}") from None
        if value is not None:
            getattr(mv, method)(value)
}
#endif

%shared_ptr(NonstandardSwap)
class NonstandardSwap : public Swap {
  public:
    NonstandardSwap(Type type,
                    const std::vector<Real> &fixedNominal,
                    const std::vector<Real> &floatingNominal,
                    const Schedule &fixedSchedule,
                    const std::vector<Real> &fixedRate,
                    const DayCounter &fixedDayCount,
                    const Schedule &floatSchedule,
                    const ext::shared_ptr<IborIndex> &index,
                    const std::vector<Real> &gearing,
                    const std::vector<Spread> &spread,
                    const DayCounter &floatDayCount,
                    const bool intermediateCapitalExchange = false,
                    const bool finalCapitalExchange = false,
                    BusinessDayConvention paymentConvention = Following);
    // Inspectors
    Type type() const;
    const std::vector<Real> &fixedNominal() const;
    const std::vector<Real> &floatingNominal() const;

    const Schedule &fixedSchedule() const;
    const std::vector<Real> &fixedRate() const;
    const DayCounter &fixedDayCount() const;

    const Schedule &floatingSchedule() const;
    const ext::shared_ptr<IborIndex> &iborIndex() const;
    Spread spread() const;
    Real gearing() const;
    const std::vector<Spread>& spreads() const;
    const std::vector<Real>& gearings() const;
    const DayCounter &floatingDayCount() const;

    BusinessDayConvention paymentConvention() const;

    const Leg &fixedLeg() const;
    const Leg &floatingLeg() const;
};

%shared_ptr(DiscountingSwapEngine)
class DiscountingSwapEngine : public PricingEngine {
  public:
    DiscountingSwapEngine(const Handle<YieldTermStructure>& discountCurve,
                          bool includeSettlementDateFlows,
                          const Date& settlementDate = Date(),
                          const Date& npvDate = Date());
    %extend {
        DiscountingSwapEngine(const Handle<YieldTermStructure>& discountCurve,
                              const Date& settlementDate = Date(),
                              const Date& npvDate = Date()) {
            return new DiscountingSwapEngine(discountCurve,
                                             ext::nullopt,
                                             settlementDate,
                                             npvDate);
        }
    }
};


%{
using QuantLib::AssetSwap;
using QuantLib::OvernightIndexedSwapIndex;
%}

%shared_ptr(AssetSwap)
class AssetSwap : public Swap {
    #if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
    %feature("kwargs") AssetSwap;
    #endif
  public:
    AssetSwap(bool payFixedRate,
              const ext::shared_ptr<Bond>& bond,
              Real bondCleanPrice,
              const ext::shared_ptr<IborIndex>& index,
              Spread spread,
              const Schedule& floatSchedule = Schedule(),
              const DayCounter& floatingDayCount = DayCounter(),
              bool parAssetSwap = true,
              Real gearing = 1.0,
              Real nonParRepayment = Null<Real>(),
              Date dealMaturity = Date());
    Real fairCleanPrice();
    Spread fairSpread();
};

%shared_ptr(FloatFloatSwap)
class FloatFloatSwap : public Swap {
  public:
    FloatFloatSwap(Type type, const std::vector<Real> &nominal1,
        const std::vector<Real> &nominal2, const Schedule &schedule1,
        const ext::shared_ptr<InterestRateIndex> &index1,
        const DayCounter &dayCount1, const Schedule &schedule2,
        const ext::shared_ptr<InterestRateIndex> &index2,
        const DayCounter &dayCount2,
        const bool intermediateCapitalExchange = false,
        const bool finalCapitalExchange = false,
        const std::vector<Real> &gearing1 = std::vector<Real>(),
        const std::vector<Real> &spread1 = std::vector<Real>(),
        const std::vector<Real> &cappedRate1 = std::vector<Real>(),
        const std::vector<Real> &flooredRate1 = std::vector<Real>(),
        const std::vector<Real> &gearing2 = std::vector<Real>(),
        const std::vector<Real> &spread2 = std::vector<Real>(),
        const std::vector<Real> &cappedRate2 = std::vector<Real>(),
        const std::vector<Real> &flooredRate2 = std::vector<Real>(),
        BusinessDayConvention paymentConvention1 = Following,
        BusinessDayConvention paymentConvention2 = Following);
};

%shared_ptr(OvernightIndexedSwap)
class OvernightIndexedSwap : public FixedVsFloatingSwap {
  public:
    OvernightIndexedSwap(
            Type type,
            Real nominal,
            const Schedule& schedule,
            Rate fixedRate,
            const DayCounter& fixedDC,
            const ext::shared_ptr<OvernightIndex>& index,
            Spread spread = 0.0,
            Integer paymentLag = 0,
            BusinessDayConvention paymentAdjustment = Following,
            Calendar paymentCalendar = Calendar(),
            bool telescopicValueDates = false,
            RateAveraging::Type averagingMethod = RateAveraging::Compound,
            Natural lookbackDays = Null<Natural>(),
            Natural lockoutDays = 0,
            bool applyObservationShift = false);
    
    OvernightIndexedSwap(
            Type type,
            std::vector<Real> nominals,
            const Schedule& schedule,
            Rate fixedRate,
            const DayCounter& fixedDC,
            const ext::shared_ptr<OvernightIndex>& index,
            Spread spread = 0.0,
            Integer paymentLag = 0,
            BusinessDayConvention paymentAdjustment = Following,
            Calendar paymentCalendar = Calendar(),
            bool telescopicValueDates = false,
            RateAveraging::Type averagingMethod = RateAveraging::Compound,
            Natural lookbackDays = Null<Natural>(),
            Natural lockoutDays = 0,
            bool applyObservationShift = false);

    OvernightIndexedSwap(Type type,
                         const std::vector<Real>& fixedNominals,
                         const Schedule& fixedSchedule,
                         Rate fixedRate,
                         const DayCounter& fixedDC,
                         const std::vector<Real>& overnightNominals,
                         const Schedule& overnightSchedule,
                         const ext::shared_ptr<OvernightIndex>& overnightIndex,
                         Spread spread = 0.0,
                         Integer paymentLag = 0,
                         BusinessDayConvention paymentAdjustment = Following,
                         const Calendar& paymentCalendar = Calendar(),
                         bool telescopicValueDates = false,
                         RateAveraging::Type averagingMethod = RateAveraging::Compound,
                         Natural lookbackDays = Null<Natural>(),
                         Natural lockoutDays = 0,
                         bool applyObservationShift = false);

    Real overnightLegBPS();
    Real overnightLegNPV();
    // Inspectors
    Frequency paymentFrequency();
    ext::shared_ptr<OvernightIndex> overnightIndex() const;
    const Leg& overnightLeg();
    RateAveraging::Type averagingMethod();
    Natural lookbackDays() const;
    Natural lockoutDays() const;
    bool applyObservationShift() const;
};

#if defined(SWIGPYTHON)
%rename (_MakeOIS) MakeOIS;
#endif
class MakeOIS {
        #if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
        %feature("kwargs") MakeOIS;
        #endif
      public:
        MakeOIS(const Period& swapTenor,
                const ext::shared_ptr<OvernightIndex>& overnightIndex,
                doubleOrNull fixedRate = Null<Rate>(),
                const Period& fwdStart = 0*Days);

        %extend {
            ext::shared_ptr<OvernightIndexedSwap> makeOIS() {
                return (ext::shared_ptr<OvernightIndexedSwap>)(* $self);
            }
        }

        MakeOIS& receiveFixed(bool flag = true);
        MakeOIS& withType(Swap::Type type);
        MakeOIS& withNominal(Real n);
        MakeOIS& withSettlementDays(Natural settlementDays);
        MakeOIS& withEffectiveDate(const Date&);
        MakeOIS& withTerminationDate(const Date&);
        MakeOIS& withRule(DateGeneration::Rule r);
        MakeOIS& withFixedLegRule(DateGeneration::Rule r);
        MakeOIS& withOvernightLegRule(DateGeneration::Rule r);
        MakeOIS& withPaymentFrequency(Frequency f);
        MakeOIS& withFixedLegPaymentFrequency(Frequency f);
        MakeOIS& withOvernightLegPaymentFrequency(Frequency f);
        MakeOIS& withPaymentAdjustment(BusinessDayConvention convention);
        MakeOIS& withPaymentLag(Integer lag);
        MakeOIS& withPaymentCalendar(const Calendar& cal);
        MakeOIS& withCalendar(const Calendar& cal);
        MakeOIS& withFixedLegCalendar(const Calendar& cal);
        MakeOIS& withOvernightLegCalendar(const Calendar& cal);
        MakeOIS& withConvention(BusinessDayConvention bdc);
        MakeOIS& withFixedLegConvention(BusinessDayConvention bdc);
        MakeOIS& withOvernightLegConvention(BusinessDayConvention bdc);
        MakeOIS& withTerminationDateConvention(BusinessDayConvention bdc);
        MakeOIS& withFixedLegTerminationDateConvention(BusinessDayConvention bdc);
        MakeOIS& withOvernightLegTerminationDateConvention(BusinessDayConvention bdc);
        MakeOIS& withEndOfMonth(bool flag = true);
        MakeOIS& withFixedLegEndOfMonth(bool flag = true);
        MakeOIS& withOvernightLegEndOfMonth(bool flag = true);
        MakeOIS& withFixedLegDayCount(const DayCounter& dc);
        MakeOIS& withOvernightLegSpread(Spread sp);
        MakeOIS& withDiscountingTermStructure(
                  const Handle<YieldTermStructure>& discountingTermStructure);
        MakeOIS& withTelescopicValueDates(bool telescopicValueDates);
        MakeOIS& withAveragingMethod(RateAveraging::Type averagingMethod);
        MakeOIS& withLookbackDays(Natural lookbackDays);
        MakeOIS& withLockoutDays(Natural lockoutDays);
        MakeOIS& withObservationShift(bool applyObservationShift = true);
        MakeOIS& withPricingEngine(
                              const ext::shared_ptr<PricingEngine>& engine);
};

#if defined(SWIGPYTHON)
%pythoncode {
_MAKEOIS_METHODS = {
    "receiveFixed": "receiveFixed",
    "swapType": "withType",
    "nominal": "withNominal",
    "settlementDays": "withSettlementDays",
    "effectiveDate": "withEffectiveDate",
    "terminationDate": "withTerminationDate",
    "dateGenerationRule": "withRule",
    "fixedLegRule": "withFixedLegRule",
    "overnightLegRule": "withOvernightLegRule",
    "paymentFrequency": "withPaymentFrequency",
    "fixedLegPaymentFrequency": "withFixedLegPaymentFrequency",
    "overnightLegPaymentFrequency": "withOvernightLegPaymentFrequency",
    "paymentAdjustmentConvention": "withPaymentAdjustment",
    "paymentLag": "withPaymentLag",
    "paymentCalendar": "withPaymentCalendar",
    "calendar": "withCalendar",
    "fixedLegCalendar": "withFixedLegCalendar",
    "overnightLegCalendar": "withOvernightLegCalendar",
    "convention": "withConvention",
    "fixedLegConvention": "withFixedLegConvention",
    "overnightLegConvention": "withOvernightLegConvention",
    "terminationDateConvention": "withTerminationDateConvention",
    "fixedLegTerminationDateConvention": "withFixedLegTerminationDateConvention",
    "overnightLegTerminationDateConvention": "withOvernightLegTerminationDateConvention",
    "endOfMonth": "withEndOfMonth",
    "fixedLegEndOfMonth": "withFixedLegEndOfMonth",
    "overnightLegEndOfMonth": "withOvernightLegEndOfMonth",
    "fixedLegDayCount": "withFixedLegDayCount",
    "overnightLegSpread": "withOvernightLegSpread",
    "discountingTermStructure": "withDiscountingTermStructure",
    "telescopicValueDates": "withTelescopicValueDates",
    "averagingMethod": "withAveragingMethod",
    "lookbackDays": "withLookbackDays",
    "lockoutDays": "withLockoutDays",
    "applyObservationShift": "withObservationShift",
    "pricingEngine": "withPricingEngine",
}

def MakeOIS(swapTenor, overnightIndex, fixedRate=None, fwdStart=Period(0, Days), **kwargs):
    mv = _MakeOIS(swapTenor, overnightIndex, fixedRate, fwdStart)
    _apply_kwargs("MakeOIS", _MAKEOIS_METHODS, mv, kwargs)
    return mv.makeOIS()
}
#endif


%shared_ptr(OvernightIndexedSwapIndex)
class OvernightIndexedSwapIndex : public SwapIndex {
  public:
    OvernightIndexedSwapIndex(
              const std::string& familyName,
              const Period& tenor,
              Natural settlementDays,
              Currency currency,
              const ext::shared_ptr<OvernightIndex>& overnightIndex,
              bool telescopicValueDates = false,
              RateAveraging::Type averagingMethod = RateAveraging::Compound);
    //! \name Inspectors
    //@{
    ext::shared_ptr<OvernightIndex> overnightIndex() const;
    /*! \warning Relinking the term structure underlying the index will
                 not have effect on the returned swap.
    */
    ext::shared_ptr<OvernightIndexedSwap> underlyingSwap(
                                            const Date& fixingDate) const;
};

%inline %{
    ext::shared_ptr<OvernightIndexedSwap> as_overnight_swap_index(
                          const ext::shared_ptr<InterestRateIndex>& index) {
        return ext::dynamic_pointer_cast<OvernightIndexedSwap>(index);
    }
%}

%shared_ptr(ZeroCouponSwap)
class ZeroCouponSwap : public Swap {
  public:
    ZeroCouponSwap(Type type,
                   Real baseNominal,
                   const Date& startDate,
                   const Date& maturityDate, 
                   Real fixedPayment,
                   ext::shared_ptr<IborIndex> iborIndex,
                   const Calendar& paymentCalendar,
                   BusinessDayConvention paymentConvention = Following,
                   Natural paymentDelay = 0);

    ZeroCouponSwap(Type type,
                   Real baseNominal,
                   const Date& startDate,
                   const Date& maturityDate,
                   Rate fixedRate,
                   const DayCounter& fixedDayCounter,
                   ext::shared_ptr<IborIndex> iborIndex,
                   const Calendar& paymentCalendar,
                   BusinessDayConvention paymentConvention = Following,
                   Natural paymentDelay = 0);

    // Inspectors
    Type type() const;
    Real baseNominal() const;
    const ext::shared_ptr<IborIndex>& iborIndex() const;
    
    const Leg& fixedLeg() const;
    const Leg& floatingLeg() const;
    Real fixedPayment() const;

    Real fixedLegNPV() const;
    Real floatingLegNPV() const;
    Real fairFixedPayment() const;
    Rate fairFixedRate(const DayCounter& dayCounter) const;
};

%shared_ptr(EquityTotalReturnSwap)
class EquityTotalReturnSwap : public Swap {
  public:
    EquityTotalReturnSwap(Type type,
                          Real nominal,
                          Schedule schedule,
                          ext::shared_ptr<EquityIndex> equityIndex,
                          const ext::shared_ptr<IborIndex>& interestRateIndex,
                          DayCounter dayCounter,
                          Rate margin,
                          Real gearing = 1.0,
                          Calendar paymentCalendar = Calendar(),
                          BusinessDayConvention paymentConvention = Unadjusted,
                          Natural paymentDelay = 0);

    EquityTotalReturnSwap(Type type,
                          Real nominal,
                          Schedule schedule,
                          ext::shared_ptr<EquityIndex> equityIndex,
                          const ext::shared_ptr<OvernightIndex>& interestRateIndex,
                          DayCounter dayCounter,
                          Rate margin,
                          Real gearing = 1.0,
                          Calendar paymentCalendar = Calendar(),
                          BusinessDayConvention paymentConvention = Unadjusted,
                          Natural paymentDelay = 0);

    // Inspectors
    Type type() const;
    Real nominal() const;
    
    const ext::shared_ptr<EquityIndex>& equityIndex() const;
    const ext::shared_ptr<InterestRateIndex>& interestRateIndex() const;
    
    const Schedule& schedule() const;
    const DayCounter& dayCounter() const;
    Rate margin() const;
    Real gearing() const;
    const Calendar& paymentCalendar() const;
    BusinessDayConvention paymentConvention() const;
    Natural paymentDelay() const;

    const Leg& equityLeg() const;
    const Leg& interestRateLeg() const;

    Real equityLegNPV() const;
    Real interestRateLegNPV() const;
    Real fairMargin() const;
};

%shared_ptr(ArithmeticAverageOIS)
class ArithmeticAverageOIS : public Swap {
  public:
    ArithmeticAverageOIS(Type type,
                         Real nominal,
                         const Schedule& fixedLegSchedule,
                         Rate fixedRate,
                         DayCounter fixedDC,
                         ext::shared_ptr<OvernightIndex> overnightIndex,
                         const Schedule& overnightLegSchedule,
                         Spread spread = 0.0,
                         Real meanReversionSpeed = 0.03,
                         Real volatility = 0.00, // NO convexity adjustment by default
                         bool byApprox = false); // TRUE to use Katsumi Takada approximation
    ArithmeticAverageOIS(Type type,
                         std::vector<Real> nominals,
                         const Schedule& fixedLegSchedule,
                         Rate fixedRate,
                         DayCounter fixedDC,
                         ext::shared_ptr<OvernightIndex> overnightIndex,
                         const Schedule& overnightLegSchedule,
                         Spread spread = 0.0,
                         Real meanReversionSpeed = 0.03,
                         Real volatility = 0.00, // NO convexity adjustment by default
                         bool byApprox = false); // TRUE to use Katsumi Takada approximation

    Type type() const;
    Real nominal() const;
    std::vector<Real> nominals() const;

    Frequency fixedLegPaymentFrequency();
    Frequency overnightLegPaymentFrequency();

    Rate fixedRate() const;
    const DayCounter& fixedDayCount();

    ext::shared_ptr<OvernightIndex> overnightIndex();
    Spread spread() const;

    const Leg& fixedLeg() const;
    const Leg& overnightLeg() const;

    Real fixedLegBPS() const;
    Real fixedLegNPV() const;
    Real fairRate() const;

    Real overnightLegBPS() const;
    Real overnightLegNPV() const;
    Spread fairSpread() const;
};
#endif