From a1ac8378eb4f5f3ba7d8dcb62503bb4c60c778c4 Mon Sep 17 00:00:00 2001 From: zeroflag Date: Thu, 14 Oct 2021 14:04:59 +0200 Subject: [PATCH] cagr, pmt, ggm --- src/main/res/raw/misc.forth | 1 + src/main/res/raw/ops.forth | 2 ++ src/test/java/com/vectron/fcl/FclTest.java | 3 +++ 3 files changed, 6 insertions(+) diff --git a/src/main/res/raw/misc.forth b/src/main/res/raw/misc.forth index b5b9f87..b108b76 100644 --- a/src/main/res/raw/misc.forth +++ b/src/main/res/raw/misc.forth @@ -50,6 +50,7 @@ var: irr-guess 0 irr-guess ! nil ; : irr* ( cashflow -- n ) >list* irr ; +: pmt -> n 100 / -> r -> p p 1 1 1 r + n pow / - r / / ; var: juggler.steps 5 juggler.steps ! [ ] val: juggler.exclude diff --git a/src/main/res/raw/ops.forth b/src/main/res/raw/ops.forth index d7ae5b3..20c8080 100644 --- a/src/main/res/raw/ops.forth +++ b/src/main/res/raw/ops.forth @@ -25,6 +25,8 @@ : tip2 ( bill split -- total tip ) / dup 115 percent swap 15 percent ; : fire ( monthly-expense real-interest-rate -- money-needed ) 100 / swap 12 * swap / ; : ri ( nominal-interest-rate inflation-rate -- real-interest-rate ) 100 / 1+ swap 100 / 1+ swap / 1- 100 * ; +: cagr ( bv ev n -- p ) 1 swap / >r swap / r> pow 1- 100 * ; +: ggm ( cf r g -- pvg ) 100 / swap 100 / swap - / ; ( trigonometry ) : pi ( n -- n ) :java.lang.Math/PI jvm-static-var ; : sin ( n -- n ) :java.lang.Math/sin/d jvm-call-static ; diff --git a/src/test/java/com/vectron/fcl/FclTest.java b/src/test/java/com/vectron/fcl/FclTest.java index 681cbe0..db55a3c 100644 --- a/src/test/java/com/vectron/fcl/FclTest.java +++ b/src/test/java/com/vectron/fcl/FclTest.java @@ -237,6 +237,9 @@ public class FclTest { assertEquals(-28.482, evalPop("-10 irr-guess ! -5000 200 230 400 202 450 irr*").doubleValue(), 0.01); assertEquals(120000000, evalPop("400000 4 fire").doubleValue(), 0.01); assertEquals(1.96, evalPop("4 2 ri").doubleValue(), 0.01); + assertEquals(23.8562, evalPop("10000 19000 3 cagr").doubleValue(), 0.01); + assertEquals(24389.07, evalPop("100000 7 5 pmt").doubleValue(), 0.01); + assertEquals(41.67, evalPop("2.5 11 5 ggm").doubleValue(), 0.01); } private void evalDoubles(String script, List expected) {