Coverage Report

Created: 2026-03-31 07:01

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 NPV is computed as:
38
        \f[
39
        \text{NPV} = \pm N_{source} \times D_{source}(T) \mp N_{target} \times D_{target}(T) / S
40
        \f]
41
        where:
42
        - \f$ N_{source} \f$ is the source currency nominal
43
        - \f$ N_{target} \f$ is the target currency nominal
44
        - \f$ D_{source}(T) \f$ is the source currency discount factor to maturity
45
        - \f$ D_{target}(T) \f$ is the target currency discount factor to maturity
46
        - \f$ S \f$ is the spot FX rate (target/source)
47
        - \f$ T \f$ is the maturity date
48
49
        The fair forward rate is computed as:
50
        \f[
51
        F = S \times \frac{D_{target}(T)}{D_{source}(T)}
52
        \f]
53
54
        \ingroup forwardengines
55
    */
56
    class DiscountingFxForwardEngine : public FxForward::engine {
57
      public:
58
        /*! \param sourceCurrencyDiscountCurve  Discount curve for source currency
59
            \param targetCurrencyDiscountCurve  Discount curve for target currency
60
            \param spotFx                       Spot FX rate (target/source), i.e.,
61
                                                1 unit of source currency = spotFx units of target currency
62
        */
63
        DiscountingFxForwardEngine(Handle<YieldTermStructure> sourceCurrencyDiscountCurve,
64
                                   Handle<YieldTermStructure> targetCurrencyDiscountCurve,
65
                                   Handle<Quote> spotFx);
66
67
        void calculate() const override;
68
69
        //! \name Inspectors
70
        //@{
71
0
        const Handle<YieldTermStructure>& sourceCurrencyDiscountCurve() const {
72
0
            return sourceCurrencyDiscountCurve_;
73
0
        }
74
0
        const Handle<YieldTermStructure>& targetCurrencyDiscountCurve() const {
75
0
            return targetCurrencyDiscountCurve_;
76
0
        }
77
0
        const Handle<Quote>& spotFx() const { return spotFx_; }
78
        //@}
79
80
      private:
81
        Handle<YieldTermStructure> sourceCurrencyDiscountCurve_;
82
        Handle<YieldTermStructure> targetCurrencyDiscountCurve_;
83
        Handle<Quote> spotFx_;
84
    };
85
86
}
87
88
#endif