biweeklybudget.interest module

class biweeklybudget.interest.AdbCompoundedDaily(apr)[source]

Bases: biweeklybudget.interest._InterestCalculation

Average Daily Balance method, compounded daily (like American Express).

calculate(principal, first_d, last_d, transactions={})[source]

Calculate compound interest for the specified principal.

Parameters:
  • principal (decimal.Decimal) – balance at beginning of statement period
  • first_d (datetime.date) – date of beginning of statement period
  • last_d (datetime.date) – last date of statement period
  • transactions (dict) – dict of datetime.date to float amount adjust the balance by on the specified dates.
Returns:

dict describing the result: end_balance (float), interest_paid (float)

Return type:

dict

description = 'Average Daily Balance Compounded Daily (AmEx)'

Human-readable string name of the interest calculation type.

class biweeklybudget.interest.CCStatement(interest_cls, principal, min_payment_cls, billing_period, transactions={}, end_balance=None, interest_amt=None)[source]

Bases: object

Represent a credit card statement (one billing period).

apr
billing_period

Return the Billing Period for this statement.

Returns:billing period for this statement
Return type:_BillingPeriod
end_date
interest
minimum_payment

Return the minimum payment for the next billing cycle.

Returns:minimum payment for the next billing cycle
Return type:decimal.Decimal
next_with_transactions(transactions={})[source]

Return a new CCStatement reflecting the next billing period, with a payment of amount applied to it.

Parameters:transactions (dict) – dict of transactions, datetime.date to Decimal
Returns:next period statement, with transactions applied
Return type:CCStatement
pay(amount)[source]

Return a new CCStatement reflecting the next billing period, with a payment of amount applied to it at the middle of the period.

Parameters:amount (decimal.Decimal) – amount to pay during the next statement period
Returns:next period statement, with payment applied
Return type:CCStatement
principal
start_date
class biweeklybudget.interest.FixedPaymentMethod(max_total_payment=None, increases={}, onetimes={})[source]

Bases: biweeklybudget.interest._PayoffMethod

TESTING ONLY - pay the same amount on every statement.

description = 'TESTING ONLY - Fixed Payment for All Statements'
find_payments(statements)[source]

Given a list of statements, return a list of payment amounts to make on each of the statements.

Parameters:statements (list) – statements to pay, list of CCStatement
Returns:list of payment amounts to make, same order as statements
Return type:list
show_in_ui = False
class biweeklybudget.interest.HighestBalanceFirstMethod(max_total_payment=None, increases={}, onetimes={})[source]

Bases: biweeklybudget.interest._PayoffMethod

Pay statements off from highest to lowest balance.

description = 'Highest to Lowest Balance'
find_payments(statements)[source]

Given a list of statements, return a list of payment amounts to make on each of the statements.

Parameters:statements (list) – statements to pay, list of CCStatement
Returns:list of payment amounts to make, same order as statements
Return type:list
show_in_ui = True
class biweeklybudget.interest.HighestInterestRateFirstMethod(max_total_payment=None, increases={}, onetimes={})[source]

Bases: biweeklybudget.interest._PayoffMethod

Pay statements off from highest to lowest interest rate.

description = 'Highest to Lowest Interest Rate'
find_payments(statements)[source]

Given a list of statements, return a list of payment amounts to make on each of the statements.

Parameters:statements (list) – statements to pay, list of CCStatement
Returns:list of payment amounts to make, same order as statements
Return type:list
show_in_ui = True
biweeklybudget.interest.INTEREST_CALCULATION_NAMES = {'AdbCompoundedDaily': {'cls': <class 'biweeklybudget.interest.AdbCompoundedDaily'>, 'description': 'Average Daily Balance Compounded Daily (AmEx)', 'doc': 'Average Daily Balance method, compounded daily (like American Express).'}, 'SimpleInterest': {'cls': <class 'biweeklybudget.interest.SimpleInterest'>, 'description': 'Interest charged once on the balance at end of period.', 'doc': 'Simple interest, charged on balance at the end of the billing period.'}}

