Showing posts with label XIRR. Show all posts
Showing posts with label XIRR. Show all posts

Wednesday, September 15, 2010

Android Application FREENPVIRR 2.19 Tutorial - A Free NPV, IRR, XNPV, XIRR and Date Different Calculator

1.0 BACKGROUND

In finance, the net present value (NPV) of a time series of cash flows, both inflow and outflow, is defined as the sum of the present values (PVs) of the individual cash flows. In the case when all future or expected cash flows are:
- inflow (e.g as coupons, dividend etc) and;
- outflow of cash is the purchase price (normally we use negative sign for the outflow).

NPV is a central tool in discounted cash flow (DCF) analysis, and is a standard method for using the time value of money to appraise LONG-TERM PROJECTS. Used for capital budgeting, and widely throughout economics, finance, and accounting, it measures the excess or shortfall of cash flows, in present value terms, once financing charges are met.





Figure 1: To calculate the net present value for a series of cash flows that is regularly periodic, NPV function is used. Graphical illustration of net present value NPV - total sum of discounted individual cash flow to present day with the given expected rate. And, net future value NFV - total sum of compounded individual cash flow to future end date of the project with the given expected rate.


Decision making criteria:
For NPV>0 with a given expected rate, the investment would add value to the firm, thus the project may be accepted.
For NPV<0 with a given expected rate, the investment would subtract value from the firm, thus the project should be rejected.
For NPV = 0 with the expected rate, the investment would neither gain nor lose value for the firm. We should be indifferent in the decision whether to accept or reject the project. This project adds no monetary value. And, the given expected rate is now called as IRR - internal rate of return.


 
Figure 2: Returns the net present value for a schedule of cash flows that is not necessarily periodic, XNPV is used. Graphical illustration of net present value XNPV - total sum of discounted individual cash flow to present day with the given expected rate. And, net future value XNFV - total sum of compounded individual cash flow to future end date of the project with the given expected rate.

By taking XNPV = 0, XIRR is defined as below:

 

2.0 Methodology
2.1 Net present value - NPV Android Java source code

dbnpv = 0;
            for(i=0;i<=5;i++)
            dbnpv = dbnpv + dbcf[i]/(Math.pow((1+dbrate/100), i));
                       
            if (v==NPV)
            {
                if(dbnpv<=0)
                {
                    answernpv = "NPV = " + currency.format(dbnpv) +" , project/investment rejected.";
                    result.setText(answernpv);   
                }
                else
                {
                    answernpv = "NPV = " + currency.format(dbnpv) +" , project/investment accepted.";
                    result.setText(answernpv);   
                }
            }//NPV calculation closing


2.2 Internal rate of return - IRR Android Java source code

