Skip to content

Commit

Permalink
[Enh]: Compounding Formula
Browse files Browse the repository at this point in the history
For e.g. interest or inflation
  • Loading branch information
seandenigris committed Sep 10, 2024
1 parent aa7cf30 commit a5b0d17
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
60 changes: 60 additions & 0 deletions source/Aconcagua-Core/CompoundingFormula.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Class {
#name : #CompoundingFormula,
#superclass : #Object,
#instVars : [
'presentValue',
'nominalRate',
'timeUnits',
'periods'
],
#category : #'Aconcagua-Core-MeasureModel'
}

{ #category : #calculating }
CompoundingFormula >> calculate [

| exponent parenthesized |
exponent := self periods * self timeUnits.
parenthesized := 1 + (self nominalRate / self periods).
^ self presentValue * (parenthesized raisedTo: exponent)
]

{ #category : #accessing }
CompoundingFormula >> nominalRate [
^ nominalRate
]

{ #category : #accessing }
CompoundingFormula >> nominalRate: anObject [
nominalRate := anObject
]

{ #category : #accessing }
CompoundingFormula >> periods [
^ periods ifNil: [ 1 ]
]

{ #category : #accessing }
CompoundingFormula >> periods: anObject [
periods := anObject
]

{ #category : #accessing }
CompoundingFormula >> presentValue [
^ presentValue
]

{ #category : #accessing }
CompoundingFormula >> presentValue: anObject [
presentValue := anObject
]

{ #category : #accessing }
CompoundingFormula >> timeUnits [
^ timeUnits
]

{ #category : #accessing }
CompoundingFormula >> timeUnits: anObject [
timeUnits := anObject
]
10 changes: 9 additions & 1 deletion source/Aconcagua-Core/Measure.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,15 @@ Measure >> compareGreaterThan: aNumber [

]

{ #category : 'converting' }
{ #category : #compounding }
Measure >> compoundingFormula [

^ CompoundingFormula new
presentValue: self;
yourself
]

{ #category : #converting }
Measure >> convertAmountToBaseUnit [

^self unit convertAmountToBaseUnit: self amount
Expand Down

0 comments on commit a5b0d17

Please sign in to comment.