Showing posts with label Internal rate of return. Show all posts
Showing posts with label Internal rate of return. Show all posts

Friday, June 7, 2019

Casio fx-5800P: Cash Flow Program (Pierre Gillet)

Casio fx-5800P:  Cash Flow Program (Pierre Gillet)

Introduction:  Cash Flows Using the Stat List

Today's program comes from Pierre Gillet, who emailed me a set of programs to calculate net present value (NPV) and internal rate of return (IRR) for the Casio fx-5800P.  A key feature is that these programs use the statistical lists List X and List Freq from the SD mode.

There are three programs listed:

"NPV":  calculates Net Present Value.  Store the interest rate in decimal in variable X in Comp mode before running "NPV".

"SOLVE":  solves for the Internal rate of return (IRR) using the secant method.  Again, use decimals for interest rates.  For the IRR, your YTARGET is always 0.

"YFX":  The function to solve.  In this case, YFX refers the program to "NPV".

The programs here are from Pierre Gillet and are presented with permission.

Casio fx-5800P program "NPV"  (Pierre Gillet) 

Notes:
1.  Small n  is from the Statistics variable n.  [ FUNCTION ], 7:  STAT, 2: VAR, 1: n
2.  Call up the Stat lists by:  [ FUNCTION ], 7: STAT, 1: LIST  (1: List, 2:  Freq, or type X for List X)

0 → Y : 1 → U : 2 → W 
Lbl 1
U + List Freq[W] → V
Lbl 2
Y (1 + X) + List X[W] → Y
Isz U
U < V ⇒ Goto 2
Isz W
U < n ⇒ Goto 1
List X[1] + Y ÷ ( ( 1 + X ) ^ ( n - 1 ) ) → Y

Casio fx-5800P program "SOLVE"  (Pierre Gillet)

Note:  Keep recycling the loop with [ EXE ] until an error occurs.  The final result is the IRR (stored in X).

Note: The frequency of the first data point (X[1]) is not considered in the calculation.

"X1" ? → A
"X2" ? → B
"YTARGET" ? → T
A → X : Prog "YFX"
Y - T → R
B → X : Prog "YFX"
Y - T → S
Lbl 1
B - S ( B - A ) ÷ ( S - R ) → C
C → X ⊿
Prog "YFX" : Y - T → Q
A → B : R → S : C → A : Q → R
Goto 1

Casio fx-5800P program "YFX"  (Pierre Gillet)

Prog "NPV"

Example

Go to SD mode.  Make sure that the Frequency is turned on by pressing [ SHIFT ],  ( SETUP), 5: STAT, 1: FreqOn

Data:  List X, Freq
-5600, 1
1300, 1
2500, 1
3000, 1

NPV:  interest rate of 8%.  (store 0.08 in X)

Result:  $128.55

Solve for IRR,  run SOLVE with guesses X1 = 0, X2 = .15, and YTARGET = 0.

Final result:  0.0912 (9.12%)

Thank you Pierre Gillet!

Note: I wasn't called to jury duty - back to normal life for me.  I'm also posting this a day early. 

Eddie

All original content copyright, © 2011-2019.  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.

Thursday, May 10, 2018

HP Prime: Combined Internal Rate of Return


HP Prime: Combined Internal Rate of Return

Introduction

An investor has several projects, each with their own initial investments and discount rate.  The net present value is calculated (NPV) for each project.  If the investor combined all the projects into one set of cash flows, what is the effective internal rate of return (IRR)?  The program COMBIRR tackles this question.

For example, an investor has the following projects, each lasting five years:

Project A:  NPV:  -$3,500, discount rate: 10%
Project B:  NPV:  $18,000, discount rate: 12%
Project C:  NPV:  $20,000, discount rate: 9%

If the investor combines all three projects, what would be the combined internal rate of return?  I use the following steps:

1. Calculate the NUS (net utility stream) of each project.  Since we are only given the net present value in this case, will need to determine a payment flow.  The NUS calculates the cash flow of each year, assuming they are equal.  Setup:  N = number of years, I/YR = discount rate, PV = -NPV, FV = 0, P/Y = 1.