Dict mapping interest calculation class names to their description and docstring.

class biweeklybudget.interest.InterestHelper(db_sess, increases={}, onetimes={})[source]

Bases: object

_calc_payoff_method(cls)[source]

Calculate payoffs using one method.

Parameters:cls (biweeklybudget.interest._PayoffMethod) – payoff method class
Returns:Dict with integer account_id as the key, and values are dicts with keys “payoff_months” (int), “total_payments” (Decimal), “total_interest” (Decimal), “next_payment” (Decimal).
Return type:dict
_get_credit_accounts()[source]

Return a dict of account_id to Account for all Credit type accounts with OFX data present.

Returns:dict of account_id to Account instance
Return type:dict
_make_statements(accounts)[source]

Make CCStatement instances for each account; return a dict of account_id to CCStatement instance.

Parameters:accounts (dict) – dict of (int) account_id to Account instance
Returns:dict of (int) account_id to CCStatement instance
Return type:dict
accounts

Return a dict of account_id to Account for all Credit type accounts with OFX data present.

Returns:dict of account_id to Account instance
Return type:dict
calculate_payoffs()[source]

Calculate payoffs for each account/statement.

Returns:dict of payoff information. Keys are payoff method names. Values are dicts, with keys “description” (str description of the payoff method), “doc” (the docstring of the class), and “results”. The “results” dict has integer account_id as the key, and values are dicts with keys “payoff_months” (int), “total_payments” (Decimal), “total_interest” (Decimal) and next_payment (Decimal).
Return type:dict
min_payments

Return a dict of account_id to minimum payment for the latest statement, for each account.

Returns:dict of account_id to minimum payment (Decimal)
Return type:dict
class biweeklybudget.interest.LowestBalanceFirstMethod(max_total_payment=None, increases={}, onetimes={})[source]

Bases: biweeklybudget.interest._PayoffMethod

Pay statements off from lowest to highest balance, a.k.a. the “snowball” method.

description = 'Lowest to Highest Balance (a.k.a. Snowball Method)'
find_payments(statements)[source]

Given a list of statements, return a list of payment amounts to make on each of the statements.

Parameters:statements (list) – statements to pay, list of CCStatement
Returns:list of payment amounts to make, same order as statements
Return type:list
show_in_ui = True
class biweeklybudget.interest.LowestInterestRateFirstMethod(max_total_payment=None, increases={}, onetimes={})[source]

Bases: biweeklybudget.interest._PayoffMethod

Pay statements off from lowest to highest interest rate.

description = 'Lowest to Highest Interest Rate'
find_payments(statements)[source]

Given a list of statements, return a list of payment amounts to make on each of the statements.

Parameters:statements (list) – statements to pay, list of CCStatement
Returns:list of payment amounts to make, same order as statements
Return type:list
show_in_ui = True
biweeklybudget.interest.MIN_PAYMENT_FORMULA_NAMES = {'MinPaymentAmEx': {'cls': <class 'biweeklybudget.interest.MinPaymentAmEx'>, 'description': 'AmEx - Greatest of Interest Plus 1% of Principal, or $35', 'doc': 'Interest on last statement plus 1% of balance,\n or $35 if balance is less than $35.'}, 'MinPaymentCiti': {'cls': <class 'biweeklybudget.interest.MinPaymentCiti'>, 'description': 'Citi - Greatest of 1.5% of Principal, or 1% of Principal plus interest and fees, or $25, or Principal', 'doc': "Greater of:\n - $25;\n - The new balance, if it's less than $25;\n - 1 percent of the new balance, plus the current statement's interest\n charges or minimum interest charges, plus late fees;\n - 1.5% of the new balance, rounded to the nearest dollar amount.\n\n In all cases, add past fees and finance charges due, plus any amount in\n excess of credit line."}, 'MinPaymentDiscover': {'cls': <class 'biweeklybudget.interest.MinPaymentDiscover'>, 'description': 'Discover - Greatest of 2% of Principal, or $20 plus Interest, or $35', 'doc': 'Greater of:\n - $35; or\n - 2% of the New Balance shown on your billing statement; or\n - $20, plus any of the following charges as shown on your billing statement:\n fees for any debt protection product that you enrolled in on or after\n 2/1/2015; Interest Charges; and Late Fees.'}}

