# payback period calculation in R

I need to calculate payback period in R. I set it up like this:
...
library(FinancialMath)

initial_investment <- 63

annual_cash_flows <- c(-140,...-130) [all the cash flows are negative for 20 years)

payback_period <- initial_investment / annual_cash_flows

payback_period: -0.4978229

...
Is the no -.49 alright? or is there something wrong with it? how can i interpret it please?

I think you want

payback_period <- initial_investment / mean(annual_cash_flows)

where both initial investment and each annual cash flow is positive. So payback period is 63/135 = .47, or about half a year.

I don't think you need library(FinancialMath) for this.

• i is the periodic rate
• PV is the present value of the amount borrowed/lent, also called principal
• PMT is the periodic payment (negative paid/positive received)
• FV is the amount remaining, if any, at the end

To solve for n: i, PV and PMT must be known and FV if not zero, as in the case of a balloon period.

The example lacks i, so i could be zero. A no-interest loan with a PV of 63 with an initial annual payment of -140 (repaid) would be paid off in year 1, leaving an FV of 37.

The calculations depend also on whether payments occur either in arrears or in advance. Loans can be amortizing (a portion of each payment reduces the outstanding principal balance after i is applied to the outstanding balance), or paid at the end, with periodic interest collected during each period.

The length of time as expressed as a multiple of n depends on knowing what interval n is measured in. A loan could be, if permitted by the terms of the loan, be prepaid in whole or in part at any time, in which case n could represent a fractional period for the final period.

Definitionally, a loan cannot be paid before it is taken, so the negative result even if correctly calculated lacks meaning.

As it stands the problem is under-specified and the meaning of payback period should be more clearly defined before attempting to calculate it.

1 Like

I am a little surprised at the -.49. It looks like you should be getting 63/(-140), which isn't -.49.

The payback period would generally be the number of payments before you break even. If you make a positive investment and have negative cashflow, you never break even.

In addition, payback period sometimes requires discounting for the present value of cashflows.

Hi Startz and technocrat,

I thought payback period is based on average cash flows and disregards the time value of money.

The link you give says to divide by the annual cashflow. That makes sense if the annual cashflow is constant, as it is for many financial instruments. (And then your formula works perfectly.) But suppose all the payback is at the end. It doesn't make sense to say the payback period is halfway through.

Just to clarify, the initial investment is 69.7375

I have calculated NPV and it is -1096.

Now I need to calculate payback period (not the discounted payback period).

I have annual cash flows of 20 years like this: -140.0849, -140.1475, -140.2285, -140.3113, -140.4059, -140.5058, -140.6408, -140.7762, -140.9418, -141.1327, -136.3924, -136.3924, -136.3924,-136.3924, -136.3924, -136.3924, -136.3924, -136.3924, -136.3924, -136.3924.

So now, how can I calculate payback period here, please? My formula payback_period <- initial_investment / annual_cash_flows gives me -.49, which does not make sense. So what should I do please?

someone invests 69; lets say 70\$
They are expected to receive annual payments of approx 140\$ each year for 20 years ?
That does seem very unlikely. but we can do fantasy math I'd say if the first payment receive effectively paid off the initial investment; then the payback period is effectively `1`; that first year waiting for the first payment.

``````ceiling(69.7375 /
140.0849)
``````

note that the cash flow values; are considered from a perspective; from the perspective of the debtor; them owing an annual payment of 100\$ would be written in their ledger as -100\$ each time; but to to the creditor its a credit and would be 100\$; ie. the first payment to the creditor is 140.0849 not -140.0849

My bad, I'm a finance buy, not an investment guy. Sort of like the difference between NFL and Fantasy Football.

1 Like

For a second, stop thinking about R. It sounds like you put out 70\$ and then lose 140\$ a year for a while. Is that what you mean? If it is, then the investment is never paid back. If, following along with @nirgrahamuk, you put out 70\$ and get paid back 140\$ the first year, then the payback period is 1.

Neither of these, outside of fantasy and intentionally tricky homework assignments, makes much sense.

1 Like

Note that i have said NPV is hugely negative. so when I say initial investment is 63 dollar and then the cash flows of 20 years are like this: -140.0849, -140.1475, -140.2285, -140.3113, -140.4059, -140.5058, -140.6408, -140.7762, -140.9418, -141.1327, -136.3924, -136.3924, -136.3924,-136.3924, -136.3924, -136.3924, -136.3924, -136.3924, -136.3924, -136.3924. so the investment is never paid off. so payback period can be negative, is it alright or not?

This is not an assignment, rather my thesis work.

If the investment is never paid off then the payback period is infinite.

What is the investment instrument here... ?

What do you mean by investment instrument?

@ibrahimecon, is this a make-believe problem (nothing wrong with that) or are you studying a real investment? If it's the latter, if you can say more about it you might get more helpful advice.

Stocks. Stocks, also known as shares or equities, might be the most well-known and simple type of investment. ...
Bonds. ...
Mutual Funds. ...
Certificates of Deposit (CDs) ...
Retirement Plans. ...
Options. ...
Annuities.

The data are from literature that has examined the financial viability of biojet project. So the data come from different literature, those literature used historical average for cost and revenue variables or single year value.

These are the codes by which i have generated the cash flows:
..
amort <- amort.table(Loan=capex*debt,n=t_loan,pmt=NA,r_dis)[["Schedule"]]
CF1 <- as.data.frame(amort) # cash flow for Y1-10
CF1\$Depreciation <- dep

CF2 <- CF1*0 # cash flow for Y11-20
CF <- rbind(CF1,CF2)
...

Part of what is confusing is that if the revenue is always negative, then the project isn't financially viable. No further analysis is needed.

payback period is when you get back your initial investment. Normally, it is calculated using the nominal cashflow (i.e non discounted cashflow).

for example: initial investment: 100. cashflow year 1: 10, year 2: 20, year 3: 50, year 4: 40, then payback period is 3.5 years. in other words, in 3.5 year, the initial investment - cumulative cashflow equals to zero.

in your specific case, the cashflow is negative. thus, the project needs to have additional funding / investment for it to continue, otherwise, it will just go bust. and since after all the time period (20 years), it is still negative (the cumulative cashflow), then the project never pays back (i.e there is no payback).

this has actually had nothing to do with R. but the calculation I suppose require some looping to find out when investment - cumulative cashflow equals zero.

Thanks for your response. Could you please let me know how I can calculate payback period in R? Are the following right codes to calculate payback period?

initial_investment <- 63

annual_cash_flows <- c(-140,...-130) [all the cash flows are negative for 20 years)

payback_period <- initial_investment / annual_cash_flows