2.  Combine the present values from each project, along with net utility streams calculated from each project.  Calculate IRR.  Setup:  CF0 = -ΣNPV, Cash Flows = ΣNUS, frequency length of project

This procedure, like the program COMBIRR, assumes that each project has the same length.  With some adjustments, you can calculate combined IRR using projects of the same length.

Going back to our example:
 
Project A:  NPV:  -$3,500, discount rate: 10%, NUS: -$569.61
Project B:  NPV:  $18,000, discount rate: 12%, NUS: $3,185.71
Project C:  NPV:  $20,000, discount rate: 9%, NUS: $3,116.40

ΣNPV:  $34,500, ΣNUS:  $5,732.50

Calculate IRR with CF0 = -34500.00, Cash Flows:  5,732.50 with a frequency of 5

Result:  10.49  (Combined IRR: 10.49%)

How to Run COMBIRR:

1. Enter the length of each of the projects.  COMBIRR assumes each project has the same length.

2.  Enter the NPV and discount RATE for the first project.  Each time the program will ask you “ENTRY?”.  Select YES for additional entries, NO to stop entering amounts.

3.  The combined IRR is calculated. 

HP Prime Program: COMBIRR

sub1(); // data subroutine

EXPORT COMBIRR()
BEGIN
// EWS 2018-05-10
// Combined IRR using
// same length projects

// initialize
LOCAL L1,U,T,L,C;
LOCAL h,N,I;

// input
INPUT(L,"Number of Periods",
"LEN: ");

// entry routine
REPEAT
L1:=sub1(); N:=L1(1); I:=L1(2);
T:=T-N;
U:=U+Finance.TvmPMT(L,I,−N,0,1);
CHOOSE(h,"ENTRY?","YES","NO");
UNTIL h==2;

// calculate combined IRR
C:=Finance.CashFlowIRR(
{T,{U,L}},1);
RETURN C;

END;

// data entry subroutine
sub1()
BEGIN
LOCAL x1,x2;
INPUT({x1,x2},"Data Entry",
{"NPV: ","RATE: "});
RETURN {x1,x2};
END;

Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.




Monday, September 5, 2016

Sharp EL-738: A Short Tutorial

Sharp EL-738:  A Short Tutorial


This is a short tutorial on how to use some of the common features of the Sharp EL-738 financial calculator.  There was a request for a video tutorial in the comments, however given the time frame I am able to work with, I think I can write a tutorial and cover more faster.  So hope this helps!


To see my review back in August last year, click here:

Let’s get to it.


Set Decimal Settings

To Fix 2 Mode:  [SET UP], 0 (DSP), 0 (TAB), 2

To Float (B) Mode:  [SET UP], 0 (DSP), 3 (FLO_A)

The difference between FLO_A (option 2) and FLO_B is the limit of how small a number can be before the calculator switches to scientific notation.  .000000001 for A and .01 for B.

Time Value of Money

To set the number of payments:  press [2ndF] [I/Y] (P/Y).  Enter the payments per year and press [ENT].  You can enter compounding periods (C/Y) per year separately. 

Toggle Begin/End Mode:  [2ndF] [ FV ] (BGN/END).  Beginning mode is indicated by “BGN” in the display.

Clear the Financial registers:  [2ndF] [MODE] (CA).  Caution: This sets the P/Y to its default value of 1. 

Calculation:  Enter each of the date and press the appropriate financial variable (N, I/Y, PV, PMT, or FV).  To calculate, press [COMP] then the financial variable. 

Example:  Find the monthly payment of a $160,000 loan to be paid back in 15 years with 3.5% interest. 

If not already, set P/Y to 12 and calculator to END mode (see the above).
160000 [ PV ]
15 [2ndF] [ N ] (xP/Y) [ N ] 
3.5 [I/Y]
0 [ FV ]
[COMP] [PMT]

Result:  -1143.81

Amortization

