Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
analyticfactory.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2024 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 orea/app/analytics/analyticsfactory.hpp
20 \brief Analytics Factory
21 \ingroup analytics
22*/
23
24#pragma once
25
26#include <map>
27#include <ql/patterns/singleton.hpp>
28
29#include <boost/make_shared.hpp>
30#include <boost/thread/lock_types.hpp>
31#include <boost/thread/shared_mutex.hpp>
32
34
35namespace ore {
36namespace analytics {
37
38class Analytic;
39
40//! TradeBuilder base class
41/*! All derived classes have to be stateless. It should not be necessary to derive classes
42 other than TradeBuilder from this class anyway.
43
44 \ingroup portfolio
45*/
47public:
49 virtual QuantLib::ext::shared_ptr<Analytic>
50 build(const QuantLib::ext::shared_ptr<ore::analytics::InputParameters>& inputs) const = 0;
51};
52
53//! Template AnalyticBuilder class
54/*!
55 \ingroup analytics
56*/
57template <class T> class AnalyticBuilder : public AbstractAnalyticBuilder {
58public:
59 virtual QuantLib::ext::shared_ptr<Analytic>
60 build(const QuantLib::ext::shared_ptr<ore::analytics::InputParameters>& inputs) const override {
61 return QuantLib::ext::make_shared<T>(inputs);
62 }
63};
64
65//! AnalyticFactory
66/*!
67 \ingroup analytics
68*/
69class AnalyticFactory : public QuantLib::Singleton<AnalyticFactory, std::integral_constant<bool, true>> {
70 std::map<std::string, std::pair<std::set<std::string>, QuantLib::ext::shared_ptr<AbstractAnalyticBuilder>>>
72 mutable boost::shared_mutex mutex_;
73
74public:
75 std::map<std::string,
76 std::pair<std::set<std::string>, QuantLib::ext::shared_ptr<AbstractAnalyticBuilder>>> getBuilders() const;
77 std::pair < std::string,
78 QuantLib::ext::shared_ptr<AbstractAnalyticBuilder>> getBuilder(const std::string& analyticType) const;
79 void addBuilder(const std::string& className, const std::set<std::string>& subAnalytics,
80 const QuantLib::ext::shared_ptr<AbstractAnalyticBuilder>& builder,
81 const bool allowOverwrite = false);
82
83 //! Build, throws for unknown className
84 std::pair<std::string, QuantLib::ext::shared_ptr<Analytic>> build(const std::string& subAnalytic,
85 const QuantLib::ext::shared_ptr<ore::analytics::InputParameters>& inputs) const;
86};
87
88} // namespace analytics
89} // namespace ore
virtual QuantLib::ext::shared_ptr< Analytic > build(const QuantLib::ext::shared_ptr< ore::analytics::InputParameters > &inputs) const =0
Template AnalyticBuilder class.
virtual QuantLib::ext::shared_ptr< Analytic > build(const QuantLib::ext::shared_ptr< ore::analytics::InputParameters > &inputs) const override
std::pair< std::string, QuantLib::ext::shared_ptr< AbstractAnalyticBuilder > > getBuilder(const std::string &analyticType) const
std::map< std::string, std::pair< std::set< std::string >, QuantLib::ext::shared_ptr< AbstractAnalyticBuilder > > > getBuilders() const
void addBuilder(const std::string &className, const std::set< std::string > &subAnalytics, const QuantLib::ext::shared_ptr< AbstractAnalyticBuilder > &builder, const bool allowOverwrite=false)
std::map< std::string, std::pair< std::set< std::string >, QuantLib::ext::shared_ptr< AbstractAnalyticBuilder > > > builders_
std::pair< std::string, QuantLib::ext::shared_ptr< Analytic > > build(const std::string &subAnalytic, const QuantLib::ext::shared_ptr< ore::analytics::InputParameters > &inputs) const
Build, throws for unknown className.
Input Parameters.