1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2008, 2009 Ralph Schreyer
5  Copyright (C) 2008, 2009 Klaus Spanderen
6 
7  This file is part of QuantLib, a free-software/open-source library
8  for financial quantitative analysts and developers - http://quantlib.org/
9 
10  QuantLib is free software: you can redistribute it and/or modify it
11  under the terms of the QuantLib license.  You should have received a
12  copy of the license along with this program; if not, please email
13  <quantlib-dev@lists.sf.net>. The license is also available online at
14  <http://quantlib.org/license.shtml>.
15 
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE.  See the license for more details.
19 */
20 
21 /*! \file fdmquantohelper.cpp
22 \brief quanto helper to store market data needed for the quanto adjustment.
23 */
24 
25 #include <ql/methods/finitedifferences/utilities/fdmquantohelper.hpp>
26 #include <ql/termstructures/yieldtermstructure.hpp>
27 #include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
28 
29 namespace QuantLib {
30 
FdmQuantoHelper(const ext::shared_ptr<YieldTermStructure> & rTS,const ext::shared_ptr<YieldTermStructure> & fTS,const ext::shared_ptr<BlackVolTermStructure> & fxVolTS,Real equityFxCorrelation,Real exchRateATMlevel)31     FdmQuantoHelper::FdmQuantoHelper(
32         const ext::shared_ptr<YieldTermStructure> & rTS,
33         const ext::shared_ptr<YieldTermStructure> & fTS,
34         const ext::shared_ptr<BlackVolTermStructure> & fxVolTS,
35         Real equityFxCorrelation,
36         Real exchRateATMlevel)
37     : rTS_(rTS),
38       fTS_(fTS),
39       fxVolTS_(fxVolTS),
40       equityFxCorrelation_(equityFxCorrelation),
41       exchRateATMlevel_(exchRateATMlevel) {}
42 
quantoAdjustment(Volatility equityVol,Time t1,Time t2) const43     Rate FdmQuantoHelper::quantoAdjustment(Volatility equityVol,
44                                                  Time t1, Time t2) const {
45         const Rate rDomestic = rTS_->forwardRate(t1, t2, Continuous).rate();
46         const Rate rForeign  = fTS_->forwardRate(t1, t2, Continuous).rate();
47         const Volatility fxVol
48             = fxVolTS_->blackForwardVol(t1, t2, exchRateATMlevel_);
49 
50         return rDomestic - rForeign + equityVol*fxVol*equityFxCorrelation_;
51     }
52 
quantoAdjustment(const Array & equityVol,Time t1,Time t2) const53     Disposable<Array> FdmQuantoHelper::quantoAdjustment(
54         const Array& equityVol, Time t1, Time t2) const {
55 
56         const Rate rDomestic = rTS_->forwardRate(t1, t2, Continuous).rate();
57         const Rate rForeign  = fTS_->forwardRate(t1, t2, Continuous).rate();
58         const Volatility fxVol
59             = fxVolTS_->blackForwardVol(t1, t2, exchRateATMlevel_);
60 
61         Array retVal(equityVol.size());
62         for (Size i=0; i < retVal.size(); ++i) {
63             retVal[i]
64                 = rDomestic - rForeign + equityVol[i]*fxVol*equityFxCorrelation_;
65         }
66         return retVal;
67     }
68 }
69