QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
prices.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006, 2007 Ferdinando Ametrano
5 Copyright (C) 2006 Katiuscia Manzoni
6 Copyright (C) 2006 Joseph Wang
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22/*! \file prices.hpp
23 \brief price classes
24*/
25
26#ifndef quantlib_prices_hpp
27#define quantlib_prices_hpp
28
29#include <ql/timeseries.hpp>
30#include <ql/utilities/null.hpp>
31
32namespace QuantLib {
33
34 //! Price types
35 enum PriceType {
36 Bid, /*!< Bid price. */
37 Ask, /*!< Ask price. */
38 Last, /*!< Last price. */
39 Close, /*!< Close price. */
40 Mid, /*!< Mid price, calculated as the arithmetic
41 average of bid and ask prices. */
42 MidEquivalent, /*!< Mid equivalent price, calculated as
43 a) the arithmetic average of bid and ask prices
44 when both are available; b) either the bid or the
45 ask price if any of them is available;
46 c) the last price; or d) the close price. */
47 MidSafe /*!< Safe Mid price, returns the mid price only if
48 both bid and ask are available. */
49 };
50
51 /*! return the MidEquivalent price, i.e. the mid if available,
52 or a suitable substitute if the proper mid is not available
53 \test different combinations are tested
54 */
55 Real midEquivalent(Real bid, Real ask, Real last, Real close);
56
57 /*! return the MidSafe price, i.e. the mid only if
58 both bid and ask prices are available
59 \test different combinations are tested
60 */
61 Real midSafe(Real bid, Real ask);
62
63 //! interval price
64 /*! \test Inspectors, Modifiers, and Helper functions are tested.
65 */
67 public:
68 enum Type { Open, Close, High, Low };
69
72
73 //! \name Inspectors
74 //@{
75 Real open() const { return open_; }
76 Real close() const { return close_; }
77 Real high() const { return high_; }
78 Real low() const { return low_; }
80 //@}
81
82 //! \name Modifiers
83 //@{
86 //@}
87
88 //! \name Helper functions
89 //@{
91 const std::vector<Date>& d,
92 const std::vector<Real>& open,
93 const std::vector<Real>& close,
94 const std::vector<Real>& high,
95 const std::vector<Real>& low);
96 static std::vector<Real> extractValues(
102 //@}
103 private:
105 };
106
107 #ifdef QL_NULL_AS_FUNCTIONS
108
109 template <>
111 return {};
112 };
113
114 #else
115
116 template <>
118 {
119 public:
120 Null() = default;
121 operator IntervalPrice() const { return {}; }
122 };
123
124 #endif
125
126}
127
128#endif
interval price
Definition: prices.hpp:66
static TimeSeries< Real > extractComponent(const TimeSeries< IntervalPrice > &, IntervalPrice::Type)
Definition: prices.cpp:143
void setValue(Real value, IntervalPrice::Type)
Definition: prices.cpp:79
Real low() const
Definition: prices.hpp:78
static std::vector< Real > extractValues(const TimeSeries< IntervalPrice > &, IntervalPrice::Type)
Definition: prices.cpp:132
Real open() const
Definition: prices.hpp:75
Real close() const
Definition: prices.hpp:76
Real high() const
Definition: prices.hpp:77
void setValues(Real open, Real close, Real high, Real low)
Definition: prices.cpp:99
Real value(IntervalPrice::Type) const
Definition: prices.cpp:64
static TimeSeries< IntervalPrice > makeSeries(const std::vector< Date > &d, const std::vector< Real > &open, const std::vector< Real > &close, const std::vector< Real > &high, const std::vector< Real > &low)
Definition: prices.cpp:104
template class providing a null value for a given type.
Definition: null.hpp:76
Container for historical data.
Definition: timeseries.hpp:51
Date d
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
PriceType
Price types.
Definition: prices.hpp:35
@ MidSafe
Definition: prices.hpp:47
@ MidEquivalent
Definition: prices.hpp:42
@ Close
Definition: prices.hpp:39
@ Last
Definition: prices.hpp:38
Real midSafe(const Real bid, const Real ask)
Definition: prices.cpp:46
Real midEquivalent(const Real bid, const Real ask, const Real last, const Real close)
Definition: prices.cpp:27
bool close(const Quantity &m1, const Quantity &m2, Size n)
Definition: quantity.cpp:163
null values
Container for historical data.