Press [AMRT].   Enter the first period (P1) then press [ENT].  Scroll down [ ↓ ] and enter the second period (P2) then press [ENT].  Scroll down for the following results (calculated automatically):  BALANCE, ΣPRINCIPAL (amount of principal paid in period range specified), ΣINTEREST (amount of interest paid in period range specified).

Take the last example and set P1 to 1 and P2 to 24.  After two years:
[AMRT] 1 [ENT] [ ↓ ]
24 [ENT] [ ↓ ]
Result:  BALANCE:  143,191.61   [ ↓ ]
Result:  ΣPRINCIPAL = -16808.39  [ ↓ ]
Result:  ΣINTEREST = -10643.05

Days Between Dates

Press [DATE].   M-D-Y 1 represents the beginning date.  M-D-Y 2 represents the ending date.  DAYS is the number of days between the two dates.  This assumes the U.S. date system is set up.

Scroll up and down.  Enter two of the three variables and press [COMP] to solve for the third.

Example:  A bond is issued on 7/1/2016. The bond is to be repaid in 120 days.  When is the bond supposed to be repaid?  Assume an actual calendar.  ([2ndF] [COMP] (360/ACT) toggles calendar counting mode)

[DATE]
For M-D-Y 1:  07, 01, 2016 [ENT]
[ ↓ ], [ ↓ ]
For DAYS:  120 [ENT]
[ ↑ ] to M-D-Y 2, press [COMP]

Result:  10/29/2016

Cash Flows

To clear all cash flows:  Press [2ndF] [ENT] (CLR-D).  I also recommend setting P/Y to 1 (pressing [2ndF] [MODE] (CA) will do it)

To enter cash flows:  Enter the cash flow, press [ ENT ].  (Don’t be in any menu or worksheet)

To enter cash flows with frequency greater than 1:  Enter the cash flow, press [(x,y)], enter the frequency, press [ ENT ].

To calculate NPV (net present value):  press [2ndF] [CFi] (CASH).  Enter the periodic rate at the RATE(I/Y)=, press [ENT], then [ ↓ ], and press [COMP] at the NET_PV prompt.

To calculate IRR (initial rate of return):  press [2ndF] [CFi] (CASH).  Press [COMP] at the RATE(I/Y)= prompt.   For this purpose, ignore the NET_PV register.

Example:   Calculate the NPV and IRR of the following cash flows:
Flow #
Amount
CF0
-$10,000
CF1
$5,000
CF2
$2,000
CF3
$5,000

For NPV, assume a return rate of 10%.

Cash Flows:
[2ndF] [MODE] (CA)
[2ndF] [ENT] (CLR-D)
10000 [+/-] [ENT]   (Display:  DATA SET: CF 0.00)
5000 [ENT] (Display:  DATA SET: CF 1.00 (and so on))
2000 [ENT]
5000 [ENT]

Net Present Value:
[2ndF] [CFi] (CASH)
RATE I/Y=:  10 [ENT]
[ ↓ ]
NET_PV=:  [COMP]
Result:  -45.08

Internal Rate of Return:
[ ↑ ]
RATE(I/Y)=:   [COMP]
Result:  9.74

Some quick instructions about depreciation and statistics:

Depreciation

The EL-738 has three depreciation modes:  Straight Line (SL), Sum of the Years Digits (SYD), and Declining Balance (DB).  To change the depreciation mode, press [SETUP], 2 and then:
0 for SL, 1 for SYD, 2 for DB.

