Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fixings.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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
19/*! \file ored/marketdata/loader.hpp
20 \brief Market Datum Loader Interface
21 \ingroup
22*/
23
24#include <boost/timer/timer.hpp>
28#include <ql/index.hpp>
31
32using boost::timer::cpu_timer;
33using boost::timer::default_places;
34using namespace std;
35using namespace QuantLib;
36using namespace QuantExt;
37
38namespace ore {
39namespace data {
40
41void applyFixings(const set<Fixing>& fixings) {
42
43 QuantExt::SavedObservableSettings savedObservableSettings;
44 ObservableSettings::instance().disableUpdates(true);
45
46 Size count = 0;
47 cpu_timer timer;
48 QuantLib::ext::shared_ptr<Index> index;
49 std::string lastIndexName;
50 for (auto& f : fixings) {
51 if(f.name.empty()) {
52 WLOG("Skipping fixing with empty name, value " << f.fixing << ", date " << f.date);
53 }
54 try {
55 if (lastIndexName != f.name) {
56 index = parseIndex(f.name);
57 lastIndexName = f.name;
58 }
59 index->addFixing(f.date, f.fixing, true);
60 TLOG("Added fixing for " << f.name << " (" << io::iso_date(f.date) << ") value:" << f.fixing);
61 ++count;
62 } catch (const std::exception& e) {
63 WLOG("Error during adding fixing for " << f.name << ": " << e.what());
64 }
65 }
66 timer.stop();
67 LOG("Added " << count << " of " << fixings.size() << " fixings in " << timer.format(default_places, "%w")
68 << " seconds");
69}
70
71bool operator<(const Fixing& f1, const Fixing& f2) {
72 if (f1.name != f2.name)
73 return f1.name < f2.name;
74 return f1.date < f2.date;
75}
76
77} // namespace data
78} // namespace ore
QuantLib::ext::shared_ptr< Index > parseIndex(const string &s)
Convert std::string to QuantLib::Index.
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
#define LOG(text)
Logging Macro (Level = Notice)
Definition: log.hpp:552
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
#define TLOG(text)
Logging Macro (Level = Data)
Definition: log.hpp:556
bool operator<(const Dividend &d1, const Dividend &d2)
void applyFixings(const set< Fixing > &fixings)
Utility to write a vector of fixings in the QuantLib index manager's fixing history.
Definition: fixings.cpp:41
Serializable Credit Default Swap.
Definition: namespaces.docs:23
std::size_t count
Fixing data structure.
Definition: fixings.hpp:44
std::string name
Index name.
Definition: fixings.hpp:48
QuantLib::Date date
Fixing date.
Definition: fixings.hpp:46