QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
catrisk.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) 2012, 2013 Grzegorz Andruszkiewicz
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
20/*! \file catrisk.hpp
21 \brief classes that encapsulate catastrophe risk
22*/
23
24#ifndef quantlib_catrisk_hpp
25#define quantlib_catrisk_hpp
26
27#include <ql/time/date.hpp>
28#include <ql/errors.hpp>
29#include <ql/shared_ptr.hpp>
30#include <random>
31#include <vector>
32
33namespace QuantLib {
34
36 public:
38 Date end)
39 : start_(start), end_(end)
40 {}
41
42 virtual ~CatSimulation() = default;
43 virtual bool nextPath(std::vector<std::pair<Date, Real> > &path) = 0;
44 protected:
47 };
48
49 class CatRisk {
50 public:
51 virtual ~CatRisk() = default;
52 virtual ext::shared_ptr<CatSimulation> newSimulation(const Date& start, const Date& end) const = 0;
53 };
54
56 public:
57 EventSetSimulation(ext::shared_ptr<std::vector<std::pair<Date, Real> > > events,
58 Date eventsStart,
59 Date eventsEnd,
60 Date start,
61 Date end);
62 bool nextPath(std::vector<std::pair<Date, Real> >& path) override;
63
64 private:
65 ext::shared_ptr<std::vector<std::pair<Date, Real> > > events_;
68
72 unsigned int i_ = 0;
73 };
74
75 class EventSet : public CatRisk {
76 public:
77 EventSet(ext::shared_ptr<std::vector<std::pair<Date, Real> > > events,
78 Date eventsStart,
79 Date eventsEnd);
80
81 ext::shared_ptr<CatSimulation> newSimulation(const Date& start,
82 const Date& end) const override;
83
84 private:
85 ext::shared_ptr<std::vector<std::pair<Date, Real> > > events_;
88 };
89
91 public:
93 Date end,
94 Real maxLoss,
95 Real lambda,
96 Real alpha,
97 Real beta) ;
98
99 bool nextPath(std::vector<std::pair<Date, Real> >& path) override;
101
102 private:
104
107
108 std::mt19937 rng_;
109 std::exponential_distribution<Real> exponential_;
110 std::gamma_distribution<Real> gammaAlpha_;
111 std::gamma_distribution<Real> gammaBeta_;
112 };
113
114 class BetaRisk : public CatRisk {
115 public:
116 BetaRisk(Real maxLoss,
117 Real years,
118 Real mean,
119 Real stdDev);
120
121 ext::shared_ptr<CatSimulation> newSimulation(const Date& start,
122 const Date& end) const override;
123
124 private:
129 };
130
131}
132
133#endif
ext::shared_ptr< CatSimulation > newSimulation(const Date &start, const Date &end) const override
Definition: catrisk.cpp:132
std::gamma_distribution< Real > gammaAlpha_
Definition: catrisk.hpp:110
std::exponential_distribution< Real > exponential_
Definition: catrisk.hpp:109
bool nextPath(std::vector< std::pair< Date, Real > > &path) override
Definition: catrisk.cpp:99
std::gamma_distribution< Real > gammaBeta_
Definition: catrisk.hpp:111
virtual ext::shared_ptr< CatSimulation > newSimulation(const Date &start, const Date &end) const =0
virtual ~CatRisk()=default
virtual ~CatSimulation()=default
virtual bool nextPath(std::vector< std::pair< Date, Real > > &path)=0
CatSimulation(Date start, Date end)
Definition: catrisk.hpp:37
Concrete date class.
Definition: date.hpp:125
ext::shared_ptr< std::vector< std::pair< Date, Real > > > events_
Definition: catrisk.hpp:85
ext::shared_ptr< CatSimulation > newSimulation(const Date &start, const Date &end) const override
Definition: catrisk.cpp:76
ext::shared_ptr< std::vector< std::pair< Date, Real > > > events_
Definition: catrisk.hpp:65
bool nextPath(std::vector< std::pair< Date, Real > > &path) override
Definition: catrisk.cpp:48
date- and time-related classes, typedefs and enumerations
Classes and functions for error handling.
Integer Year
Year number.
Definition: date.hpp:87
QL_REAL Real
real number
Definition: types.hpp:50
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Definition: any.hpp:35
Real years(const Period &p)
Definition: period.cpp:279
Real beta
Definition: sabr.cpp:200
Real alpha
Definition: sabr.cpp:200
Maps shared_ptr to either the boost or std implementation.