To the Depreciation worksheet:  Press [DEPR].
Mode:  If the Declining Balance Deprecation Mode is set, enter the rate (for 200%, enter 200, press [ENT])  [ ↓ ]
Life (N):  Enter the number of years of the life of the asset, [ENT], [ ↓ ]
Start Month:  Enter the month when the asset is acquired (1 = January, 2 = February, etc), [ENT], [ ↓ ]
COST (PV): Cost of the asset, [ENT], [ ↓ ]
SALVAGE (FV):  Salvage value of the asset, [ENT], [ ↓ ]
YEAR=  Enter year of depreciation that you want to analyze, [ENT], [ ↓ ].
The next three lines are calculated: DEPRECIATE (the deprecation for the year, RBV (remaining book value), RDV (remaining depreciation value)

Statistics

To enter statistics mode, press [MODE], 2.  Select statistics type:
0:  SD, single variable
1:  LINE: linear regression, y = a + bx
2:  QUAD: quadratic regression, y = a + bx + cx^2
3:  EXP:  exponential regression, y = a * e^(bx)
4:  LOG:  logarithmic regression, y = a + b * ln x
5:  PWR:  power regression, y = a * x^b
6:  INV:  inverse regression, y = a + b/x

Clearing Data:  [2ndF] [DATA] (CLR D)
Entering Data:  x [(x,y)] y/freq [ENT] (DATA)
Recall variables:  [ALPHA] [(appropriate key)] [ = ]

Examples:
Mean:  μx: [ALPHA], 4;  μy: [ALPHA], 7
Sample Deviation:  sx: [ALPHA], 5; sy:  [ALPHA], 8
Regression variables a, b, c, r:  [ALPHA] [ ÷ ], [ DEL],. [ × ], [ ( ], respectively

  
You can find detailed instructions for the other operations (cost/sell/margin worksheet, Δ% worksheet, bond worksheet, depreciation, scientific functions), plus more examples, in the manual:  http://sharpcalculators.com/images/Manuals/Financial/EL738F_Manual_Branded.pdf


This blog is property of Edward Shore, 2016.

Saturday, August 20, 2016

Internal Rate of Return and Polynomials

Internal Rate of Return and Polynomials 

The internal rate of return function (IRR) is featured on many financial calcualtors, such as the HP 12C and HP 10bII (Plus) from Hewlett Packard, and BA II Plus (Professional) from Texas Instruments.  It calculates an interest rate of a group of cash flows when the net present value (NPV) is zero.  

0 = CF0 + CF1/(1 + r%) + CF2/(1 + r%)^2 + CF3/(1 + r%)^3 + ...

where r% = r/100 and r = IRR. 

The IRR can also aid in finding a root of polynomial.  Let x = 1/(1 + r/100).  Then:

0 = CF0 + CF1*x + CF2*x^2 + CF3*x^3 + ...

In the case, the cash flows are coefficients of the polynomial.  When calculating IRR, enter cash flows (coefficients) in terms of coefficients of increasing powers of x. 

Once r is calculated, then we can calculate for x (the root):

Algebraic operating system (HP 10bII, BA II Plus, and most others):
IRR [ ÷ ] 100 [ + ] 1 [ = ] [1/x] 

Reverse Polish Notation (RPN) system (HP 12C, a setting on the HP 17B II+):
IRR 1 [ % ] 1 [ + ] [1/x]

Things to keep in mind:

1.  This method is for polynomials for real roots only.  If all the roots are complex, this method is a no-go. 
2. Likewise, no complex number coefficients.  
3. The IRR function and algorithm to adjust it to find the root will be a positive root that is closest to zero (not always, but this is the case most of the time).  

A beautiful article by Valentin Albillo covers this topic for the HP 12C calculator and has a program to find all the roots for polynomials: http://www.hpcc.org/datafile/V21N2/V21N2P35.pdf

Let's look at a few examples. For these examples, all results are rounded to four decimal places (FIX 4). 

Using IRR to Find a Root to a Polynomial 

Example 1:  x^2 + 2x - 3 = 0

Enter the cash flows:
CF0 = -3
CF1 = 2
CF2 = 1

If need be, set P/Y = 1 (not necessary for the HP 12C and BA II Plus (Professional))

Compute IRR to get 0.0000

Follow the transformation x = 1/(IRR/100 + 1) and one root of x^2 + 2x - 3 is:

x = 1.0000

To my knowledge, the only calculator that allows for initial guesses is the HP 12C by entering the initial guess, then pressing [RCL], [ g ], [R/S].  

Example 2: 11.2x^4 - 2.1x^3 + 3x^2 - 3.6x - 2 = 0

Set the cash flows as follows:
CF0 = -2
CF1 = -3.6
CF2 = 3
CF3 = -2.1
CF4 = 11.2

Calculating IRR yields 29.7291.  

Transforming to the root for the polynomial will yield the root 0.7708.  

Simple enough, but let's look at the next example. 

Example 3: x^2 + 10x + 24 = 0

The cash flows for this problem would be:

CF0 = 24
CF1 = 10
CF2 = 1

Straight forward so far.  However, calculating IRR will yield an error.  Why?

The IRR function will require that at least one cash flow be the opposite sign, a mix of negative and positive cash flows.  Looking at what we have, all the flows are positive.  We can make the problem more palpable, we can make another substitution x = -t. As a consequence:

x = -t, x^2 = t^2, x^3 = -t^3, x^4 = t^4, and so on.

Our transformed polynomial is now:  t^2 - 10t + 24 = 0.  

The adjusted cash flows are:

CF0 = 24
CF1 = -10
CF2 = 1


This will require an adjustment in transform from IRR to root:

x = -1/(IRR/100 + 1) 

Procedure if the polynomial is going to adjusted by this additional step:

Algebraic operating system (HP 10bII, BA II Plus, and most others):
IRR [ ÷ ] 100 [ + ] 1 [ = ] [1/x] [+/-]

Reverse Polish Notation (RPN) system (HP 12C, a setting on the HP 17B II+):
IRR 1 [ % ] 1 [ + ] [1/x] [CHS]

Now calculate IRR. 

The HP 10b II+ gives -83.3333.   Translating to the root -6.0000. 

The BA II gives -75.000, which translate to the root -4.0000. 

Both are correct. 

The HP 12C gives Error 3.  However, if I entered an initial guess of say, -50, by keying -50 [RCL], [ g ], [R/S] returns -75.0000.   (For the root of -4.0000 after converting IRR to x (see above)). 

Interesting to see how the IRR function can help find a root of polynomials, which the required adjustments. 

Using the Polynomial Solver to Find IRR

Let's go the other way.  Say we have a scientific, even graphing calculator, and we are going to need to find the IRR but we don't have such function?  

Recall:

0 = CF0 + CF1/(1 + r%) + CF2/(1 + r%)^2 + CF3/(1 + r%)^3 + ...

where r% = r/100 and r = IRR. 

The IRR can also aid in finding a root of polynomial.  Let x = 1/(1 + r/100).  Then:

0 = CF0 + CF1*x + CF2*x^2 + CF3*x^3 + ...

Solving x = 1/(1 + r/100) for r yields:  r = 100*(1/x- 1)

In this case (and ideally), pick the root (x) that is positive and the closet to zero. 

Example 4:  Find the IRR for the following cash flows:
CF0 = -5000
CF1 = 1000
CF2 = 2000
CF3 = 3000
CF4 = 5000

The translated polynomial to be solved is:
0 = -5000 + 1000x + 2000x^2 + 3000x^3 + 5000x^4

Using the PolySmlt2 app of the TI-84 Plus CE I get the following roots, rounded to four decimal places:
-0.1238 ± 1.0739i, -1.1179, 0.7655

Substituting x = 0.7655 into r = 100*(1/x- 1) yields an approximate IRR of 30.6336%.  

Running the problem through the financial calculators yield 30.6348%. Using more decimal places of x will get a more precise IRR. 

This is the relationship between IRR and roots of polynomials.  

Eddie

Source: Albillo, Valentin "HP-12C's Serendipitous Solver". Ex-PPC #4747, HPCC #1075, Datafile.  March/April 2002. http://www.hpcc.org/datafile/V21N2/V21N2P35.pdf



This blog is property of Edward Shore, 2016 

HP 71B Basic and Casio fx-CG 100: Weighted Random Sample

HP 71B Basic and Casio fx-CG 100: Weighted Random Sample Introduction In calculators, it is fairly easy to generate a rand...