Dict mapping Minimum Payment Formula class names to their description and docstring.

class biweeklybudget.interest.MinPaymentAmEx[source]

Bases: biweeklybudget.interest._MinPaymentFormula

Interest on last statement plus 1% of balance, or $35 if balance is less than $35.

calculate(balance, interest)[source]

Calculate the minimum payment for a statement with the given balance and interest amount.

Parameters:
Returns:

minimum payment for the statement

Return type:

decimal.Decimal

description = 'AmEx - Greatest of Interest Plus 1% of Principal, or $35'

human-readable string description of the formula

class biweeklybudget.interest.MinPaymentCiti[source]

Bases: biweeklybudget.interest._MinPaymentFormula

Greater of: - $25; - The new balance, if it’s less than $25; - 1 percent of the new balance, plus the current statement’s interest charges or minimum interest charges, plus late fees; - 1.5% of the new balance, rounded to the nearest dollar amount.

In all cases, add past fees and finance charges due, plus any amount in excess of credit line.

calculate(balance, interest)[source]

Calculate the minimum payment for a statement with the given balance and interest amount.

Parameters:
Returns:

minimum payment for the statement

Return type:

decimal.Decimal

description = 'Citi - Greatest of 1.5% of Principal, or 1% of Principal plus interest and fees, or $25, or Principal'

human-readable string description of the formula

class biweeklybudget.interest.MinPaymentDiscover[source]

Bases: biweeklybudget.interest._MinPaymentFormula

Greater of: - $35; or - 2% of the New Balance shown on your billing statement; or - $20, plus any of the following charges as shown on your billing statement: fees for any debt protection product that you enrolled in on or after 2/1/2015; Interest Charges; and Late Fees.

calculate(balance, interest)[source]

Calculate the minimum payment for a statement with the given balance and interest amount.

Parameters:
Returns:

minimum payment for the statement

Return type:

decimal.Decimal

description = 'Discover - Greatest of 2% of Principal, or $20 plus Interest, or $35'

human-readable string description of the formula

class biweeklybudget.interest.MinPaymentMethod(max_total_payment=None, increases={}, onetimes={})[source]

Bases: biweeklybudget.interest._PayoffMethod

Pay only the minimum on each statement.

description = 'Minimum Payment Only'
find_payments(statements)[source]

Given a list of statements, return a list of payment amounts to make on each of the statements.

Parameters:statements (list) – statements to pay, list of CCStatement
Returns:list of payment amounts to make, same order as statements
Return type:list
show_in_ui = True
biweeklybudget.interest.PAYOFF_METHOD_NAMES = {'FixedPaymentMethod': {'cls': <class 'biweeklybudget.interest.FixedPaymentMethod'>, 'description': 'TESTING ONLY - Fixed Payment for All Statements', 'doc': 'TESTING ONLY - pay the same amount on every statement.'}, 'HighestBalanceFirstMethod': {'cls': <class 'biweeklybudget.interest.HighestBalanceFirstMethod'>, 'description': 'Highest to Lowest Balance', 'doc': 'Pay statements off from highest to lowest balance.'}, 'HighestInterestRateFirstMethod': {'cls': <class 'biweeklybudget.interest.HighestInterestRateFirstMethod'>, 'description': 'Highest to Lowest Interest Rate', 'doc': 'Pay statements off from highest to lowest interest rate.'}, 'LowestBalanceFirstMethod': {'cls': <class 'biweeklybudget.interest.LowestBalanceFirstMethod'>, 'description': 'Lowest to Highest Balance (a.k.a. Snowball Method)', 'doc': 'Pay statements off from lowest to highest balance, a.k.a. the "snowball"\n method.'}, 'LowestInterestRateFirstMethod': {'cls': <class 'biweeklybudget.interest.LowestInterestRateFirstMethod'>, 'description': 'Lowest to Highest Interest Rate', 'doc': 'Pay statements off from lowest to highest interest rate.'}, 'MinPaymentMethod': {'cls': <class 'biweeklybudget.interest.MinPaymentMethod'>, 'description': 'Minimum Payment Only', 'doc': 'Pay only the minimum on each statement.'}}

