QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
rounding.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004 Decillion Pty(Ltd)
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 <http://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
24#ifndef quantlib_rounding_hpp
25#define quantlib_rounding_hpp
26
27#include <ql/types.hpp>
28
29namespace QuantLib {
30
32
35 class Rounding {
36 public:
38
44 enum Type {
46 Up,
50 Down,
52 Closest,
59 Floor,
62 Ceiling
65 };
67
70 Rounding() = default;
73 Integer digit = 5)
74 : precision_(precision), type_(type), digit_(digit) {}
76 Decimal operator()(Decimal value) const;
78
79 Integer precision() const { return precision_; }
80 Type type() const { return type_; }
81 Integer roundingDigit() const { return digit_; }
82 private:
86 };
87
88
90 class UpRounding : public Rounding {
91 public:
93 Integer digit = 5)
94 : Rounding(precision,Up,digit) {}
95 };
96
98 class DownRounding : public Rounding {
99 public:
101 Integer digit = 5)
102 : Rounding(precision,Down,digit) {}
103 };
104
106 class ClosestRounding : public Rounding {
107 public:
109 Integer digit = 5)
110 : Rounding(precision,Closest,digit) {}
111 };
112
115 public:
117 Integer digit = 5)
118 : Rounding(precision,Ceiling,digit) {}
119 };
120
122 class FloorTruncation : public Rounding {
123 public:
125 Integer digit = 5)
126 : Rounding(precision,Floor,digit) {}
127 };
128
129}
130
131
132#endif
Ceiling truncation.
Definition: rounding.hpp:114
CeilingTruncation(Integer precision, Integer digit=5)
Definition: rounding.hpp:116
Closest rounding.
Definition: rounding.hpp:106
ClosestRounding(Integer precision, Integer digit=5)
Definition: rounding.hpp:108
Down-rounding.
Definition: rounding.hpp:98
DownRounding(Integer precision, Integer digit=5)
Definition: rounding.hpp:100
Concrete floor class.
Definition: capfloor.hpp:118
Floor truncation.
Definition: rounding.hpp:122
FloorTruncation(Integer precision, Integer digit=5)
Definition: rounding.hpp:124
basic rounding class
Definition: rounding.hpp:35
Type
rounding methods
Definition: rounding.hpp:44
Integer precision_
Definition: rounding.hpp:83
Rounding(Integer precision, Type type=Closest, Integer digit=5)
Definition: rounding.hpp:71
Decimal operator()(Decimal value) const
perform rounding
Definition: rounding.cpp:29
Integer precision() const
Definition: rounding.hpp:79
Rounding()=default
default constructor
Integer roundingDigit() const
Definition: rounding.hpp:81
Type type() const
Definition: rounding.hpp:80
Up-rounding.
Definition: rounding.hpp:90
UpRounding(Integer precision, Integer digit=5)
Definition: rounding.hpp:92
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Real Decimal
decimal number
Definition: types.hpp:54
Definition: any.hpp:35