Finance namespace

You're viewing an older version of this page (#5600). View the current version.

View versions (2)

Interface

#include <codecogs/finance/accounting/depreciation.h>

using namespace Finance::Accounting;

This function calculates the depreciation of an asset for a specified period, using the double-declining balance method (or, more generally, any fixed-rate declining balance method controlled by fact). This function is equivalent to the Microsoft Excel function DDB. It works on the following equation, applied successively for each period up to and including per:

$$deprec = (cost-prevTot)*rate$$
(1)

where:

$$rate = \frac{fact}{life}$$
(2)

and prevTot is the total depreciation accumulated over all previous periods (so the declining rate is always applied to the asset's remaining book value, cost - prevTot). The one exception is the final period before the asset reaches its salvage value: for that period, the depreciation is capped so that the asset's book value never drops below valSalv, i.e.:

$$deprec = \min\left( (cost-prevTot)*rate,\ \ cost-prevTot-salv \right)$$
(3)

Where:

  • salv is the salvage value of the asset,
  • cost is the initial cost of the asset,
  • life is the number of periods over which the asset is being depreciated,
  • fact is the declining-balance rate factor (2.0 for the standard "double" declining balance method),
  • prevTot is the total depreciation from previous periods.

Example 1

The following code calculates the double-declining balance depreciation, for each of the first 10 years, of an asset costing 2400 with a salvage value of 300 and a useful life of 10 years (this is the worked example from Microsoft's own DDB documentation, used here to cross-check the two implementations).

#include <stdio.h>
#include <codecogs/finance/accounting/depreciation.h>

int main(void)
{
  double costVal=2400;
  double salvVal=300;
  int lifeVal=10;

  printf("Cost\tSalvage\tLife\tPeriod\tDepreciation\n");

  for (int per=1; per<=lifeVal; ++per)
  {
    printf("%.0f\t%.0f\t%i\t%i\t%f\n",
           costVal,
           salvVal,
           lifeVal,
           per,
           Finance::Accounting::depreciation(costVal, salvVal, lifeVal, per));
  }

  return 0;
}

Output:

Cost	Salvage	Life	Period	Depreciation
2400	300	10	1	480.000000
2400	300	10	2	384.000000
2400	300	10	3	307.200000
2400	300	10	4	245.760000
2400	300	10	5	196.608000
2400	300	10	6	157.286400
2400	300	10	7	125.829120
2400	300	10	8	100.663296
2400	300	10	9	80.530637
2400	300	10	10	22.122547

Parameters

valCost
The initial cost of the asset.
valSalv
The salvage value of the asset at the end of its life.
life
The is the number of periods over which the asset is being depreciated (sometimes called the useful life of the asset).
per
The period for which you want to calculate the depreciation. per must have the same units as life.
fact
The rate at which the balance declines. Defaults to 2.0, giving the standard double-declining balance method; a value of 1.5 gives the 150%-declining balance method, etc.

Returns

The depreciation for each accounting period.

References

http://www.vni.com/products/imsl/jmsl/v30/api/

GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

valCost
valSalv
life
per
fact
Result