{
            {
               final double estimateddbirr = 0;
           
            Double dbirr = Double.NaN;
           
            if (dbcf != null && dbcf.length > 0)
            {
                //check if business startup costs is not zero:
                if (dbcf[0] != 0.0)
                {
                    final double noOfdbcf = dbcf.length;
                   
                    double sumdbcf = 0.0;
                    //check if at least 1 positive and 1 negative cash flow exists:
                    int noOfNegativedbcf = 0;
                    int noOfPositivedbcf = 0;
                    for (int i1 = 0; i1 < noOfdbcf; i1++)
                    {
                        sumdbcf += dbcf[i1];
                        if (dbcf[i1] > 0)
                        {
                            noOfPositivedbcf++;
                        }
                        else if (dbcf[i1] < 0)
                        {
                            noOfNegativedbcf++;
                        }
                    }
                   
                    if (noOfNegativedbcf > 0 && noOfPositivedbcf > 0)
                    { //at least 1 negative and 1 positive cash flow available?
                      //set estimated dbirr:
                        double irrGuess = 0.1; //default: 10%
                        if (estimateddbirr != Double.NaN)
                        {
                            irrGuess = estimateddbirr;
                            if (irrGuess <= 0.0) irrGuess = 0.5;
                        }
                       
                        //initialize first IRR with estimated dbirr:
                        double irr = 0.0;
                        if (sumdbcf < 0)
                        { //sum of cash flows negative?
                            irr = -irrGuess;
                        }
                        else
                        { //sum of cash flows not negative
                            irr = irrGuess;
                        }
                       
                        //iteration Newton-Raphson method:
                        final double minDistance = .0000000001; //the smaller the distance, the smaller the interpolation error
                        final double dbcftart = dbcf[0]; //business startup costs
                        final int maxIteration = 50;
                        boolean wasHi = false;
                        double cashValue = 0.0;
                        for (int i1 = 0; i1 <= maxIteration; i1++)
                        {     //for each iteration
                            //calculate cash value with current irr:
                            cashValue = dbcftart; //init value with startup costs
                            for (int j1 = 1; j1 < noOfdbcf; j1++)
                            { //for each cash flow
                                cashValue += dbcf[j1] / Math.pow(1.0 + irr, j1);
                            }//next cash flow
                           
                            if (Math.abs(cashValue) < 0.01)
                            { //cash value is nearly zero
                                dbirr = irr;
                                break;
                            }
                           
                            //adjust irr for next iteration:
                            if (cashValue > 0.0)
                            { //cash value > 0 => next irr > current irr
                                if (wasHi)
                                {
                                    irrGuess /= 2;
                                }
                               
                                irr += irrGuess;
                               
                                if (wasHi)
                                {
                                    irrGuess -= minDistance;
                                    wasHi = false;
                                }
                            }
                            else
                            { //cash value < 0 => next irr < current irr
                                irrGuess /= 2;
                                irr -= irrGuess;
                                wasHi = true;
                            }
                           
                            if (irrGuess <= minDistance)
                            { //estimated dbirr too small to continue => end calculation
                                dbirr = irr;
                                break;
                            }
                        }//next iteration
                    }//else: noOfNegativedbcf == 0 || noOfPositivedbcf == 0
                }//else: first cash flow is 0
            }//else: dbcf unavailable
            answerirr = "IRR(%) = " + formatter.format(dbirr*100) + "%";
            result.setText((String) answerirr.toString());
            //return ir;
            }//getIRR()
        } //IRR calculation closing


 2.3 Net future value - NFV Android Java source code

{
                           
                dbnfv = dbnpv*Math.pow(1+dbrate/100,number-1);
                answernfv = "NFV = " + currency.format(dbnfv);
                result.setText(answernfv);
                   
            } //NFV calculation closing


2.4 Net present value - XNPV Android Java source code

dbnpv = 0;
            for(i=0;i<=5;i++)
            dbnpv = dbnpv + dbcf[i]/(Math.pow((1+dbrate/100),ddiff[i]/365));


if (v==NPV)
            {   
                if(ddiff[5]<0||ddiff[4]<0||ddiff[3]<0||ddiff[2]<0||ddiff[1]<0||ddiff[0]<0)
                {
                    new AlertDialog.Builder(this)
                    .setTitle("Error Message")
                    .setMessage("Please key in date in ascending order!")
                    .setNeutralButton("Close", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dlg, int sumthin) {
                    // do nothing – it will close on its own
                    }
                    })
                    .show();   
                }
                else
                {
                    if(dbnpv<=0)
                    {
                        answernpv = "NPV = " + currency.format(dbnpv) +" , project/investment rejected.";
                        result.setText(answernpv);   
                    }
                    else
                    {
                        answernpv = "NPV = " + currency.format(dbnpv) +" , project/investment accepted.";
                        result.setText(answernpv);   
                    }
                }//Error message closing
            }//NPV calculation closing


 2.5 Internal rate of return - XIRR Android Java source code

