**HP Articles Forum**

[Return to the Index ]

[ Previous | Next ]

**WP 34S: financial routines IRR, NPV, Amortization, Interest rate conversion (updated 2013-04-28)**

*Posted by Miguel Toro on 12 Nov 2011, 2:20 p.m.*

/* Finance Routines What is included in this file: 1. Cash flow Analysis (Net present value and Internal rate of return) 2. Amortization 3. Nominal vs. Effective interest rate conversionHow to use:

1. Copy all this text in a new file called something like "fin.wp34s", not forgetting the comment marks.

2. Assemble the file. Here is an example on Windows:

wp34s_lib -ilib wp34s.dat -cat -state -olib wp34s.dat fin.wp34s

3. Transfer the .dat file to the emulator and/or your calculator. Notes: - The routines can be executed from flash. - These are been tested on version 3.2 revision 3376

1. CASH FLOW ANALYSIS ---------------------------------------------------- a.- CFE - Cash Flow input - Enters a maximum of 49 cash flow pairs for NPV and IRR calculation - Usage: Call the program and enter each pair of cash flow and occurrences and finish entering with 0 and [R/S]. A second [R/S] executes the Cash Flow Review routine for easily verify the entries.

Input Alpha x ------------------------ ----- ------- [XEQ], [ENTER], CFE CF0^n0 0. . . CF#^n# 0. CF#, [ENTER], n#, [R/S] -- or -- 0, [R/S] #CF= # of cash flows [R/S] ---> see CFR

b. CFR - Cash Flow Review - Review and modification of an existing cash flows series - Usage: Call the program and browse through the cash flow pairs. When a value is shown it can be modified before continuing the review, pressing the [R/S] key. This is a circular routine.

Input Alpha x -------------------------- ----- --------- [XEQ], [ENTER], CFR CF0= CF0 value . . CF#= CF# value (new cf - optional), [R/S] n#= n# value (new n - optional), [R/S] ...

c. NPV - Net Present Value - Calls NPV routine (LBL 00) to calculate NPV values - Usage: Input the Interest rate per period and execute NPV to calculate the Net Present Value based on previously entered Cash Flows(see CFE). The result will be shown in register x and the interest rate per period is kept in register I.

Input Alpha x ------------------------ ----- --------- I/P% I/P% value [XEQ], [ENTER], NPV NPV= NPV value

Additional Output : I: I/P% for further usage

d. IRR - Internal Rate of Return - Solves NPV routine (LBL 00) to find an IRR value - Usage: Call IRR based on a previously entered Cash Flows (see CFE). Input Alpha x ------------------------ ----- --------- [XEQ], [ENTER], IRR IRR= IRR value

2. AMORTIZATION -----------------------------------------------------------

a. ADE - Amortization Data Entry - Obtains the required data to calculate an amortization schedule: Capital, Payment per period, Number of periods and Interest rate per period (see the WP34s TVM application). - Usage: Call the routine and provide the following data: - Capital: Positive value, - Payment: negative value, - Total periods: if information is in years, multiply it by the number of periods per year, - Interest rate: if annual interest, divide it by the number of periods per year.

Input Alpha x ------------------------ ----- ------------------------------- [XEQ], [ENTER], ADE Cap? previous Cap value if any Cap value or nothing, [R/S] Pmt? previous Pmt value if any Pmt value or nothing, [R/S] Tprds? previous total of periods if any Tprds value or nothing, [R/S] I/P%? previous Interest/period if any I/P% value or nothing, [R/S] 0.

b. AMT - Amortization calculation - Calculates an amortization schedule for a interval of time based on data previously entered with ADE - Usage: Call AMT and enter an initial period and a final period. if you want to calculate for just a period (ex: a month), just enter the initial period and press [R/S] when asked for the final period. the routine finishes, entering 0 when asked for a new initial period.

Input Alpha x ------------------------ ----- --------- [XEQ], [ENTER], AMT Prd I? 0. Prd I, [R/S] Prd F? Prd I Prd F, [R/S] Pri principal amount [R/S] Int interest amount [R/S] Bal Balance at period F [R/S] Prd I? 0. 0, [R/S] ---> ends routine

3. NOMINAL/EFFECTIVE INTEREST RATE CONVERSION ------------------------------

a. EFF - Effective interest rate calculation Calculate the effective interest rate base on the compounding ... - Usage: Input the Interest rate per period and execute NPV to calculate the Net Present Value based on a previously entered Cash Flow series using CFE. The result will be shown in register x and the interest rate per period is kept in register I.

Input Alpha x ------------------------------ ----- --------- Nominal %, [XEQ], [ENTER], EFF P/Y? Previous P/Y if any new P/Y or nothing, [R/S] Effective %

b. NOM - Nominal interest rate calculation

Calculate the Nominal interest rate base on the compounding ... - Usage: Input the Interest rate per period and execute NPV to calculate the Net Present Value based on a previously entered Cash Flow series using CFE. The result will be shown in register x and the interest rate per period is kept in register I.

Input Alpha x ------------------------ ----- --------- Effective %, [XEQ], [ENTER], EFF P/Y? Previous P/Y if any new P/Y or nothing, [R/S] Nominal % */

