Coverage Report

Created: 2026-06-23 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/pricingengines/forward/discountingfxforwardengine.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2026 Chirag Desai
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <https://www.quantlib.org/license.shtml>.
14
15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19
20
/*! \file discountingfxforwardengine.hpp
21
    \brief Discounting FX Forward engine
22
*/
23
24
#ifndef quantlib_discounting_fx_forward_engine_hpp
25
#define quantlib_discounting_fx_forward_engine_hpp
26
27
#include <ql/handle.hpp>
28
#include <ql/instruments/fxforward.hpp>
29
#include <ql/termstructures/yieldtermstructure.hpp>
30
31
namespace QuantLib {
32
33
    //! Discounting engine for FX Forward
34
    /*! This engine discounts the two legs of an FX forward using their
35
        respective currency discount curves.
36
37
        The source-currency NPV is computed as:
38
        \f[
39
        \text{NPV}_{source} =
40
            \left(\pm N_{source} \times D_{source}(\tau,T)
41
            \mp N_{target} \times D_{target}(\tau,T) / S\right)
42
            \times D_{source}(\tau)
43
        \f]
44
        where:
45
        - \f$ N_{source} \f$ is the source currency nominal
46
        - \f$ N_{target} \f$ is the target currency nominal
47
        - \f$ D_{source}(\tau,T) \f$ is the source currency discount factor
48
          from settlement to maturity
49
        - \f$ D_{target}(\tau,T) \f$ is the target currency discount factor
50
          from settlement to maturity
51
        - \f$ D_{source}(\tau) \f$ is the source currency discount factor to
52
          settlement
53
        - \f$ S \f$ is the spot FX rate (target/source)
54
        - \f$ \tau \f$ is the settlement date
55
        - \f$ T \f$ is the maturity date
56
57
        The fair forward rate is computed as:
58
        \f[
59
        F = S \times \frac{D_{source}(\tau,T)}{D_{target}(\tau,T)}
60
        \f]
61
62
        \ingroup forwardengines
63
    */
64
    class DiscountingFxForwardEngine : public FxForward::engine {
65
      public:
66
        /*! \param sourceCurrencyDiscountCurve  Discount curve for source currency
67
            \param targetCurrencyDiscountCurve  Discount curve for target currency
68
            \param spotFx                       Spot FX rate (target/source), i.e.,
69
                                                1 unit of source currency = spotFx units of target currency
70
        */
71
        DiscountingFxForwardEngine(Handle<YieldTermStructure> sourceCurrencyDiscountCurve,
72
                                   Handle<YieldTermStructure> targetCurrencyDiscountCurve,
73
                                   Handle<Quote> spotFx);
74
75
        void calculate() const override;
76
77
        //! \name Inspectors
78
        //@{
79
0
        const Handle<YieldTermStructure>& sourceCurrencyDiscountCurve() const {
80
0
            return sourceCurrencyDiscountCurve_;
81
0
        }
82
0
        const Handle<YieldTermStructure>& targetCurrencyDiscountCurve() const {
83
0
            return targetCurrencyDiscountCurve_;
84
0
        }
85
0
        const Handle<Quote>& spotFx() const { return spotFx_; }
86
        //@}
87
88
      private:
89
        Handle<YieldTermStructure> sourceCurrencyDiscountCurve_;
90
        Handle<YieldTermStructure> targetCurrencyDiscountCurve_;
91
        Handle<Quote> spotFx_;
92
    };
93
94
}
95
96
#endif