{
            {
               final double estimateddbirr = 0;
           
            Double dbirr = Double.NaN;
           
            if (dbcf != null && dbcf.length > 0)
            {
                //check if business startup costs is not zero:
                if (dbcf[0] != 0.0)
                {
                    final double noOfdbcf = dbcf.length;
                   
                    double sumdbcf = 0.0;
                    //check if at least 1 positive and 1 negative cash flow exists:
                    int noOfNegativedbcf = 0;
                    int noOfPositivedbcf = 0;
                    for (int i1 = 0; i1 < noOfdbcf; i1++)
                    {
                        sumdbcf += dbcf[i1];
                        if (dbcf[i1] > 0)
                        {
                            noOfPositivedbcf++;
                        }
                        else if (dbcf[i1] < 0)
                        {
                            noOfNegativedbcf++;
                        }
                    }
                   
                    if (noOfNegativedbcf > 0 && noOfPositivedbcf > 0)
                    { //at least 1 negative and 1 positive cash flow available?
                      //set estimated dbirr:
                        double irrGuess = 0.1; //default: 10%
                        if (estimateddbirr != Double.NaN)
                        {
                            irrGuess = estimateddbirr;
                            if (irrGuess <= 0.0) irrGuess = 0.5;
                        }
                       
                        //initialize first IRR with estimated dbirr:
                        double irr = 0.0;
                        if (sumdbcf < 0)
                        { //sum of cash flows negative?
                            irr = -irrGuess;
                        }
                        else
                        { //sum of cash flows not negative
                            irr = irrGuess;
                        }
                       
                        //iteration Newton-Raphson method:
                        final double minDistance = .0000000001; //the smaller the distance, the smaller the interpolation error
                        final double dbcftart = dbcf[0]; //business startup costs
                        final int maxIteration = 50;
                        boolean wasHi = false;
                        double cashValue = 0.0;
                        for (int i1 = 0; i1 <= maxIteration; i1++)
                        {     //for each iteration
                            //calculate cash value with current irr:
                            cashValue = dbcftart; //init value with startup costs
                            for (int j1 = 1; j1 < noOfdbcf; j1++)
                            { //for each cash flow
                                cashValue += dbcf[j1] / Math.pow(1.0 + irr, ddiff[j1]/365);
                            }//next cash flow
                           
                            if (Math.abs(cashValue) < 0.01)
                            { //cash value is nearly zero
                                dbirr = irr;
                                break;
                            }
                           
                            //adjust irr for next iteration:
                            if (cashValue > 0.0)
                            { //cash value > 0 => next irr > current irr
                                if (wasHi)
                                {
                                    irrGuess /= 2;
                                }
                               
                                irr += irrGuess;
                               
                                if (wasHi)
                                {
                                    irrGuess -= minDistance;
                                    wasHi = false;
                                }
                            }
                            else
                            { //cash value < 0 => next irr < current irr
                                irrGuess /= 2;
                                irr -= irrGuess;
                                wasHi = true;
                            }
                           
                            if (irrGuess <= minDistance)
                            { //estimated dbirr too small to continue => end calculation
                                dbirr = irr;
                                break;
                            }
                        }//next iteration
                    }//else: noOfNegativedbcf == 0 || noOfPositivedbcf == 0
                }//else: first cash flow is 0
            }//else: dbcf unavailable
            answerirr = "IRR(%) = " + formatter.format(dbirr*100) + "%";
            result.setText((String) answerirr.toString());
            //return ir;
            }//getIRR()
            }//error message closing
        } //IRR calculation closing


 2.6 Net future value - XNFV Android Java source code

{
                    dbnfv = dbnpv*Math.pow(1+dbrate/100,ddiff[number-1]/365);
                    answernfv = "NFV = " + currency.format(dbnfv);
                    result.setText(answernfv);
                }//Error message closing
            } //NFV calculation closing
            else if (v==IRR)
            {if(ddiff[5]<0||ddiff[4]<0||ddiff[3]<0||ddiff[2]<0||ddiff[1]<0||ddiff[0]<0)
            {
                new AlertDialog.Builder(this)
                .setTitle("Error Message")
                .setMessage("Please key in date in ascending order!")
                .setNeutralButton("Close", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dlg, int sumthin) {
                // do nothing – it will close on its own
                }
                })
                .show();   
            }



3.0 Excel Example:

3.1 Net present value - NPV


3.2 Internal rate of return - IRR



3.3 Net future value - NFV



3.4 Net present value - XNPV



3.5 Internal rate of return - XIRR



3.6 Net future value - XNFV



 4.0 Practical Application

4.1 Regular Period - Highway Project



 4.2 Irregular Period - Stock's return calculation



4.3 Bonus - Number of day between two dates calculation



