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

Savings account - earns APY interest, compounded monthly. More...

#include <savings_account.hpp>

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

Public Member Functions

 SavingsAccount (std::string id, std::string name, double apy, double initial_balance=0.0, std::string routing_tag="savings", Schedule schedule=make_savings_schedule())
 
 ~SavingsAccount () override=default
 
double apy () const
 Get the APY (annual percentage yield)
 
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::AccountBase
 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.
 
- Public Member Functions inherited from financesim::Model
virtual ~Model ()=default
 

Protected Member Functions

void on_income (const IncomeEvent &event) override
 Called when an income event is routed to this account.
 
void on_expense (const ExpenseEvent &event) override
 Called when an expense event is routed to this account.
 
- Protected Member Functions inherited from financesim::AccountBase
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.
 
template<typename EventType , typename... Args>
void emit (SimTime time, Args &&... args)
 
- Protected Member Functions inherited from financesim::Model
 Model ()=default
 

Private Member Functions

void accrue_interest_up_to (SimTime time)
 

Private Attributes

double apy_
 
SimTime last_interest_time_ = 0.0
 

Detailed Description

Savings account - earns APY interest, compounded monthly.

Definition at line 15 of file savings_account.hpp.

Constructor & Destructor Documentation

◆ SavingsAccount()

financesim::SavingsAccount::SavingsAccount ( std::string  id,
std::string  name,
double  apy,
double  initial_balance = 0.0,
std::string  routing_tag = "savings",
Schedule  schedule = make_savings_schedule() 
)

Create a savings account

Parameters
idUnique identifier
nameHuman-readable name
apyAnnual Percentage Yield (e.g., 0.05 for 5%)
initial_balanceStarting balance
routing_tagTag for routing events (defaults to "savings")
scheduleExecution schedule (default: monthly updates for interest)

Definition at line 6 of file savings_account.cpp.

◆ ~SavingsAccount()

financesim::SavingsAccount::~SavingsAccount ( )
overridedefault

Member Function Documentation

◆ accrue_interest_up_to()

void financesim::SavingsAccount::accrue_interest_up_to ( SimTime  time)
private

Definition at line 53 of file savings_account.cpp.

References apy_, financesim::AccountBase::balance(), financesim::AccountBase::deposit(), financesim::AccountBase::emit(), and last_interest_time_.

Referenced by on_expense(), on_income(), and update().

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

◆ apy()

double financesim::SavingsAccount::apy ( ) const
inline

Get the APY (annual percentage yield)

Definition at line 32 of file savings_account.hpp.

References apy_.

Referenced by PYBIND11_MODULE().

Here is the caller graph for this function:

◆ finalize()

void financesim::SavingsAccount::finalize ( )
overridevirtual

Called once after simulation ends Use for cleanup, final calculations, releasing resources

Reimplemented from financesim::AccountBase.

Definition at line 29 of file savings_account.cpp.

References financesim::AccountBase::finalize().

Here is the call graph for this function:

◆ initialize()

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

Called once before simulation starts Use for setup, subscribing to events, allocating resources

Reimplemented from financesim::AccountBase.

Definition at line 18 of file savings_account.cpp.

References financesim::AccountBase::bus(), and financesim::AccountBase::initialize().

Here is the call graph for this function:

◆ on_expense()

void financesim::SavingsAccount::on_expense ( const ExpenseEvent event)
overrideprotectedvirtual

Called when an expense event is routed to this account.

Reimplemented from financesim::AccountBase.

Definition at line 47 of file savings_account.cpp.

References accrue_interest_up_to(), financesim::AccountBase::emit(), and financesim::AccountBase::on_expense().

Here is the call graph for this function:

◆ on_income()

void financesim::SavingsAccount::on_income ( const IncomeEvent event)
overrideprotectedvirtual

Called when an income event is routed to this account.

Reimplemented from financesim::AccountBase.

Definition at line 41 of file savings_account.cpp.

References accrue_interest_up_to(), financesim::AccountBase::emit(), and financesim::AccountBase::on_income().

Here is the call graph for this function:

◆ reset()

void financesim::SavingsAccount::reset ( )
overridevirtual

Reset model to initial state (for replay)

Reimplemented from financesim::AccountBase.

Definition at line 36 of file savings_account.cpp.

References last_interest_time_, and financesim::AccountBase::reset().

Here is the call graph for this function:

◆ update()

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

Called at each scheduled execution time Must be deterministic given the same inputs and time

Reimplemented from financesim::AccountBase.

Definition at line 23 of file savings_account.cpp.

References accrue_interest_up_to(), and financesim::AccountBase::emit().

Here is the call graph for this function:

Member Data Documentation

◆ apy_

double financesim::SavingsAccount::apy_
private

Definition at line 46 of file savings_account.hpp.

Referenced by accrue_interest_up_to(), and apy().

◆ last_interest_time_

SimTime financesim::SavingsAccount::last_interest_time_ = 0.0
private

Definition at line 47 of file savings_account.hpp.

Referenced by accrue_interest_up_to(), and reset().


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