Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

(no description)

File Size: 2475 lines (100 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Financial:: (60 methods):
  isLastDayOfMonth()
  couponFirstPeriodDate()
  isValidFrequency()
  daysPerYear()
  interestAndPrincipal()
  ACCRINT()
  ACCRINTM()
  AMORDEGRC()
  AMORLINC()
  COUPDAYBS()
  COUPDAYS()
  COUPDAYSNC()
  COUPNCD()
  COUPNUM()
  COUPPCD()
  CUMIPMT()
  CUMPRINC()
  DB()
  DDB()
  DISC()
  DOLLARDE()
  DOLLARFR()
  EFFECT()
  FV()
  FVSCHEDULE()
  INTRATE()
  IPMT()
  IRR()
  ISPMT()
  MIRR()
  NOMINAL()
  NPER()
  NPV()
  PDURATION()
  PMT()
  PPMT()
  validatePrice()
  PRICE()
  PRICEDISC()
  PRICEMAT()
  PV()
  RATE()
  rateNextGuess()
  RECEIVED()
  RRI()
  SLN()
  SYD()
  TBILLEQ()
  TBILLPRICE()
  TBILLYIELD()
  bothNegAndPos()
  xirrPart2()
  xirrPart1()
  xirrPart3()
  XIRR()
  XNPV()
  validateXnpv()
  xnpvOrdered()
  YIELDDISC()
  YIELDMAT()


Class: Financial  - X-Ref

isLastDayOfMonth(\DateTime $testDate)   X-Ref
isLastDayOfMonth.

Returns a boolean TRUE/FALSE indicating if this date is the last date of the month

param: \DateTime $testDate The date for testing
return: bool

couponFirstPeriodDate($settlement, $maturity, $frequency, $next)   X-Ref
No description

isValidFrequency($frequency)   X-Ref
No description

daysPerYear($year, $basis = 0)   X-Ref
daysPerYear.

Returns the number of days in a specified year, as defined by the "basis" value

param: int|string $year The year against which we're testing
param: int|string $basis The type of day count:
return: int|string Result, or a string containing an error

interestAndPrincipal($rate = 0, $per = 0, $nper = 0, $pv = 0, $fv = 0, $type = 0)   X-Ref
No description

ACCRINT($issue, $firstinterest, $settlement, $rate, $par = 1000, $frequency = 1, $basis = 0)   X-Ref
ACCRINT.

Returns the accrued interest for a security that pays periodic interest.

Excel Function:
ACCRINT(issue,firstinterest,settlement,rate,par,frequency[,basis])

param: mixed $issue the security's issue date
param: mixed $firstinterest the security's first interest date
param: mixed $settlement The security's settlement date.
param: float $rate the security's annual coupon rate
param: float $par The security's par value.
param: int $frequency the number of coupon payments per year.
param: int $basis The type of day count to use.
return: float|string Result, or a string containing an error

ACCRINTM($issue, $settlement, $rate, $par = 1000, $basis = 0)   X-Ref
ACCRINTM.

Returns the accrued interest for a security that pays interest at maturity.

Excel Function:
ACCRINTM(issue,settlement,rate[,par[,basis]])

param: mixed $issue The security's issue date
param: mixed $settlement The security's settlement (or maturity) date
param: float $rate The security's annual coupon rate
param: float $par The security's par value.
param: int $basis The type of day count to use.
return: float|string Result, or a string containing an error

AMORDEGRC($cost, $purchased, $firstPeriod, $salvage, $period, $rate, $basis = 0)   X-Ref
AMORDEGRC.

Returns the depreciation for each accounting period.
This function is provided for the French accounting system. If an asset is purchased in
the middle of the accounting period, the prorated depreciation is taken into account.
The function is similar to AMORLINC, except that a depreciation coefficient is applied in
the calculation depending on the life of the assets.
This function will return the depreciation until the last period of the life of the assets
or until the cumulated value of depreciation is greater than the cost of the assets minus
the salvage value.

Excel Function:
AMORDEGRC(cost,purchased,firstPeriod,salvage,period,rate[,basis])

param: float $cost The cost of the asset
param: mixed $purchased Date of the purchase of the asset
param: mixed $firstPeriod Date of the end of the first period
param: mixed $salvage The salvage value at the end of the life of the asset
param: float $period The period
param: float $rate Rate of depreciation
param: int $basis The type of day count to use.
return: float

AMORLINC($cost, $purchased, $firstPeriod, $salvage, $period, $rate, $basis = 0)   X-Ref
AMORLINC.

Returns the depreciation for each accounting period.
This function is provided for the French accounting system. If an asset is purchased in
the middle of the accounting period, the prorated depreciation is taken into account.

Excel Function:
AMORLINC(cost,purchased,firstPeriod,salvage,period,rate[,basis])

param: float $cost The cost of the asset
param: mixed $purchased Date of the purchase of the asset
param: mixed $firstPeriod Date of the end of the first period
param: mixed $salvage The salvage value at the end of the life of the asset
param: float $period The period
param: float $rate Rate of depreciation
param: int $basis The type of day count to use.
return: float

COUPDAYBS($settlement, $maturity, $frequency, $basis = 0)   X-Ref
COUPDAYBS.

Returns the number of days from the beginning of the coupon period to the settlement date.

Excel Function:
COUPDAYBS(settlement,maturity,frequency[,basis])

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: int $frequency the number of coupon payments per year.
param: int $basis The type of day count to use.
return: float|string

COUPDAYS($settlement, $maturity, $frequency, $basis = 0)   X-Ref
COUPDAYS.

Returns the number of days in the coupon period that contains the settlement date.

Excel Function:
COUPDAYS(settlement,maturity,frequency[,basis])

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: mixed $frequency the number of coupon payments per year.
param: int $basis The type of day count to use.
return: float|string

COUPDAYSNC($settlement, $maturity, $frequency, $basis = 0)   X-Ref
COUPDAYSNC.

Returns the number of days from the settlement date to the next coupon date.

Excel Function:
COUPDAYSNC(settlement,maturity,frequency[,basis])

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: mixed $frequency the number of coupon payments per year.
param: int $basis The type of day count to use.
return: float|string

COUPNCD($settlement, $maturity, $frequency, $basis = 0)   X-Ref
COUPNCD.

Returns the next coupon date after the settlement date.

Excel Function:
COUPNCD(settlement,maturity,frequency[,basis])

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: mixed $frequency the number of coupon payments per year.
param: int $basis The type of day count to use.
return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,

COUPNUM($settlement, $maturity, $frequency, $basis = 0)   X-Ref
COUPNUM.

Returns the number of coupons payable between the settlement date and maturity date,
rounded up to the nearest whole coupon.

Excel Function:
COUPNUM(settlement,maturity,frequency[,basis])

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: mixed $frequency the number of coupon payments per year.
param: int $basis The type of day count to use.
return: int|string

COUPPCD($settlement, $maturity, $frequency, $basis = 0)   X-Ref
COUPPCD.

Returns the previous coupon date before the settlement date.

Excel Function:
COUPPCD(settlement,maturity,frequency[,basis])

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: mixed $frequency the number of coupon payments per year.
param: int $basis The type of day count to use.
return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,

CUMIPMT($rate, $nper, $pv, $start, $end, $type = 0)   X-Ref
CUMIPMT.

Returns the cumulative interest paid on a loan between the start and end periods.

Excel Function:
CUMIPMT(rate,nper,pv,start,end[,type])

param: float $rate The Interest rate
param: int $nper The total number of payment periods
param: float $pv Present Value
param: int $start The first period in the calculation.
param: int $end the last period in the calculation
param: int $type A number 0 or 1 and indicates when payments are due:
return: float|string

CUMPRINC($rate, $nper, $pv, $start, $end, $type = 0)   X-Ref
CUMPRINC.

Returns the cumulative principal paid on a loan between the start and end periods.

Excel Function:
CUMPRINC(rate,nper,pv,start,end[,type])

param: float $rate The Interest rate
param: int $nper The total number of payment periods
param: float $pv Present Value
param: int $start The first period in the calculation.
param: int $end the last period in the calculation
param: int $type A number 0 or 1 and indicates when payments are due:
return: float|string

DB($cost, $salvage, $life, $period, $month = 12)   X-Ref
DB.

Returns the depreciation of an asset for a specified period using the
fixed-declining balance method.
This form of depreciation is used if you want to get a higher depreciation value
at the beginning of the depreciation (as opposed to linear depreciation). The
depreciation value is reduced with every depreciation period by the depreciation
already deducted from the initial cost.

Excel Function:
DB(cost,salvage,life,period[,month])

param: float $cost Initial cost of the asset
param: float $salvage Value at the end of the depreciation.
param: int $life Number of periods over which the asset is depreciated.
param: int $period The period for which you want to calculate the
param: int $month Number of months in the first year. If month is omitted,
return: float|string

DDB($cost, $salvage, $life, $period, $factor = 2.0)   X-Ref
DDB.

Returns the depreciation of an asset for a specified period using the
double-declining balance method or some other method you specify.

Excel Function:
DDB(cost,salvage,life,period[,factor])

param: float $cost Initial cost of the asset
param: float $salvage Value at the end of the depreciation.
param: int $life Number of periods over which the asset is depreciated.
param: int $period The period for which you want to calculate the
param: float $factor The rate at which the balance declines.
return: float|string

DISC($settlement, $maturity, $price, $redemption, $basis = 0)   X-Ref
DISC.

Returns the discount rate for a security.

Excel Function:
DISC(settlement,maturity,price,redemption[,basis])

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: int $price The security's price per $100 face value
param: int $redemption The security's redemption value per $100 face value
param: int $basis The type of day count to use.
return: float|string

DOLLARDE($fractional_dollar = null, $fraction = 0)   X-Ref
DOLLARDE.

Converts a dollar price expressed as an integer part and a fraction
part into a dollar price expressed as a decimal number.
Fractional dollar numbers are sometimes used for security prices.

Excel Function:
DOLLARDE(fractional_dollar,fraction)

param: float $fractional_dollar Fractional Dollar
param: int $fraction Fraction
return: float|string

DOLLARFR($decimal_dollar = null, $fraction = 0)   X-Ref
DOLLARFR.

Converts a dollar price expressed as a decimal number into a dollar price
expressed as a fraction.
Fractional dollar numbers are sometimes used for security prices.

Excel Function:
DOLLARFR(decimal_dollar,fraction)

param: float $decimal_dollar Decimal Dollar
param: int $fraction Fraction
return: float|string

EFFECT($nominal_rate = 0, $npery = 0)   X-Ref
EFFECT.

Returns the effective interest rate given the nominal rate and the number of
compounding payments per year.

Excel Function:
EFFECT(nominal_rate,npery)

param: float $nominal_rate Nominal interest rate
param: int $npery Number of compounding payments per year
return: float|string

FV($rate = 0, $nper = 0, $pmt = 0, $pv = 0, $type = 0)   X-Ref
FV.

Returns the Future Value of a cash flow with constant payments and interest rate (annuities).

Excel Function:
FV(rate,nper,pmt[,pv[,type]])

param: float $rate The interest rate per period
param: int $nper Total number of payment periods in an annuity
param: float $pmt The payment made each period: it cannot change over the
param: float $pv present Value, or the lump-sum amount that a series of
param: int $type A number 0 or 1 and indicates when payments are due:
return: float|string

FVSCHEDULE($principal, $schedule)   X-Ref
FVSCHEDULE.

Returns the future value of an initial principal after applying a series of compound interest rates.
Use FVSCHEDULE to calculate the future value of an investment with a variable or adjustable rate.

Excel Function:
FVSCHEDULE(principal,schedule)

param: float $principal the present value
param: float[] $schedule an array of interest rates to apply
return: float

INTRATE($settlement, $maturity, $investment, $redemption, $basis = 0)   X-Ref
INTRATE.

Returns the interest rate for a fully invested security.

Excel Function:
INTRATE(settlement,maturity,investment,redemption[,basis])

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: int $investment the amount invested in the security
param: int $redemption the amount to be received at maturity
param: int $basis The type of day count to use.
return: float|string

IPMT($rate, $per, $nper, $pv, $fv = 0, $type = 0)   X-Ref
IPMT.

Returns the interest payment for a given period for an investment based on periodic, constant payments and a constant interest rate.

Excel Function:
IPMT(rate,per,nper,pv[,fv][,type])

param: float $rate Interest rate per period
param: int $per Period for which we want to find the interest
param: int $nper Number of periods
param: float $pv Present Value
param: float $fv Future Value
param: int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period
return: float|string

IRR($values, $guess = 0.1)   X-Ref
IRR.

Returns the internal rate of return for a series of cash flows represented by the numbers in values.
These cash flows do not have to be even, as they would be for an annuity. However, the cash flows must occur
at regular intervals, such as monthly or annually. The internal rate of return is the interest rate received
for an investment consisting of payments (negative values) and income (positive values) that occur at regular
periods.

Excel Function:
IRR(values[,guess])

param: float[] $values An array or a reference to cells that contain numbers for which you want
param: float $guess A number that you guess is close to the result of IRR
return: float|string

ISPMT(...$args)   X-Ref
ISPMT.

Returns the interest payment for an investment based on an interest rate and a constant payment schedule.

Excel Function:
=ISPMT(interest_rate, period, number_payments, PV)

interest_rate is the interest rate for the investment

period is the period to calculate the interest rate.  It must be betweeen 1 and number_payments.

number_payments is the number of payments for the annuity

PV is the loan amount or present value of the payments

MIRR($values, $finance_rate, $reinvestment_rate)   X-Ref
MIRR.

Returns the modified internal rate of return for a series of periodic cash flows. MIRR considers both
the cost of the investment and the interest received on reinvestment of cash.

Excel Function:
MIRR(values,finance_rate, reinvestment_rate)

param: float[] $values An array or a reference to cells that contain a series of payments and
param: float $finance_rate The interest rate you pay on the money used in the cash flows
param: float $reinvestment_rate The interest rate you receive on the cash flows as you reinvest them
return: float|string Result, or a string containing an error

NOMINAL($effect_rate = 0, $npery = 0)   X-Ref
NOMINAL.

Returns the nominal interest rate given the effective rate and the number of compounding payments per year.

param: float $effect_rate Effective interest rate
param: int $npery Number of compounding payments per year
return: float|string Result, or a string containing an error

NPER($rate = 0, $pmt = 0, $pv = 0, $fv = 0, $type = 0)   X-Ref
NPER.

Returns the number of periods for a cash flow with constant periodic payments (annuities), and interest rate.

param: float $rate Interest rate per period
param: int $pmt Periodic payment (annuity)
param: float $pv Present Value
param: float $fv Future Value
param: int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period
return: float|string Result, or a string containing an error

NPV(...$args)   X-Ref
NPV.

Returns the Net Present Value of a cash flow series given a discount rate.

return: float

PDURATION($rate = 0, $pv = 0, $fv = 0)   X-Ref
PDURATION.

Calculates the number of periods required for an investment to reach a specified value.

param: float $rate Interest rate per period
param: float $pv Present Value
param: float $fv Future Value
return: float|string Result, or a string containing an error

PMT($rate = 0, $nper = 0, $pv = 0, $fv = 0, $type = 0)   X-Ref
PMT.

Returns the constant payment (annuity) for a cash flow with a constant interest rate.

param: float $rate Interest rate per period
param: int $nper Number of periods
param: float $pv Present Value
param: float $fv Future Value
param: int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period
return: float|string Result, or a string containing an error

PPMT($rate, $per, $nper, $pv, $fv = 0, $type = 0)   X-Ref
PPMT.

Returns the interest payment for a given period for an investment based on periodic, constant payments and a constant interest rate.

param: float $rate Interest rate per period
param: int $per Period for which we want to find the interest
param: int $nper Number of periods
param: float $pv Present Value
param: float $fv Future Value
param: int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period
return: float|string Result, or a string containing an error

validatePrice($settlement, $maturity, $rate, $yield, $redemption, $frequency, $basis)   X-Ref
No description

PRICE($settlement, $maturity, $rate, $yield, $redemption, $frequency, $basis = 0)   X-Ref
No description

PRICEDISC($settlement, $maturity, $discount, $redemption, $basis = 0)   X-Ref
PRICEDISC.

Returns the price per $100 face value of a discounted security.

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: int $discount The security's discount rate
param: int $redemption The security's redemption value per $100 face value
param: int $basis The type of day count to use.
return: float|string Result, or a string containing an error

PRICEMAT($settlement, $maturity, $issue, $rate, $yield, $basis = 0)   X-Ref
PRICEMAT.

Returns the price per $100 face value of a security that pays interest at maturity.

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: mixed $issue The security's issue date
param: int $rate The security's interest rate at date of issue
param: int $yield The security's annual yield
param: int $basis The type of day count to use.
return: float|string Result, or a string containing an error

PV($rate = 0, $nper = 0, $pmt = 0, $fv = 0, $type = 0)   X-Ref
PV.

Returns the Present Value of a cash flow with constant payments and interest rate (annuities).

param: float $rate Interest rate per period
param: int $nper Number of periods
param: float $pmt Periodic payment (annuity)
param: float $fv Future Value
param: int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period
return: float|string Result, or a string containing an error

RATE($nper, $pmt, $pv, $fv = 0.0, $type = 0, $guess = 0.1)   X-Ref
RATE.

Returns the interest rate per period of an annuity.
RATE is calculated by iteration and can have zero or more solutions.
If the successive results of RATE do not converge to within 0.0000001 after 20 iterations,
RATE returns the #NUM! error value.

Excel Function:
RATE(nper,pmt,pv[,fv[,type[,guess]]])

param: float $nper The total number of payment periods in an annuity
param: float $pmt The payment made each period and cannot change over the life
param: float $pv The present value - the total amount that a series of future
param: float $fv The future value, or a cash balance you want to attain after
param: int $type A number 0 or 1 and indicates when payments are due:
param: float $guess Your guess for what the rate will be.
return: float|string

rateNextGuess($rate, $nper, $pmt, $pv, $fv, $type)   X-Ref
No description

RECEIVED($settlement, $maturity, $investment, $discount, $basis = 0)   X-Ref
RECEIVED.

Returns the price per $100 face value of a discounted security.

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: int $investment The amount invested in the security
param: int $discount The security's discount rate
param: int $basis The type of day count to use.
return: float|string Result, or a string containing an error

RRI($nper = 0, $pv = 0, $fv = 0)   X-Ref
RRI.

Calculates the interest rate required for an investment to grow to a specified future value .

param: float $nper The number of periods over which the investment is made
param: float $pv Present Value
param: float $fv Future Value
return: float|string Result, or a string containing an error

SLN($cost, $salvage, $life)   X-Ref
SLN.

Returns the straight-line depreciation of an asset for one period

param: mixed $cost Initial cost of the asset
param: mixed $salvage Value at the end of the depreciation
param: mixed $life Number of periods over which the asset is depreciated
return: float|string Result, or a string containing an error

SYD($cost, $salvage, $life, $period)   X-Ref
SYD.

Returns the sum-of-years' digits depreciation of an asset for a specified period.

param: mixed $cost Initial cost of the asset
param: mixed $salvage Value at the end of the depreciation
param: mixed $life Number of periods over which the asset is depreciated
param: mixed $period Period
return: float|string Result, or a string containing an error

TBILLEQ($settlement, $maturity, $discount)   X-Ref
TBILLEQ.

Returns the bond-equivalent yield for a Treasury bill.

param: mixed $settlement The Treasury bill's settlement date.
param: mixed $maturity The Treasury bill's maturity date.
param: int $discount The Treasury bill's discount rate
return: float|string Result, or a string containing an error

TBILLPRICE($settlement, $maturity, $discount)   X-Ref
TBILLPRICE.

Returns the yield for a Treasury bill.

param: mixed $settlement The Treasury bill's settlement date.
param: mixed $maturity The Treasury bill's maturity date.
param: int $discount The Treasury bill's discount rate
return: float|string Result, or a string containing an error

TBILLYIELD($settlement, $maturity, $price)   X-Ref
TBILLYIELD.

Returns the yield for a Treasury bill.

param: mixed $settlement The Treasury bill's settlement date.
param: mixed $maturity The Treasury bill's maturity date.
param: int $price The Treasury bill's price per $100 face value
return: float|mixed|string

bothNegAndPos($neg, $pos)   X-Ref
No description

xirrPart2(&$values)   X-Ref
No description

xirrPart1(&$values, &$dates)   X-Ref
No description

xirrPart3($values, $dates, $x1, $x2)   X-Ref
No description

XIRR($values, $dates, $guess = 0.1)   X-Ref
XIRR.

Returns the internal rate of return for a schedule of cash flows that is not necessarily periodic.

Excel Function:
=XIRR(values,dates,guess)

param: float[] $values     A series of cash flow payments
param: mixed[] $dates      A series of payment dates
param: float $guess        An optional guess at the expected answer
return: float|mixed|string

XNPV($rate, $values, $dates)   X-Ref
XNPV.

Returns the net present value for a schedule of cash flows that is not necessarily periodic.
To calculate the net present value for a series of cash flows that is periodic, use the NPV function.

Excel Function:
=XNPV(rate,values,dates)

param: float $rate the discount rate to apply to the cash flows
param: float[] $values     A series of cash flows that corresponds to a schedule of payments in dates.
param: mixed[] $dates      A schedule of payment dates that corresponds to the cash flow payments.
return: float|mixed|string

validateXnpv($rate, $values, $dates)   X-Ref
No description

xnpvOrdered($rate, $values, $dates, $ordered = true)   X-Ref
No description

YIELDDISC($settlement, $maturity, $price, $redemption, $basis = 0)   X-Ref
YIELDDISC.

Returns the annual yield of a security that pays interest at maturity.

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: int $price The security's price per $100 face value
param: int $redemption The security's redemption value per $100 face value
param: int $basis The type of day count to use.
return: float|string Result, or a string containing an error

YIELDMAT($settlement, $maturity, $issue, $rate, $price, $basis = 0)   X-Ref
YIELDMAT.

Returns the annual yield of a security that pays interest at maturity.

param: mixed $settlement The security's settlement date.
param: mixed $maturity The security's maturity date.
param: mixed $issue The security's issue date
param: int $rate The security's interest rate at date of issue
param: int $price The security's price per $100 face value
param: int $basis The type of day count to use.
return: float|string Result, or a string containing an error