FinanceSim 0.1.0
Financial Simulation Library
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <memory>
5#include "core/time.hpp"
6
7namespace financesim {
8
10class Event {
11public:
12 virtual ~Event() = default;
13
15 virtual const char* type_name() const = 0;
16
18 SimTime timestamp() const { return timestamp_; }
19
21 const std::string& source_id() const { return source_id_; }
22
23protected:
26
27private:
29 std::string source_id_;
30};
31
32using EventPtr = std::shared_ptr<const Event>;
33
34// ============================================================================
35// Typed Events for Financial Models
36// ============================================================================
37
39class IncomeEvent : public Event {
40public:
42 double amount, std::string category,
43 std::string target_account = "")
44 : Event(timestamp, std::move(source_id))
46 , category_(std::move(category))
47 , target_account_(std::move(target_account)) {}
48
49 const char* type_name() const override { return "IncomeEvent"; }
50
51 double amount() const { return amount_; }
52 const std::string& category() const { return category_; }
53 const std::string& target_account() const { return target_account_; }
54
55private:
56 double amount_;
57 std::string category_;
58 std::string target_account_;
59};
60
62class ExpenseEvent : public Event {
63public:
65 double amount, std::string category,
66 std::string target_account = "")
67 : Event(timestamp, std::move(source_id))
69 , category_(std::move(category))
70 , target_account_(std::move(target_account)) {}
71
72 const char* type_name() const override { return "ExpenseEvent"; }
73
74 double amount() const { return amount_; }
75 const std::string& category() const { return category_; }
76 const std::string& target_account() const { return target_account_; }
77
78private:
79 double amount_;
80 std::string category_;
81 std::string target_account_;
82};
83
85class AssetEvent : public Event {
86public:
88 std::string asset_id, double value, double delta)
89 : Event(timestamp, std::move(source_id))
90 , asset_id_(std::move(asset_id))
91 , value_(value)
92 , delta_(delta) {}
93
94 const char* type_name() const override { return "AssetEvent"; }
95
96 const std::string& asset_id() const { return asset_id_; }
97 double value() const { return value_; }
98 double delta() const { return delta_; }
99
100private:
101 std::string asset_id_;
102 double value_;
103 double delta_;
104};
105
107class LiabilityEvent : public Event {
108public:
110 std::string liability_id, double value, double delta)
111 : Event(timestamp, std::move(source_id))
112 , liability_id_(std::move(liability_id))
113 , value_(value)
114 , delta_(delta) {}
115
116 const char* type_name() const override { return "LiabilityEvent"; }
117
118 const std::string& liability_id() const { return liability_id_; }
119 double value() const { return value_; }
120 double delta() const { return delta_; }
121
122private:
123 std::string liability_id_;
124 double value_;
125 double delta_;
126};
127
129class AccountEvent : public Event {
130public:
132 std::string account_id, double balance, double delta,
133 std::string reason)
134 : Event(timestamp, std::move(source_id))
135 , account_id_(std::move(account_id))
137 , delta_(delta)
138 , reason_(std::move(reason)) {}
139
140 const char* type_name() const override { return "AccountEvent"; }
141
142 const std::string& account_id() const { return account_id_; }
143 double balance() const { return balance_; }
144 double delta() const { return delta_; }
145 const std::string& reason() const { return reason_; }
146
147private:
148 std::string account_id_;
149 double balance_;
150 double delta_;
151 std::string reason_;
152};
153
155class TransferEvent : public Event {
156public:
158 std::string from_account, std::string to_account,
159 double amount, std::string reason)
160 : Event(timestamp, std::move(source_id))
161 , from_account_(std::move(from_account))
162 , to_account_(std::move(to_account))
163 , amount_(amount)
164 , reason_(std::move(reason)) {}
165
166 const char* type_name() const override { return "TransferEvent"; }
167
168 const std::string& from_account() const { return from_account_; }
169 const std::string& to_account() const { return to_account_; }
170 double amount() const { return amount_; }
171 const std::string& reason() const { return reason_; }
172
173private:
174 std::string from_account_;
175 std::string to_account_;
176 double amount_;
177 std::string reason_;
178};
179
180} // namespace financesim
Event emitted when an account balance changes.
Definition event.hpp:129
double delta() const
Definition event.hpp:144
std::string account_id_
Definition event.hpp:148
AccountEvent(SimTime timestamp, std::string source_id, std::string account_id, double balance, double delta, std::string reason)
Definition event.hpp:131
const char * type_name() const override
Returns the type name of this event (for debugging/logging)
Definition event.hpp:140
const std::string & reason() const
Definition event.hpp:145
double balance() const
Definition event.hpp:143
const std::string & account_id() const
Definition event.hpp:142
Event emitted when asset value changes.
Definition event.hpp:85
double delta() const
Definition event.hpp:98
std::string asset_id_
Definition event.hpp:101
AssetEvent(SimTime timestamp, std::string source_id, std::string asset_id, double value, double delta)
Definition event.hpp:87
double value() const
Definition event.hpp:97
const char * type_name() const override
Returns the type name of this event (for debugging/logging)
Definition event.hpp:94
const std::string & asset_id() const
Definition event.hpp:96
Base class for all typed events in the simulation.
Definition event.hpp:10
const std::string & source_id() const
Source model ID that generated this event.
Definition event.hpp:21
Event(SimTime timestamp, std::string source_id)
Definition event.hpp:24
SimTime timestamp_
Definition event.hpp:28
virtual const char * type_name() const =0
Returns the type name of this event (for debugging/logging)
std::string source_id_
Definition event.hpp:29
SimTime timestamp() const
Time at which this event was generated.
Definition event.hpp:18
virtual ~Event()=default
Event emitted when an expense occurs.
Definition event.hpp:62
ExpenseEvent(SimTime timestamp, std::string source_id, double amount, std::string category, std::string target_account="")
Definition event.hpp:64
const char * type_name() const override
Returns the type name of this event (for debugging/logging)
Definition event.hpp:72
double amount() const
Definition event.hpp:74
const std::string & category() const
Definition event.hpp:75
std::string category_
Definition event.hpp:80
std::string target_account_
Definition event.hpp:81
const std::string & target_account() const
Definition event.hpp:76
Event emitted when income is received.
Definition event.hpp:39
const std::string & target_account() const
Definition event.hpp:53
std::string category_
Definition event.hpp:57
const char * type_name() const override
Returns the type name of this event (for debugging/logging)
Definition event.hpp:49
const std::string & category() const
Definition event.hpp:52
std::string target_account_
Definition event.hpp:58
IncomeEvent(SimTime timestamp, std::string source_id, double amount, std::string category, std::string target_account="")
Definition event.hpp:41
double amount() const
Definition event.hpp:51
Event emitted when liability value changes.
Definition event.hpp:107
const char * type_name() const override
Returns the type name of this event (for debugging/logging)
Definition event.hpp:116
double delta() const
Definition event.hpp:120
double value() const
Definition event.hpp:119
LiabilityEvent(SimTime timestamp, std::string source_id, std::string liability_id, double value, double delta)
Definition event.hpp:109
std::string liability_id_
Definition event.hpp:123
const std::string & liability_id() const
Definition event.hpp:118
Event emitted when funds are transferred between accounts.
Definition event.hpp:155
TransferEvent(SimTime timestamp, std::string source_id, std::string from_account, std::string to_account, double amount, std::string reason)
Definition event.hpp:157
const std::string & reason() const
Definition event.hpp:171
const std::string & from_account() const
Definition event.hpp:168
const char * type_name() const override
Returns the type name of this event (for debugging/logging)
Definition event.hpp:166
const std::string & to_account() const
Definition event.hpp:169
double amount() const
Definition event.hpp:170
std::string to_account_
Definition event.hpp:175
std::string from_account_
Definition event.hpp:174
double SimTime
Represents a point in simulation time (continuous, in days)
Definition time.hpp:6
std::shared_ptr< const Event > EventPtr
Definition event.hpp:32