5.0 Download - It is available at Android Market now. Search for FREENPVIRR from Application>Finance - Just in for free download. Enjoy!






Tuesday, August 17, 2010

Investment Exit plan - Decision Making Via XIRR and XNPV 2


Extended story from Miss K (http://seannchine.blogspot.com/2010/07/investment-exit-plan-decision-making.html)

Layman calculation:
1) Holding yield (HY) and Holding period yield (HPY).
It cant be used to compare with other annualized rate (Fixed Deposit rate, Inflation, GDP, etc.). For example, HY for the share from first investment 13-Aug-06 to 16-Aug-10 is (8.47-7.6)/7.6 = 11.44%; while second investment 28-Aug-07 is (8.47-7.24)/7.24 = 16.99%. Holding Period Yield (HPY) for the individual investment are 2.68% p.a.(11.44%/4) and 5.66% (16.99%/3) respectively. In this return calculation , however, dividends given from the subsequent years are not taken into account for the HY calculation.

2) Average Return
For a layman calculation, they take average cost which is (300*7.6+1700*7.24)/(300+1700) = 7.29. Today price, said 8.47, means HY is (8.47-7.29)/7.29 = 16.19%. Holding period yield over period (HPY) = 16.19%/4 = 4.05% p.a. if compares it with FD rate 3.25% p.a., then it is not a good investment if you ignore dividend (in the case, dividend from Share G is too less, it can be ignore). Something very wrong which is using 4 years as the denominator. emm...

3) Dividend Return
If we need to take the dividend into the account, then just sum up all dividend per share (DPS), which is 0.02+0.22+0.03+0.02+0.03+0.03 = 0.35. Dividend yield is 0.35/7.29/4 = 1.2% p.a.

4) Total Return
Thus, total return is return of appreciation + return of dividend yield = 4.05+1.2% = 5.25% p.a. It is not a successful investment because it has to offset with inflation which about 4% p.a. Layman’s Real return is 5.25% - 4% = 1.25%.

 
In the practical way, I mean time value of money, it shall be calculated in the cash flow which varies with date given. Thus, Compounded Annualized Growth Rate (CAGR) is calculated via XIRR = 6.47% p.a. Real return = (1+5.25%)/(1+4%)-1 =1.20%.

Miss K wants to sell it because it is one of the investments that not really contribute much for her portfolio's CAGR. To increase her portfolio's CAGR, she needs to liquidate it in order to buy another better return stock. Thus, solver, once again, is used to solve for the desired CAGR return for 8%, 10% and 15%. The exit plan is suggested to liquidate the share by selling it at RM9.40 if she aims for 10% CAGR, while RM10.83 at 15% CAGR.

Tuesday, July 27, 2010

REIT and Shop Lot Investment in Malaysia

Mr. E intends to invest in property after he receives an amount of sum assured from his deceased father's life insurance. With his own parent taught since his childhood, properties investment is the best investment vehicle that he can park his money in. Net receivable of the sum assured is RM100,000. Mr. E believes in conventional way to invest it in such way to "own" a shop physically at somewhere in the town. However, his wife receives information about REIT from his securities broker.  
 
REIT in Malaysia is not popular, even their DY (dividend yield) recorded 7% - 8% p.a. recently. This is due to limited appreciation of the stock value itself, around 4% p.a. It is about 13 REITs listed in Bursa Malaysia.

Case Study#1: Invest RM100,000 directly to "own" a 2-storey-shop lot at KL

Assumption:
Net rental income is the gross rental income of RM7,000 offset with taxes and maintenance, said RM6,000.




Case Study#2: Invest RM100,000 in REIT

Assumption:
1) dividend per unit paid in semiannual
2) dividend per unit growth at 5% p.a.
3) Capital appreciation at 5% p.a.

Finding:
Case Study#1:
IRR = 22.62% p.a.
NPV@6.5%p.a. = RM1,114,452.25 (Accepted)
Pro/con: 1) consistence monthly rental income that can against inflation, 2) Psychologically "own" the shop, feel more secure, 3) low liquidity, 4) Higher cost (lawyer fees etc), 5) higher return, 6) high maintenance, 7) committed to loan servicing  

