File: yoyoptionlethelpers.cpp

package info (click to toggle)
quantlib 1.2-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 30,760 kB
  • sloc: cpp: 232,809; ansic: 21,483; sh: 11,108; makefile: 4,717; lisp: 86
file content (97 lines) | stat: -rw-r--r-- 3,940 bytes parent folder | download | duplicates (3)
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
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
 Copyright (C) 2009 Chris Kenyon

 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.
*/

#include <ql/experimental/inflation/yoyoptionlethelpers.hpp>
#include <ql/instruments/makeyoyinflationcapfloor.hpp>

namespace QuantLib {

    namespace {
        void no_deletion(void*) {}
    }


    YoYOptionletHelper::YoYOptionletHelper(
                  const Handle<Quote>& price,
                  Real notional,
                  YoYInflationCapFloor::Type capFloorType,
                  Period &lag,
                  const DayCounter& yoyDayCounter,
                  const Calendar& paymentCalendar,
                  Natural fixingDays,
                  const boost::shared_ptr<YoYInflationIndex>& index,
                  Rate strike, Size n,
                  const boost::shared_ptr<YoYInflationCapFloorEngine> &pricer)
    : BootstrapHelper<YoYOptionletVolatilitySurface>(price),
      notional_(notional), capFloorType_(capFloorType), lag_(lag),
      fixingDays_(fixingDays), index_(index), strike_(strike), n_(n),
      yoyDayCounter_(yoyDayCounter), calendar_(paymentCalendar),
      pricer_(pricer) {

        // build the instrument to reprice (only need do this once)
        yoyCapFloor_ = boost::shared_ptr<YoYInflationCapFloor>(
                 new YoYInflationCapFloor(
                     MakeYoYInflationCapFloor(capFloorType_, n_, calendar_,
                                              index_, lag_, strike_)
                    .withNominal(notional)
                    .withFixingDays(fixingDays_)
                    .withPaymentDayCounter(yoyDayCounter_)
                                          ));
        // dates already build in lag of index/instrument
        // these are the dates of the values of the index
        // that fix the capfloor
          earliestDate_ =
          boost::dynamic_pointer_cast<YoYInflationCoupon>(yoyCapFloor_->yoyLeg().front())
          ->fixingDate();
          latestDate_ =
          boost::dynamic_pointer_cast<YoYInflationCoupon>(yoyCapFloor_->yoyLeg().back())
          ->fixingDate();

        // each reprice is resetting the inflation surf in the
        // pricer... so set the pricer
        yoyCapFloor_->setPricingEngine(pricer_);
        // haven't yet set the vol (term structure = surface)
    }


    Real YoYOptionletHelper::impliedQuote() const {
        yoyCapFloor_->recalculate();
        return yoyCapFloor_->NPV();
    }


    void YoYOptionletHelper::setTermStructure(
                                           YoYOptionletVolatilitySurface* v) {

        BootstrapHelper<YoYOptionletVolatilitySurface>::setTermStructure(v);
        // set up a new yoyCapFloor
        // but this one does NOT own its inflation term structure
        const bool own = false;
        // create a handle to the new vol surface
        Handle<YoYOptionletVolatilitySurface> volSurf(
              boost::shared_ptr<YoYOptionletVolatilitySurface>(v,no_deletion),
              own);
        // in this case all we need to do is reset the vol in the pricer
        // we must do it because the surface is a different one each time
        // i.e. the pointer (handle) changes, not just what it points to
        pricer_->setVolatility(volSurf);
    }

}