Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions rosetta-source/src/main/rosetta/base-math-func.rosetta
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,28 @@ func UpdateAmount: <"Updates an amount based on the given QuantityChangeDirectio
Decrease then oldAmount - changeAmount,
Replace then changeAmount

func UpdateDatedValues: <"Updates the amounts of the dated values based on the given QuantityChangeDirectionEnum. For all periods after the effective date of the change, if the direction is Increase, the old amount and change amount are summed, if the direction is Decrease, then the change amount is subtracted from the old amount, and if the direction is Replace then the change amount replaces the old amount.">
inputs:
datedValues DatedValue (0..*)
changeAmount number (0..1)
direction QuantityChangeDirectionEnum (1..1)
effectiveDate date (0..1)
output:
newdatedValues DatedValue (0..*)

add newdatedValues:
datedValues
extract
DatedValue {
date: item -> date,
value:
if item -> date >= effectiveDate then (
if direction = QuantityChangeDirectionEnum -> Increase then item -> value + changeAmount
else if direction = QuantityChangeDirectionEnum -> Decrease then item -> value - changeAmount
else if direction = QuantityChangeDirectionEnum -> Replace then changeAmount)
else item -> value
}

func FilterQuantity: <"Filter list of quantities based on unit type.">
inputs:
quantities Quantity (0..*) <"List of quantities to filter.">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version "${project.version}"

import cdm.base.math.*
import cdm.observable.asset.*
import cdm.margin.schedule.*

func UpdateAmountForEachMatchingQuantity: <"Updates any price or quantity from the list of PriceQuantity if the unit of amount matches.">
inputs:
Expand All @@ -27,7 +28,8 @@ func UpdateAmountForEachMatchingQuantity: <"Updates any price or quantity from t
extract
UpdateQuantityAmountForEachMatchingQuantity(
item,
change -> quantity, // FilterChangePriceQuantity(priceQuantity, change) -> quantity,
change, // FilterChangePriceQuantity(priceQuantity, change),
// PriceQuantity used as input to keep the quantity and effectiveDate linked
direction
),
observable: priceQuantity -> observable,
Expand Down Expand Up @@ -76,20 +78,31 @@ func UpdateQuantityAmountForEachMatchingQuantity: <"Updates any quantity from th
inputs:
quantity NonNegativeQuantitySchedule (0..1) <"List of NonNegativeQuantitySchedule to update.">
[metadata location]
change NonNegativeQuantitySchedule (0..*) <"List of new NonNegativeQuantitySchedule to use where the units match.">
change PriceQuantity (0..*) <"List of new PriceQuantity to use where the units match."> // PriceQuantity defined as input to keep the quantity and effectiveDate linked
direction QuantityChangeDirectionEnum (1..1) <"Enum specifying how the updated amounts should be applied, e.g., add, subtract or replace.">
output:
updatedQuantity NonNegativeQuantitySchedule (0..1)
[metadata location]

alias changedAmount:
alias changeMatching:
change
filter UnitEquals(item -> unit, quantity -> unit)
filter UnitEquals(item -> quantity then first -> unit, quantity -> unit)
then first
then extract UpdateAmount(quantity -> value, value, direction)

alias changedAmount:
UpdateAmount(quantity -> value, changeMatching -> quantity only-element -> value, direction)

alias changeEffectiveDate:
AdjustableDateResolution(changeMatching -> effectiveDate -> adjustableDate)
//ResolveAdjustableDate(changeMatching -> effectiveDate)
// TODO uncomment usage once function is available

alias changedDatedValue:
UpdateDatedValues(quantity -> datedValue, changeMatching -> quantity only-element -> value, direction, changeEffectiveDate)

set updatedQuantity: quantity
set updatedQuantity -> value: changedAmount default quantity -> value
set updatedQuantity -> datedValue : changedDatedValue default quantity -> datedValue

func PriceUnitEquals: <"Compares two PriceSchedule to check if all attributes match, except for the amount.">
inputs:
Expand Down
Loading