Case Study#2:
IRR = 10.28% p.a.
NPV@3.25%p.a. = RM255,567.73 (Accepted)
Pro/con: 1) consistence semi annual dividend income that can against inflation, 2) liquidity very high, switch to other investment vehicle easier, 3) low brokerage fees, 4) lower return, 5) less maintenance, 6) No commitment

Present Value Evaluation (DDM) by using my expected return at 15% p.a.
Case Study#1:
P=D,o(1+g)/(r-g) = 12*6000(1+0.04)/(0.15-0.04) = RM680,727.30 (Assume freehold property)
Case Study#2:
P=D,o(1+g)/(r-g) = 2*2500(1+0.05)/(0.15-0.05) = RM52,500

Thursday, July 8, 2010

Investment Exit plan - Decision Making Via XIRR and XNPV

Miss K bought company G share about four years ago. Over years, she received dividend from company G semi annually. However, share price has no significant increase. Its range from RM6 to RM8. She has no idea on the calculation of the return of investment. Indecisively, she does not know how to make the move from it.

a) what is the CAGR of the share G investment? loss and gain?
b) does the invest worth to be kept if we take finance cost as the risk free rate of 4%p.a.?
c) does the invest worth to be kept if our expected rate is targeted as 15%p.a.?
d) if she wants to realize the loss/gain by taking finance cost as the risk free rate of 4%p.a. CAGR, what is the selling price for share G?

Solution:

Step 1: Tabulate the net cashflow in time series.
Step 2: Take the market value base on today price - make it liquidate by today (+ve sign)

a) what is the CAGR of the share G investment? loss and gain? 

Step 3:  Function XIRR is used to calculate CAGR. 1.31% gain p.a. is obtained, but it is lower than the risk free rate 4% p.a. The return 1.31% is bench-marked with 4% e.g. MGS or simply make it as 4% p.a. for fix deposit return.

b) does the invest worth to be kept if we take finance cost as the risk free rate of 4%p.a.?

Step 4: Function XNPV is used to make the investment feasibility. Positive NPV leads to make the decision to accept the project while negative NPV leads to reject the project. For the 4% p.a. benchmarking, the project has the net present value of -RM1041. Thus, we reject the project. So we should not keep the investment. We should realize the loss.

c) does the invest worth to be kept if our expected rate is targeted as 15%p.a.?

Step 5: For the 15% p.a. benchmarking, the project has the net present value of -RM3997. Thus, we reject the project. So we should not keep the investment. We should realize the loss. 15% p.a. is my favorite CAGR investment return. It is used to gauge my investment performance.

For those who had gone through the retirement and children education planning, desired return from the planning is used to benchmark the investment share G performance. For instance, Miss K desired an investment of CAGR 6% p.a., then she should use 6% to replace 15%.

d) if she wants to realize the loss/gain by taking finance cost as the risk free rate of 4%p.a. CAGR, what is the selling price for share G?
Step 6: Excel Solver is used to calculate liquidation price by fixing CAGR at 4% p.a. Thus, she should sell the company G at least higher than RM7.86 without suffer any loss.

See, as simple as ABC.





Thursday, June 10, 2010

Amortization in Excel 2: Smart Loan Malaysia Comparison



Recap: please read Amortization in Excel: Do You Know Your Loan Well?

Mortgage Refinancing Parameter: completed, Selangor, RM100,000 loan, conventional and Islamic loan, floating interest, 10-year-tenure, no flexi loan. BLR=6.05%p.a.

Loan Comparison Platform: http://www.smartloans.my

Let's compare the cheapest and most expansive package.

Example 1: Hong Leong Flexi Package (BLR-1.9%) - Cheapest
1) Interest Rate = RATE(nper,pmt,pv,fv,type)
= 12*Rate(12*10,-1020,100000,0,0) = 4.16% p.a.

2) Total Interest Paid for 10 years loan = CUMIPMT(rate,nper,pv,start_period,end_period,type)
= CUMIPMT(0.0416/12,12*10,1000
00,1,12*10,0) = -22,408.80