Dict mapping Payoff Method class names to their description and docstring.

class biweeklybudget.interest.SimpleInterest(apr)[source]

Bases: biweeklybudget.interest._InterestCalculation

Simple interest, charged on balance at the end of the billing period.

calculate(principal, first_d, last_d, transactions={})[source]

Calculate compound interest for the specified principal.

Parameters:
  • principal (decimal.Decimal) – balance at beginning of statement period
  • first_d (datetime.date) – date of beginning of statement period
  • last_d (datetime.date) – last date of statement period
  • transactions (dict) – dict of datetime.date to float amount adjust the balance by on the specified dates.
Returns:

dict describing the result: end_balance (float), interest_paid (float)

Return type:

dict

description = 'Interest charged once on the balance at end of period.'

Human-readable string name of the interest calculation type.

class biweeklybudget.interest._BillingPeriod(end_date, start_date=None)[source]

Bases: object

description = None

human-readable string description of the billing period type

end_date
next_period

Return the next billing period after this one.

Returns:next billing period
Return type:_BillingPeriod
payment_date
prev_period

Return the previous billing period before this one.

Returns:previous billing period
Return type:_BillingPeriod
start_date
class biweeklybudget.interest._InterestCalculation(apr)[source]

Bases: object

apr
calculate(principal, first_d, last_d, transactions={})[source]

Calculate compound interest for the specified principal.

Parameters:
  • principal (decimal.Decimal) – balance at beginning of statement period
  • first_d (datetime.date) – date of beginning of statement period
  • last_d (datetime.date) – last date of statement period
  • transactions (dict) – dict of datetime.date to float amount adjust the balance by on the specified dates.
Returns:

dict describing the result: end_balance (float), interest_paid (float)

Return type:

dict

description = None

Human-readable string name of the interest calculation type.

class biweeklybudget.interest._MinPaymentFormula[source]

Bases: object

calculate(balance, interest)[source]

Calculate the minimum payment for a statement with the given balance and interest amount.

Parameters:
Returns:

minimum payment for the statement

Return type:

decimal.Decimal

description = None

human-readable string description of the formula

class biweeklybudget.interest._PayoffMethod(max_total_payment=None, increases={}, onetimes={})[source]

Bases: object

A payoff method for multiple cards; a method of figuring out how much to pay on each card, each month.

description = None

human-readable string name of the payoff method

find_payments(statements)[source]

Given a list of statements, return a list of payment amounts to make on each of the statements.

Parameters:statements (list) – statements to pay, list of CCStatement
Returns:list of payment amounts to make, same order as statements
Return type:list
max_total_for_period(period)[source]

Given a _BillingPeriod, calculate the maximum total payment for that period, including both self._max_total and the increases and onetimes specified on the class constructor.

Parameters:period (_BillingPeriod) – billing period to get maximum total payment for
Returns:maximum total payment for the period
Return type:decimal.Decimal
biweeklybudget.interest.calculate_payoffs(payment_method, statements)[source]

Calculate the amount of time (in years) and total amount of money required to pay off the cards associated with the given list of statements. Return a list of (float number of years, decimal.Decimal amount paid, decimal.Decimal first payment amount) tuples for each item in statements.

Parameters:
  • payment_method (_PayoffMethod) – method used for calculating payment amount to make on each statement; subclass of _PayoffMethod
  • statements (list) – list of CCStatement objects to pay off.
Returns:

list of (float number of billing periods, decimal.Decimal amount paid, decimal.Decimal first payment amount) tuples for each item in statements

Return type:

list

biweeklybudget.interest.subclass_dict(klass)[source]