|
FinanceSim 0.1.0
Financial Simulation Library
|
#include <account_base.hpp>
Public Member Functions | |
| AccountBase (std::string id, std::string name, std::string routing_tag, double initial_balance=0.0, Schedule schedule=make_account_schedule()) | |
| virtual | ~AccountBase ()=default |
| const std::string & | id () const override |
| Unique identifier for this model instance. | |
| const std::string & | name () const override |
| Human-readable name/description. | |
| const Schedule & | schedule () const override |
| Get the model's execution schedule. | |
| const std::string & | routing_tag () const |
| Get the routing tag used to match income/expense events. | |
| double | balance () const |
| Get current balance. | |
| void | initialize (EventBus &bus) override |
| void | update (SimTime time) override |
| void | finalize () override |
| void | reset () override |
| Reset model to initial state (for replay) | |
Public Member Functions inherited from financesim::Model | |
| virtual | ~Model ()=default |
Protected Member Functions | |
| EventBus & | bus () |
| void | deposit (SimTime time, double amount, const std::string &reason) |
| Deposit funds into the account. | |
| void | withdraw (SimTime time, double amount, const std::string &reason) |
| Withdraw funds from the account. | |
| virtual void | on_income (const IncomeEvent &event) |
| Called when an income event is routed to this account. | |
| virtual void | on_expense (const ExpenseEvent &event) |
| Called when an expense event is routed to this account. | |
| template<typename EventType , typename... Args> | |
| void | emit (SimTime time, Args &&... args) |
Protected Member Functions inherited from financesim::Model | |
| Model ()=default | |
Private Member Functions | |
| bool | should_handle_event (const std::string &target_account) const |
Private Attributes | |
| std::string | id_ |
| std::string | name_ |
| std::string | routing_tag_ |
| double | balance_ |
| double | initial_balance_ |
| Schedule | schedule_ |
| EventBus * | bus_ = nullptr |
| SubscriptionId | income_sub_ = 0 |
| SubscriptionId | expense_sub_ = 0 |
Base class for account models (checking, savings, etc.) Accounts subscribe to IncomeEvent and ExpenseEvent and route based on target_account
Definition at line 17 of file account_base.hpp.
| financesim::AccountBase::AccountBase | ( | std::string | id, |
| std::string | name, | ||
| std::string | routing_tag, | ||
| double | initial_balance = 0.0, |
||
| Schedule | schedule = make_account_schedule() |
||
| ) |
Definition at line 5 of file account_base.cpp.
|
virtualdefault |
|
inline |
Get current balance.
Definition at line 32 of file account_base.hpp.
References balance_.
Referenced by financesim::SavingsAccount::accrue_interest_up_to(), and PYBIND11_MODULE().
|
inlineprotected |
Definition at line 40 of file account_base.hpp.
References bus_.
Referenced by initialize(), and financesim::SavingsAccount::initialize().
|
protected |
Deposit funds into the account.
Definition at line 67 of file account_base.cpp.
References balance_, emit(), and id_.
Referenced by financesim::SavingsAccount::accrue_interest_up_to(), and on_income().
|
inlineprotected |
Definition at line 55 of file account_base.hpp.
References bus_, emit(), id_, and financesim::EventBus::publish().
Referenced by financesim::SavingsAccount::accrue_interest_up_to(), deposit(), emit(), on_expense(), financesim::SavingsAccount::on_expense(), on_income(), financesim::SavingsAccount::on_income(), financesim::SavingsAccount::update(), and withdraw().
|
overridevirtual |
Called once after simulation ends Use for cleanup, final calculations, releasing resources
Implements financesim::Model.
Reimplemented in financesim::SavingsAccount.
Definition at line 43 of file account_base.cpp.
Referenced by financesim::SavingsAccount::finalize().
|
inlineoverridevirtual |
Unique identifier for this model instance.
Implements financesim::Model.
Definition at line 24 of file account_base.hpp.
References id_.
Called once before simulation starts Use for setup, subscribing to events, allocating resources
Implements financesim::Model.
Reimplemented in financesim::SavingsAccount.
Definition at line 16 of file account_base.cpp.
References bus(), bus_, expense_sub_, income_sub_, on_expense(), on_income(), should_handle_event(), and financesim::EventBus::subscribe().
Referenced by financesim::SavingsAccount::initialize().
|
inlineoverridevirtual |
Human-readable name/description.
Implements financesim::Model.
Definition at line 25 of file account_base.hpp.
References name_.
|
protectedvirtual |
Called when an expense event is routed to this account.
Reimplemented in financesim::SavingsAccount.
Definition at line 83 of file account_base.cpp.
References emit(), and withdraw().
Referenced by initialize(), and financesim::SavingsAccount::on_expense().
|
protectedvirtual |
Called when an income event is routed to this account.
Reimplemented in financesim::SavingsAccount.
Definition at line 79 of file account_base.cpp.
References deposit(), and emit().
Referenced by initialize(), and financesim::SavingsAccount::on_income().
|
overridevirtual |
Reset model to initial state (for replay)
Implements financesim::Model.
Reimplemented in financesim::SavingsAccount.
Definition at line 47 of file account_base.cpp.
References balance_, bus_, expense_sub_, income_sub_, initial_balance_, and financesim::EventBus::unsubscribe().
Referenced by financesim::SavingsAccount::reset().
|
inline |
Get the routing tag used to match income/expense events.
Definition at line 29 of file account_base.hpp.
References routing_tag_.
Referenced by PYBIND11_MODULE().
Get the model's execution schedule.
Implements financesim::Model.
Definition at line 26 of file account_base.hpp.
References schedule_.
|
private |
Definition at line 58 of file account_base.cpp.
References routing_tag_.
Referenced by initialize().
Called at each scheduled execution time Must be deterministic given the same inputs and time
Implements financesim::Model.
Reimplemented in financesim::SavingsAccount.
Definition at line 38 of file account_base.cpp.
|
protected |
Withdraw funds from the account.
Definition at line 73 of file account_base.cpp.
References balance_, emit(), and id_.
Referenced by on_expense().
|
private |
Definition at line 69 of file account_base.hpp.
Referenced by balance(), deposit(), reset(), and withdraw().
Definition at line 72 of file account_base.hpp.
Referenced by bus(), emit(), initialize(), and reset().
|
private |
Definition at line 74 of file account_base.hpp.
Referenced by initialize(), and reset().
|
private |
Definition at line 66 of file account_base.hpp.
Referenced by deposit(), emit(), id(), and withdraw().
|
private |
Definition at line 73 of file account_base.hpp.
Referenced by initialize(), and reset().
|
private |
Definition at line 70 of file account_base.hpp.
Referenced by reset().
|
private |
Definition at line 67 of file account_base.hpp.
Referenced by name().
|
private |
Definition at line 68 of file account_base.hpp.
Referenced by routing_tag(), and should_handle_event().
|
private |
Definition at line 71 of file account_base.hpp.
Referenced by schedule().