3) Ratio = (interest paid + principle)/principle
= (22408.80+100000)/100000 = 1.22.

Example 2: Standard Chartered - Standard Term Loan - Most Expansive
How to calculate the Standard Chartered - Standard Term Loan?
Uneven cashflow is determined in the study via XIRR.
First 1 year: RM1,022, Next 4 years: RM1,025, thereafter RM1,205. Bank always confuses his customer, and it leads to difficult way to compare with others.





1) IRR = 5.99%p.a.

2) Total Interest Paid for 10 years loan = CUMIPMT(rate,nper,pv,star
t_period,end_period,type)
= CUMIPMT(0.0599/12,12*10,1000
00,1,12*10,0) = -33164.43.

3) Ratio = (interest paid + principle)/principle
= (33164.43+100000)/100000 = 1.33.

Saturday, May 1, 2010

Investment Planning: XNPV and XIRR

For uneven cashflow, the best method to calculate the IRR and NPV, excel is the best.
NPV is the net of the discounted CF,j at expected return which relative to present day.
NFV is the net of the compounded CF,j at expected return which relative to future.

Expected return could be risk free rate, inflation, or anything that yu think you need for other evaluation.

This means every project has a NFV and NPV that is use to evaluate the profitability of a project. The project that we discuss here may be investment in equity, UT, real estate, business... that I will share it to you later.

Example 1: A project with 8-years cash flow is tabulated in the table. The table indicates the project have a positive NPV@15% p.a and a positive NFV@15%.
Rules of thumb, based on your expected return input to NPV, said 15%, the discounted for net cashflow produces a positive value. Then, we might accept the project. However, to be specific, IRR has a better meaning than NPV.

IRR is calculated based on the assumption of NPV=0. It is the powerful decision making tool that help me to make the judgment what investment instrument is preferred. IT is termed as CAGR, annualized return, APR, ROI...

However, that was taught from lecturer. I met CFP module 1-6 lecturers, they never mention about XIRR and XNPV. It maybe they do not use XIRR in investment module or maybe they do not even know about EXCEL.

Example 2: In reality, our actual cashflow is complicated (see table 2).The inflow and outflow of a portfolio with different counter are sorted in the table (NOTE: No sorting will return with a wrong IRR, Microsoft shall improve on this XIRR function).Thus, this portfolio has a positive NPV at expected return 15% p.a CAGR. Now, date of transaction is considered in calculation too. You have to liquidate your portfolio, said now.



XIRR is higher than my expected return 15% CAGR but in CFP, lesser than 12% is recommended in calculation. In bullish market, IRR of an aggressive portfolio could simply over 30% p.a, while in bearish it could even lower than -15% p.a We use IRR to compare with the economic indicator not direct return. Direct return has not specific time frame.

Example 3: Bond's coupon rate versus yield-to-maturity. To calculate the CAGR, we all use XIRR for the semiannual coupon. Thus, XIRR takes into the consideration of actual date payment while YTM assumes 360 days a year, or 30 days a month.



Example 4: Project A, B and C comparison.

Obviously,IRR evaluation for the uneven cashflow indicates project A has higher IRR than others. This is how decision is made.


Example 5: Deferred Annuity
You will surprise that the example of the deferred annuity will have a slightly higher IRR that FD rate. However, the only advantages that it could provide is the insurance component built-in inside the policy. For cost effectiveness, UT+termed life maybe have a better return then the annuity.


For 1ook investment, IRR,low = 1.63%, IRR,high = 4.76%, IRR,- = 1.34%
Total,low = RM151,972, Total,high = RM 422,917, Total,- = 140,000.
How about I put 100k to FD and I withdraw 7k yearly at my age 56?
so, what do you think about this annuity product? hmmm.... does your agent know about the fact? hmmm....



Example 6: Have you ever heard about the crab breeding? How NPV and IRR are used in the decision making. Crab breeding is just a background. Capture all the inflow and outflow that expected in the operation. Budget for the business, duration, escape plan .... can be considered inside the plan.
From the plan, you would notice that you have no income that can last for at least 6 months!!! So then you enjoy the value of IRR!!!



Diverted original posting from my facebook note dated 13-Nov-09.