Values that are allowed to be returned by parameter shape:
NumberShape: Decimal or int, StringShape: str, AccountIdShape: str, DenominationShape: str, DateShape: datetime, OptionalShape: OptionalValue, UnionShape: UnionItemValue with key in the set of valid keys of the UnionShape
xxxxxxxxxx
api = "3.12.0"
version = "1.0.0"
PercentageShape = NumberShape(
kind=NumberKind.PERCENTAGE, min_value=0.0, max_value=1.0, step=0.0000001
)
parameters = [
Parameter(
name="interest_rate",
description="Product Interest Rate",
display_name="Interest Rate",
level=Level.TEMPLATE,
shape=PercentageShape,
),
Parameter(
name="mad",
description="Minimum Amount Due",
display_name="Minimum Amount Due",
level=Level.INSTANCE,
shape=NumberShape(
kind=NumberKind.MONEY,
),
derived=True,
),
Parameter(
name="aer",
description="Annual Equivalent Rate",
display_name="Annual Equivalent Rate",
level=Level.INSTANCE,
shape=OptionalShape(PercentageShape),
derived=True,
),
]
@requires(parameters=True, balances="1 days")
def derived_parameters(effective_date):
balances = vault.get_balance_timeseries().at(date=effective_date)
interest_rate = vault.get_parameter_timeseries(name="interest_rate").at(date=effective_date)
return {
"mad": _calculate_mad(balances, interest_rate),
"aer": OptionalValue(_calculate_aer(interest_rate)),
}
def _calculate_aer(interest_rate):
# Assuming monthly interest payments - n = 12
return _round(Decimal(math.pow((1 + interest_rate / 12), 12) - 1), decimal_places=4)
def _calculate_mad(balances, interest_rate):
main_balance = balances[((DEFAULT_ADDRESS, DEFAULT_ASSET, "GBP", Phase.COMMITTED))].net
mad = interest_rate * main_balance
return _round(mad)
def _round(number, decimal_places=2):
return number.copy_abs().quantize(Decimal((0, (1,), -decimal_places)), rounding=ROUND_FLOOR)
Derived parameters: Executed when a request is made for the account’s derived parameters.