FinanceSim 0.1.0
Financial Simulation Library
Loading...
Searching...
No Matches
financesim::AccountBase Class Reference

#include <account_base.hpp>

Inheritance diagram for financesim::AccountBase:
[legend]
Collaboration diagram for financesim::AccountBase:
[legend]

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 Scheduleschedule () 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

EventBusbus ()
 
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_
 
EventBusbus_ = nullptr
 
SubscriptionId income_sub_ = 0
 
SubscriptionId expense_sub_ = 0
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ AccountBase()

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.

◆ ~AccountBase()

virtual financesim::AccountBase::~AccountBase ( )
virtualdefault

Member Function Documentation

◆ balance()

double financesim::AccountBase::balance ( ) const
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().

Here is the caller graph for this function:

◆ bus()

EventBus & financesim::AccountBase::bus ( )
inlineprotected

Definition at line 40 of file account_base.hpp.

References bus_.

Referenced by initialize(), and financesim::SavingsAccount::initialize().

Here is the caller graph for this function:

◆ deposit()

void financesim::AccountBase::deposit ( SimTime  time,
double  amount,
const std::string &  reason 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit()

template<typename EventType , typename... Args>
void financesim::AccountBase::emit ( SimTime  time,
Args &&...  args 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finalize()

void financesim::AccountBase::finalize ( )
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().

Here is the caller graph for this function:

◆ id()

const std::string & financesim::AccountBase::id ( ) const
inlineoverridevirtual

Unique identifier for this model instance.

Implements financesim::Model.

Definition at line 24 of file account_base.hpp.

References id_.

◆ initialize()

void financesim::AccountBase::initialize ( EventBus bus)
overridevirtual

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

const std::string & financesim::AccountBase::name ( ) const
inlineoverridevirtual

Human-readable name/description.

Implements financesim::Model.

Definition at line 25 of file account_base.hpp.

References name_.

◆ on_expense()

void financesim::AccountBase::on_expense ( const ExpenseEvent event)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_income()

void financesim::AccountBase::on_income ( const IncomeEvent event)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void financesim::AccountBase::reset ( )
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ routing_tag()

const std::string & financesim::AccountBase::routing_tag ( ) const
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().

Here is the caller graph for this function:

◆ schedule()

const Schedule & financesim::AccountBase::schedule ( ) const
inlineoverridevirtual

Get the model's execution schedule.

Implements financesim::Model.

Definition at line 26 of file account_base.hpp.

References schedule_.

◆ should_handle_event()

bool financesim::AccountBase::should_handle_event ( const std::string &  target_account) const
private

Definition at line 58 of file account_base.cpp.

References routing_tag_.

Referenced by initialize().

Here is the caller graph for this function:

◆ update()

void financesim::AccountBase::update ( SimTime  time)
overridevirtual

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.

◆ withdraw()

void financesim::AccountBase::withdraw ( SimTime  time,
double  amount,
const std::string &  reason 
)
protected

Withdraw funds from the account.

Definition at line 73 of file account_base.cpp.

References balance_, emit(), and id_.

Referenced by on_expense().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ balance_

double financesim::AccountBase::balance_
private

Definition at line 69 of file account_base.hpp.

Referenced by balance(), deposit(), reset(), and withdraw().

◆ bus_

EventBus* financesim::AccountBase::bus_ = nullptr
private

Definition at line 72 of file account_base.hpp.

Referenced by bus(), emit(), initialize(), and reset().

◆ expense_sub_

SubscriptionId financesim::AccountBase::expense_sub_ = 0
private

Definition at line 74 of file account_base.hpp.

Referenced by initialize(), and reset().

◆ id_

std::string financesim::AccountBase::id_
private

Definition at line 66 of file account_base.hpp.

Referenced by deposit(), emit(), id(), and withdraw().

◆ income_sub_

SubscriptionId financesim::AccountBase::income_sub_ = 0
private

Definition at line 73 of file account_base.hpp.

Referenced by initialize(), and reset().

◆ initial_balance_

double financesim::AccountBase::initial_balance_
private

Definition at line 70 of file account_base.hpp.

Referenced by reset().

◆ name_

std::string financesim::AccountBase::name_
private

Definition at line 67 of file account_base.hpp.

Referenced by name().

◆ routing_tag_

std::string financesim::AccountBase::routing_tag_
private

Definition at line 68 of file account_base.hpp.

Referenced by routing_tag(), and should_handle_event().

◆ schedule_

Schedule financesim::AccountBase::schedule_
private

Definition at line 71 of file account_base.hpp.

Referenced by schedule().


The documentation for this class was generated from the following files: