Showing posts with label DM41X. Show all posts
Showing posts with label DM41X. Show all posts

Saturday, April 18, 2026

DM41X: Interest Rate of a Forward-Forward Agreement

DM41X: Interest Rate of a Forward-Forward Agreement



A Future Interest Contract: Forward-Forward Agreement


A forward-forward agreement (yes, forward-forward is not a typo, that is what’s really called) is a financial transaction which starts on a forward date and ends on another forward date. An example transaction involves one party borrowing a sum amount to be paid back, only at the same time to deposit such amount in another short-term investment. The forward-forward rate, which I designate as FFR, is combined interest rate taking both transactions at the same time. The FFR is calculated as such:


FFR = [ (1 + IL * DL ÷ 365) ÷ (1 + IS * DS ÷ 365) – 1 ] * (365 ÷ (DL – DS))


IL: interest rate for the longer period, in decimal

DL: length of the long period

IS: interest rate for the shorter period, in decimal

DS: length of the short period

365: number of days in a year. It gets replaced with 360 if a 30/360 year is used.


If the loan lasts longer, the FFR represents the interest cost.

If the deposit lasts longer, the FFR represents the interest earned.



DM41X and HP 41C Code: FFR


01 LBL T^FFR

02 ^T FWD-FWD RATE

03 AVIEW

04 PSE

05 ^T LONG TRM DYS?

06 PROMPT

07 STO 01

08 STO 06

09 ^T LONG TRM %?

10 PROMPT

11 STO 02

12 %

13 365

14 /

15 1

16 +

17 STO 05

18 ^T SHORT TRM DYS?

19 PROMPT

20 STO 03

21 ST- 06

22 ^T SHORT TRM %?

23 PROMPT

24 STO 04

25 %

26 365

27 /

28 1

29 +

30 ST/ 05

31 RCL 05

32 1

33 -

34 365

35 *

36 RCL 06

37 /

38 2

39 10↑X

40 *

41 STO 07

42 ^T FFR=_

43 ARCL 07

44 AVIEW

45 RTN


Notes:

^T: It starts an alpha string.

Line 42: ^T FFR+_: The underscore is used as a space

Alpha strings are abbreviated in attempt for the message to fit the screen without scrolling.

Periods are assumed to be one year or less, and a 365-day year is assumed.


Examples


Example 1:

Longer Period (borrow): 49 days, 11%

Shorter Period (deposit): 30 days, 8%

Result: FFR= 15.6340


Example 2:

Longer Period (borrow): 63 days, 10.2%

Shorter Period (deposit): 31 days, 11.1%

Result: FFR= 9.2410


Source


Steiner, Bob. Mastering Financial Calculations. Second Edition. Prentice Hall: Financial Times. 2007. ISBN 978-0-273-70444-7. pp. 68-70



Eddie


All original content copyright, © 2011-2026. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Saturday, February 14, 2026

RPN: Absolute Value Equations with the HP 11C and DM41X

RPN: Absolute Value Equations with the HP 11C and DM41X



Introduction: Solving |z * w + y| = x


Today’s blog focuses on solving the absolute value equation:


|z * w + y| = x


for the variable w, and the values of z, y, and x are given and are on the Classic RPN stack.


For example, in the problem |5 * w + 7| = 2, the stack would be set up as:


t: (anything, it doesn’t matter)

z: 5

y: 7

x: 2


(This is why I set the variable as w instead of the usual x.)


One approach is to use memory registers and other uses only stack operations. Today’s algorithm focuses on the latter.


Caution: In the above equation, x will always be non-negative. The equation will never be valid if x is negative.



The Algebra


Solve for w:

|z * w + y| = x


This leads us to solve the two equations:


(I)

z * w + y = -x

z * w = -x – y

w = -x/z – y/z


Let w- = -x/z – y/z = (-x/z) + (-y/z)


(II)

z * w + y = x

z * w = x – y

w = x/z - y/z


Let w+ = x/z – y/z = (x/z) + (-y/z)


Then:


w- = -x/z – y/z

w- = (-x/z) + (-y/z)

w- = (-x/z) + (-y/z) + (-x/z) + (x/z)

w- = 2 * (-x/z) + (x/z) + (-y/z)

w- = 2 * (-x/z) + w+


RPN Code: HP 11C (adoptable for other RPN calculators)


LBL A

001

42, 21, 11

Program start

R↓

002

33


R↓

003

33


X<>Y

004

34


R↓

005

33


1/x

006

15


×

007

20


LST x

008

43, 36


X<>Y

009

34


R↓

010

33


×

011

20


LST x

012

43, 36


R↑

013

43, 33


X<>Y

014

34


R↓

015

33


X<>Y

016

34


CHS

017

16


X<>Y

018

34


+

019

40


ENTER

020

36


ENTER

021

36


LST x

022

43, 36


-

023

30


LST x

024

43, 36


-

025

30


RTN

026

43, 32

Program end


RPN Code: DM41X (HP 41C series, no module is required)


LBL “ASBEQ”

RDN

RDN

X<>Y

RDN


1/x

×

LAST X

X<>Y

RDN

×

LAST X

R↑

X<>Y


RDN


X<>Y

CHS

X<>Y


+

ENTER

ENTER

LAST X

-

LAST X

-


RTN



Notes:

* RDN is shown as R↓

* To enter R↑, press XEQ, ALPHA, R, SHIFT, ENTER, ALPHA



Subroutines Used


We used several techniques to manipulate the stack. They are presented below:


Rotate stack from X, Y, Z, T to Z, X, Y, T

R↓

R↓

X<>Y

R↓


Source:

Ball, John A. Algorithms for RPN Calculators John Wiley & Sons: New York. 1978. ISBN 0-471-03070-8. pg. 78



Multiply Y and Z by 1/X. Stack: X, Y, Z, T → X, Y/X, Z/X, T


1/x

×

LAST X

X<>Y

R↓

×

LAST X

R↑

X<>Y


Change X, Y to Y+ X, Y – X


+

ENTER

ENTER

LAST X

-

LAST X

-


The resulting stack is:


z

z

y + x

y – x


Doing LAST X, -, twice is effectively subtracting whatever is in L register twice.



Examples


|4 * w – 6| = 5


Stack:

z: 4

y: -6

x: 5


Results:

y: 2.75

x: 0.25


|2 * w + 5| = 3


Stack:

z: 2

y: 5

x: 3


Results:

y: -1

x: -4




Eddie


All original content copyright, © 2011-2026. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Saturday, October 11, 2025

RPN Calculators: INPUT vs PROMPT

RPN Calculators: INPUT vs PROMPT


Later RPN keystroke programming calculators are able to display alphabetic messages and store to variables for alphabetic names.


HP 32S, HP 32SII, HP 33S, HP 35S, DM32

HP 41C (all variants), DM41X

HP 42S, DM42, DM42n, Free 42

Single letter variable names

Numeric-named variables only

Both numeric-named variables and alphabetic (and alphanumeric) variable names. Alphabetic and alphanumeric named variables are enclosed in quotes (alpha strings) well stored and recalled and take additional memory.

Can display messages by setting Flag 10 and using the equation feature to type messages

Can display messages and prompts

Can display messages and prompts


Two common ways to cue the user to enter values are the INPUT and PROMPT commands.


The INPUT Command: HP 32 and HP 42S (and Swiss Micros/emulator equivalents)


Note: The INPUT command is not available in the HP 41C’s command set.


General syntax: INPUT var


When an INPUT command is encountered, the screen will display [var]?= on the X stack.


Example:

INPUT R displays R? [previous value stored in R]


HP 32 Family: The variable is a single-letter name or the indirect variable i.

HP 42S Family: A custom alpha variable, a numeric-named variable (i.e. 00, 01, 02, etc.), indirect variables, or the stack levels X, Y, T, Z, or L (last argument).


The INPUT has the double benefit of storing whatever is entered into the variable asked for. INPUT will also show the previously stored value, so we can just accept it by pressing R/S to keep the old value.


Example: Volume of a Cone


HP 32 family

HP 42S family

V01 LBL V

V02 INPUT R

V03 INPUT H

V04 π

V05 RCL R

V06 x^2

V07 ×

V08 RCL H

V09 ×

V10 3

V11 ÷

V12 RTN


No quotes are needed for alphabetic variables.



00 {30-Byte Prgm }

01 LBL “VCONE1”

02 INPUT “R”

03 INPUT “H”

04 PI

05 RCL “R”

06 x↑2

07 ×

08 RCL “H”

09 ×

10 3

11 ÷

12 RTN


We could use variables 00 and 01 (for example) for radius and height, respectively, except the input command prompt will show “R00?” or “R01?” which may not be user-friendly.


The INPUT does not replace the contents of the alpha register.


If we want the alphanumeric/alphanumeric variables (“R”, “H”) to be erased, we could have inserted CLV “R” and CLV “H” at the end, but that will erase the value associated with them.



The PROMPT Command: HP 41C and HP 42S (and Swiss Micros/emulator equivalents)


Note: The PROMPT command is not available on the HP 32S family.


General Syntax:

alpha string”

PROMPT

STO var


The alpha string is displayed until something, usually a numeric value, is entered. Unlike the INPUT command, the PROMPT does not automatically store the entered value into a variable. Therefore, if you want to use the value for future use, a STO (store) command must be used following the prompt.


Let’s take our volume of the cone example again:


HP 41C family

HP 42S family

01 LBL “VCONE2”

02 ^T RADIUS?

03 PROMPT

04 STO 00

05 ^T HEIGHT?

06 PROMPT

07 STO 01

08 PI

09 RCL 00

10 X↗2

11 *

12 RCL 01

13 *

14 3

15 /

16 RTN



R00 = radius

R01 = volume

00 { 40-Byte Prgm }

01 LBL “VCONE2”

02 “RADIUS?”

03 PROMPT

04 STO 00

05 “HEIGHT?”

06 PROMPT

07 STO 01

08 PI

09 RCL 00

10 X↑2

11 ×

12 RCL 01

13 ×

14 3

15 ÷

16 RTN



R00 = radius

R01 = volume


With PROMPT, I like to use the numeric-named memory registers, but we can use alphabetic or alphanumeric registers as well.


HP 32SII/DM32: Simulating PROMPT with Flag 10


Even though the HP 32SII does not have a PROMPT command, we can kind of simulate it by using the equation message feature.


To set flag 10: [ |→ ] [ × ]* (FLAGS), { SF }. [ . ] [ 0 ]

To clear flag 10: [ |→ ] [ × ]* (FLAGS), { CF }. [ . ] [ 0 ]

We have to use the decimal point key in order to access flags beyond 9.

(*HP 35S: [ ←| ] [ ↑ ] (FLAGS))


HP 32SII/33S/35S/DM32


W01 LBL W

W02 SF 10

W03 “=RADIUS”

W04 STO R

W05 “=HEIGHT”

W06 STO H

W07 CF 10


W08 π

W09 RCL R

W10 x^2

W11 ×

W12 RCL H

W13 ×

W14 3

W15 ÷

W16 RTN


Turn message mode on

Enter as an equation =RADIUS

Enter radius and press [R/S]

Enter as an equation =HEIGHT

Enter height and press [R/S]

Turn message mode off, so equations can operate normally



Note: Equations are NOT on the original HP 32S.



I hope you find this helpful.


Eddie


All original content copyright, © 2011-2025. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


The author does not use AI engines and never will.

HP 65 Programs: Triangulation, Percentile, Roots of Unity, Partial Fractions

  HP 65 Programs: Triangulation, Percentile, Roots of Unity, Partial Fractions Triangulation (done with HP-65 Emulator for Windows, Ber...