/* 1. Cash Flow Analysis */

/* Cash Flow input - CFE - Enters a maximum of 49 cash flow pairs for NPV and IRR calculation - Usage: Call the program and enter each pair of cash flow and occurrences and finish entering with 0 and [R/S]. A second [R/S] executes the Cash Flow Review routine for easily verify the entries.

Input Alpha x ------------------------ ----- ------- [XEQ], CFE CF0^n0 0. . . CF#^n# 0. CF#, [ENTER], n#, [R/S] -- or -- 0, [R/S] #CF= # of cash flows [R/S] ---> see CFR

*/ LBL'CFE' CLSTK STO I STO J STO K cfeloop:: CLx CL[alpha] "CF" [alpha]IP J "[^]n" [alpha]IP J PROMPT x=0? JMP endloop STO+ I [cmplx]STO[->]K INC J INC K INC K JMP cfeloop endloop:: RCL K x=0? ERR 15 2 - SDR 003 2 SDR 005 + STO K CLx CL[alpha] [alpha] # "CF=" VW[alpha]+ I STOP

/* Cash Flow Review - CFR - Review and modification of an existing cash flows series - Usage: Call the program and browse through the cash flow pairs. When a value is shown it can be modified before continuing the review, pressing the [R/S] key. This is a circular routine. Input Alpha x -------------------------- ----- --------- [XEQ], [ENTER], CFR CF0= CF0 value . . CF#= CF# value (new cf - optional), [R/S] n#= n# value (new n - optional), [R/S] ... */ LBL'CFR' RCL K STO J STO I cfrloop:: CL[alpha] "CF " [alpha]IP I [alpha] = INC J RCL[->]J PROMPT STO[->]J CL[alpha] [alpha] n [alpha]IP I [alpha] = DEC J RCL[->]J PROMPT STO[->]J INC I ISG J JMP cfrloop GTO'CFR'

/* Net Present Value - Calls NPV routine (LBL 00) to calculate NPV values - Usage: Input the Interest rate per period and execute NPV to calculate the Net Present Value based on previously entered Cash Flows(see CFE). The result will be shown in register x and the interest rate per period is kept in register I.

Input Alpha x ------------------------ ----- --------- I/P% I/P% value [XEQ], [ENTER], NPV NPV= NPV value

Additional Output : I: I/P% for further usage */ LBL'NPV' STOM D SSIZE4 XEQ npv_irr FIX 02 CL[alpha] "NPV=" VW[alpha]+ X EEX 2 STO[times] I R[v] RCLM D RTN

/* Internal Rate of Return - Solves NPV routine (LBL 00) to find an IRR value - Usage: Call IRR based on a previously entered Cash Flows (see CFE).

Input Alpha x ------------------------ ----- --------- [XEQ], [ENTER], IRR IRR= IRR value

*/ LBL'IRR' STOM D SSIZE4 FIX 06 CLSTK EEX 2 SLV npv_irr JMP irrfound x[approx]? Y JMP irrfound RCL Z FIX 02 ROUND x[!=]0? ERR 20 R[v] irrfound:: FIX 02 CL[alpha] "IRR=" VW[alpha]+ X RCLM D RTN npv_irr:: 1 // Calculates NPV and solves for IRR STO A % STO I STO B INC B CLx STO C RCL K STO J sigmanpv:: [cmplx]RCL[->]J RCL I x=0? JMP intzero LN1+x +/- [times] e[^x]-1 STO A INC A +/- RCL/ I RCL[times] B ENTER[^] intzero:: R[v] [times] STO+ C RCL A STO[times] B ISG J JMP sigmanpv RCL C RTN

