Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
metals.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20#include <set>
21
22using namespace QuantLib;
23using std::set;
24
25namespace QuantExt {
26
27// Troy ounce of Gold
29 static QuantLib::ext::shared_ptr<Data> xauData(
30 new Data("Troy Ounce of Gold", "XAU", 959, "XAU", "", 1, Rounding(), "1$.2f %3%"));
31 data_ = xauData;
32}
33
34// Troy ounce of Silver
36 static QuantLib::ext::shared_ptr<Data> xagData(
37 new Data("Troy Ounce of Silver", "XAG", 961, "XAG", "", 1, Rounding(), "1$.2f %3%"));
38 data_ = xagData;
39}
40
41// Troy ounce of Platinum
43 static QuantLib::ext::shared_ptr<Data> xptData(
44 new Data("Troy Ounce of Platinum", "XPT", 962, "XPT", "", 1, Rounding(), "1$.2f %3%"));
45 data_ = xptData;
46}
47
48// Troy ounce of Palladium
50 static QuantLib::ext::shared_ptr<Data> xpdData(
51 new Data("Troy Ounce of Palladium", "XPD", 964, "XPD", "", 1, Rounding(), "1$.2f %3%"));
52 data_ = xpdData;
53}
54
55bool isMetal(const Currency& currency) {
56
57 static auto cmpCcy = [](const Currency& c1, const Currency& c2) { return c1.name() < c2.name(); };
58 static set<Currency, decltype(cmpCcy)> metals(cmpCcy);
59
60 if (metals.empty()) {
61 metals.insert(XAUCurrency());
62 metals.insert(XAGCurrency());
63 metals.insert(XPTCurrency());
64 metals.insert(XPDCurrency());
65 }
66
67 return metals.count(currency) == 1;
68}
69
70} // namespace QuantExt
Troy ounce of Silver.
Definition: metals.hpp:48
Troy ounce of Gold.
Definition: metals.hpp:39
Troy ounce of Palladium.
Definition: metals.hpp:66
Troy ounce of Platinum.
Definition: metals.hpp:57
Extend QuantLib currencies for precious metal codes.
bool isMetal(const Currency &currency)
Definition: metals.cpp:55