Showing posts with label net present value. Show all posts
Showing posts with label net present value. 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.

Friday, May 11, 2018

Fun with the Sharp EL-5500 III (May 2018 Edition)


Fun with the Sharp EL-5500 III   (May 2018 Edition)

The EL-5500 III is one of my favorite pocket programming device, small, portable, and has my favorite programming language: BASIC. 

Let’s get started.

Note:  Substitute line numbers with labels that you find fit.  Add defined labels to the first line if you would like.  Labels can come from the bottom two rows of the QWERTY keyboard (A row and Z row).

Comments are followed by double slashes (//), they are not typed.

Sharp EL-5500 III Program:  Net Present Value

2  PAUSE “NET PRESEN VALUE”
4  CLEAR    // clears all the variables
6  INPUT “CF0:”; N, “RATE:”; I
8  J = 1
10 INPUT “FLOW:”; F, “FREQ:”; K
12 FOR L=1 TO K: N = N + F/(1 + I/100)^J: J = J+1
14 NEXT L
16 INPUT “MORE=1: “; L   // enter 1 to enter more cash flows, anything else to end entry
18 PRINT USING “#############.##”; “NPV: “; N
20 END

Example:

CF0:  -7,000,  Interest Rate:  8%
Flow 1:  2,000, Freq 1: 1  (enter 1 for MORE)
Flow 2:  1,500, Freq 2: 2  (enter 1 for MORE)
Flow 3:  2,500, Freq 3: 2  (we are at the end, enter anything other than 1 at MORE)

Result:
NPV:  2443.06

Sharp EL-5500 III Program: Synthetic Division

2 PAUSE “Synthetic Division”: CLEAR
4 PRINT “P(X)/(X – R)”: WAIT 59   // WAIT 59 is about 1 second
6 INPUT “DEGREE:”; N
8 DIM P(N): DIM Q(N)
10 FOR I=1 TO N
12 PRINT “COEF OF X^”; N-I
14 INPUT P(I): Q(I) = P(I)
16 NEXT I   // there is no line 18
20 INPUT “R:”; R
22 FOR I=0 TO N-1
24 Q(I+1) = R*Q(I) + P(I+1)
26 NEXT I
28 E = Q(N)
30 PRINT “Q(X) = “
32 FOR I=0 TO N-1
34 PRINT Q(I); “X^”; N-I-1
36 WAIT 150  // about 2.5 seconds
38 NEXT I
40 PRINT “+”; E; “/(X-“; R; “)”: END

Example:  (x^4 – 2*x^3 + 1) / (x – 1)
Degree: 4
Coefficients:  1, -2, 0, 0, 1
R: 1

Result: 1, -1, -1, -1, no remainder
x^3 – x^2 – x – x

Sharp EL-5500 III Program: Vector Basics

Cross product, dot product, norm of two vectors, angle between two vectors

2 PAUSE “Vector Basics”
4 INPUT “X1:”; X1, “Y1:”; Y1, “Z1:”; Z1  \\ vector 1
6 INPUT “X2:’; X2, “Y2:”; Y2, “Z2:”, Z2  \\ vector 2
8 C1 = Y1*Z2 – Y2*Z1: C2 = -X1*Z2 + X2*Z1: C3 = X1*Y2 – X2*Y1  // cross product
10 D = X1*X2 + Y1*Y2 + Z1*Z2  \\ dot product
12 N1 = √(SQU X1 + SQU Y1 + SQU Z1): N2 = √(SQU X2 + SQU Y2 + SQU Z2)  // norm, SQU is the x^2 key
14 DEGREE
16 A = ACS( D/(N1*N2))  // angle between vectors, ACS is ACOS
18 PRINT “CROSS X: ”; C1
20 PRINT “CROSS Y: ”; C2
22 PRINT “CROSS Z: ”; C3
24 PRINT “DOT: ”; D
26 PRINT “NORM V1: “; N1
28 PRINT “NORM V2: “; N2
30 PRINT “ANGLE: “; A
32 END


Example:  V1 = [-2, 3, 0] and V2 = [ 4, 2, -11]
Cross: [-33, -22, -16]
Dot: -2
Norm V1: 3.605551275
Norm V2: 11.87434209
Angle: 92.67749998°

Sharp EL-5500 III: Atwood Machine

M1:  mass hanging on the left side of the machine
M2:  mass hanging on the right side of the machine

The program asks to choose a unit system.  Enter 1 for US units (feet, pounds, seconds, g = 32.174 ft/s^2), anything else for SI units (meters, kilograms, seconds, g = 9.80665 m/s^2).

2 PAUSE “Atwood Machine”
4 INPUT “1: US, ELSE: SI “; I
6 IF I=1 THEN LET G=32.174
8 IF I<>1 THEN LET G=9.80665
10 INPUT “M1: “; M1, “M2: “; M2
12 A = (M1 – M2)*G / (M1 + M2)
14 T = M1 * (G-A)
16 PRINT “Accel.: “; A
18 PRINT “Tension: “: T
20 END

Example:  M1 = 11.82 kg, M2 = 9.38 kg, use SI units (enter anything other than 1 at the 1:US, ELSE:SI prompt)

Results:
Accel.: 1.128689906 m/s^2
Tension: 102.5734883 N


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.

Sunday, August 7, 2016

HP 12C Programming III: Refinancing, Advance Payments in a Lease, NPV, NFV, NUS

HP 12C Programming III: Refinancing, Advance Payments in a Lease, NPV, NFV, NUS


HP 12C Programming Part I:  Modulus, GCD, PITI 

HP 12C Programming Part II:  Weekday Number, Gross Up Calculation


HP 12C Refinancing:  When refinancing “resets” the clock.

Sometimes when a long term mortgage is refinanced, the original length of term is reset.  We will assume payments are made monthly.

Input: 

Store the following amounts in the registers:

Clear the TVM variables by pressing [ f ] [x<>y] (CLEAR FIN)
Original number of payments,  [ n ]
Annual rate, [ 12÷ ] [ I ]
Loan Amount, [ PV ]

Number of payments that have been made prior to refinance, [STO] [ 0 ]  (R0)
New annual rate, [ENTER], 12, [ ÷ ], [STO] [ 1 ]  (R1)

Run the program by pressing [R/S].  The original payment is calculated.  Press [R/S] again to get the balance.  Enter any additional monies (can be $0.00) received due to the refinance.  Finally, press [R/S] again, and the new payment is calculated.

Program:
STEP
CODE
KEY
01
45, 11
RCL n
02
44, 2
STO 2
03
14
PMT
04
14
PMT \\ calculate payment
05
31
R/S
06
45, 0
RCL 0
07
11
n
08
15
FV
09
31
R/S  \\ calculate balance, ask for amount of withdrawn
10
30
-
11
16
CHS
12
13
PV
13
0
0
14
15
FV
15
45, 1
RCL 1
16
12
i
17
45, 2
RCL 2
18
11
n
19
14
PMT
20
43, 33, 00
GTO 00

Example: 

A couple purchased a house for $185,000.  The mortgage lasts for 30 years (360 months) with a 4.8% interest rate (0.4% periodic rate).   180 payments have passed, and the couple is able to refinance the mortgage (but pay that amount in 30 years) at a rate of 3.84%.  $15,000 is also cashed out.

Input:

360 [ n ]
0.4 [ i ]
185000 [PV]
180 [STO] [ 0 ]
0.32 [STO] [ 1 ]

Results:

[R/S]    -970.63  (The original payment is $970.63)
[R/S]    -124,373.78   (Balance of $124,373.78)
Enter 15000, press [R/S] -652.60   (New payment is $652.60)

HP 12C:  Advance Payments in a Lease

The program calculates the payment where you pay number of payments in advance.

Formula:

PMT = (-PV – FV*(SPPV(I%/12:N))) ÷ (UPSV(I%/12:N-ADV)+ADV)

Where:
SPPV:  present value of $1, where FV is equal to 1
USPV:  present value of $1, where PMT is equal to 1

Input:

Number of payments, [ STO ] [ 0 ]
Number of payments made in advance, [ STO ] [ 1 ]
Periodic Rate, [STO] [ 2 ]
Price of the Lease, [STO] [ 3 ]
Salvage Value, [ STO ] [ 4 ]

Calculate lease payment by pressing [R/S].

STEP
CODE
KEY
01
42, 34
Clear FIN  ([ f ] [x<>y])
02
1
1
03
16
CHS
04
15
FV
05
45, 2
RCL 2
06
12
i
07
45, 0
RCL 0
08
11
n
09
13
PV
10
45, 4
RCL 4
11
20
*
12
16
CHS
13
45, 3
RCL 3
14
30
-
15
45, 11
RCL n
16
45, 1
RCL 1
17
30
-
18
11
n
19
45, 15
RCL FV
20
14
PMT
21
0
0
22
15
FV
23
13
PV
24
45, 1
RCL 1
25
40
+
26
10
÷
27
43, 33, 00
GTO 00

Example:

A machine with a cost of $40,000.00 is leased for 48 months.  Two advanced payments are required.  Interest rate is 10% (monthly periodic rate is 10%/12).  The residual value is estimated to be $15,000.

Input:

48 [STO] [ 0 ]   \\ term
2 [STO] [ 1 ]   \\ 2 advanced payments
10 [ENTER] 12 [ ÷ ] [STO] [ 2 ]  \\ interest rate
40000 [STO] [ 3 ]  \\ cost
15000 [STO] [ 4 ] \\ salvage value

Result:

[R/S]  -1249.30    (Each payment is $1,249.30.  Two advanced payments are $2,498.60).

Source:  HP 17bII+ Financial Calculator User’s Guide.  Hewlett Packard.  Edition 3:  2007

HP 12C: Net Present Value, Net Future Value, Net Utility Stream

Input:

Clear the registers/finance registers
Press [ g ] (GTO) 00 to get the pointer to line 00.  (000 for the HP 12C Platinum editions.  Remember, the Platinum editions have up to 400 steps and line numbers are in triple digits)
Store -1 in [ n ] (don’t worry, n is incremented in the main loop)
Store periodic interest rate in [ i ].
Store 0 in register 0  (0 [STO] [ 0 ]).  Register 0 is use for calculating NPV

Enter each cash flow one at a time, and press [R/S].

Ready to calculate:

Press [ g ] (GTO) 10  (or 010) to get the pointer to line 10. 
Press [R/S] to get NPV (net present value)
Press [R/S] to get NFV (net future value)
Press [R/S] to get NUS (net utility stream)

Program:
STEP
CODE
KEY
01
16
CHS  // main loop: input data
02
15
FV
03
45, 11
RCL n
04
1
1
05
40
+
06
11
n
07
13
PV
08
44, 40, 0
STO+ 0
09
43, 33, 0
GTO 00  // finish main loop
10
45, 0
RCL 0 // calculation part
11
31
R/S  // net present value
12
1
1
13
16
CHS
14
13
PV
15
0
0
16
14
PMT
17
15
FV
18
45, 0
RCL 0
19
20
*
20
31
R/S  // net future value
21
45, 0
RCL 0
22
1
1
23
16
CHS
24
14
PMT
25
0
0
26
15
FV
27
13
PV
28
10
÷
29
31
R/S  // net utility stream


Example:

Rate:  15%
Cash Flow #
Flow
0
-10,000.00
1
2500.00
2
3500.00
3
5000.00
4
5000.00

Input:
[ f ] CLEAR FIN, [ f ] CLEAR PRGM
-1 [ n ]  // do this on each new problem
0 [STO] [ 0 ]   // do this on each new problem

15 [ i ]
10000 [CHS] [R/S]
2500 [R/S]
3500 [R/S]
5000 [R/S]
5000 [R/S]

Results:

[GTO] 10  [R/S]:   NPV = 966.76
[R/S]:   NFV = 1690.88
[R/S]:   NUS = 338.62

Input slowly and carefully.

This blog entry is property of Edward Shore, 2016.



Python: Drawing a Ring of Circles

Python: Drawing a Ring of Circles The goal: Draw a number of circles that revolve around the origin (0,0). The center of each circle i...