/* 2. Amortization */ /* Amortization Data Entry - ADE - Obtains the required data to calculate an amortization schedule: Capital, Payment per period, Number of periods and Interest rate per period (see the WP34s TVM application). - Usage: Call the routine and provide the following data: - Capital: Positive value, - Payment: negative value, - Total periods: if information is in years, multiply it by the number of periods per year, - Interest rate: if annual interest, divide it by the number of periods per year.

Input Alpha x ------------------------ ----- ------------------------------- [XEQ], [ENTER], ADE Cap? previous Cap value if any Cap value or nothing, [R/S] Pmt? previous Pmt value if any Pmt value or nothing, [R/S] Tprds? previous total of periods if any Tprds value or nothing, [R/S] I/P%? previous Interes/period if any I/P% value or nothing, [R/S] 0. */ LBL'ADE' SSIZE4 CL[alpha] RCL A "Cap?" PROMPT STO A RCL B CL[alpha] "Pmt?" PROMPT STO B RCL C CL[alpha] "Tprds?" PROMPT STO C RCL I SDL 002 CL[alpha] "I/P%?" PROMPT SDR 002 STO I CLx RTN

/* Amortization calculation - AMT - Calculates an amortization schedule for a interval of time based on data previously entered with ADE - Usage: Call AMT and enter an initial period and a final period. if you want to calculate for just a period (ex: a month), just enter the initial period and press [R/S] when asked for the final period. the routine finishes, entering 0 when asked for a new initial period.

Input Alpha x ------------------------ ----- --------- [XEQ], [ENTER], AMT Prd I? 0. Prd I, [R/S] Prd F? Prd I Prd F, [R/S] Pri principal amount [R/S] Int interest amount [R/S] Bal Balance at period F [R/S] Prd I? 0. 0, [R/S] ---> ends routine */ LBL'AMT' SSIZE4 CLx CL[alpha] "Prd-I?" PROMPT x=0? JMP finamt ENTER[^] CL[alpha] "Prd-F?" PROMPT [cmplx]STO Z x[<->] Y // Paiments for period F-I - INC X RCL[times] B STO D R[v] XEQ princip // Principal for F x[<->] Y DEC X XEQ princip // Principal for I-1 - // Principal for period F,I CL[alpha] "Pri" PROMPT STO- D // Interest for period F,I RCL D CL[alpha] "Int" PROMPT RCL A // Balance = Capital - Principal for F RCL+ T CL[alpha] "Bal" PROMPT GTO'AMT' finamt:: RTN princip:: XEQ accfact RCL C XEQ accfact / RCL[times] A +/- RTN accfact:: RCL I LN1+x [times] e[^x]-1 RTN

/* 3. Nominal/Effective interest rate conversion */ /* Effective interest rate calculation - EFF Calculate the effective interest rate base on the compounding ... - Usage: Input the Interest rate per period and execute NPV to calculate the Net Present Value based on a previously entered Cash Flow series using CFE. The result will be shown in register x and the interest rate per period is kept in register I.

Input Alpha x ------------------------------ ----- --------- Nominal %, [XEQ], [ENTER], EFF P/Y? Previous P/Y if any new P/Y or nothing, [R/S] Effective % */ LBL'EFF' SF C JMP prep

/* Nominal interest rate calculation - NOM Calculate the Nominal interest rate base on the compounding ... - Usage: Input the Interest rate per period and execute NPV to calculate the Net Present Value based on a previously entered Cash Flow series using CFE. The result will be shown in register x and the interest rate per period is kept in register I.

Input Alpha x ------------------------ ----- --------- Effective %, [XEQ], [ENTER], EFF P/Y? Previous P/Y if any new P/Y or nothing, [R/S] Nominal %

*/ LBL'NOM' CF C prep:: STOM J SSIZE4 periods:: x[<->] D CL[alpha] "P-Y?" PROMPT x[<->] D FS? C JMP calceff calcnom:: STO I 0 ENTER[^] EEX 2 SLV nom_eff JMP nomfound FIX 06 x[approx]? Y JMP nomfound FIX 02 x[<->] Z ROUND x[!=]0? ERR 20 x[<->] Z nomfound:: STO I RCLM J RTN calceff:: 0 STO I R[v] XEQ nom_eff STO I RCLM J RTN nom_eff:: RCL D // Calculates EFF and solves for NOM SDL 002 / 1 + RCL D y[^x] 1 - SDL 002 RCL- I RTN END

*Edited: 29 Apr 2013, 1:11 p.m. *