# tablepress/3.4/libraries/vendor/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php

TablePress – Tables in WordPress made easy, version 3.4. 134 lines.

- Page: https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php
- Raw: https://pluginprobe.com/plugins/tablepress/3.4/raw/libraries/vendor/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php
- Modified: 2025-08-26T04:06:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php#L10-L20`.

```php
<?php

namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities;

use TablePress\PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception;
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Functions;
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use TablePress\PhpOffice\PhpSpreadsheet\Shared\StringHelper;

class Rates
{
	/**
				 * DISC.
				 *
				 * Returns the discount rate for a security.
				 *
				 * Excel Function:
				 *        DISC(settlement,maturity,price,redemption[,basis])
				 *
				 * @param mixed $settlement The security's settlement date.
				 *                              The security settlement date is the date after the issue
				 *                                  date when the security is traded to the buyer.
				 * @param mixed $maturity The security's maturity date.
				 *                            The maturity date is the date when the security expires.
				 * @param mixed $price The security's price per $100 face value
				 * @param mixed $redemption The security's redemption value per $100 face value
				 * @param mixed $basis The type of day count to use.
				 *                         0 or omitted    US (NASD) 30/360
				 *                         1               Actual/actual
				 *                         2               Actual/360
				 *                         3               Actual/365
				 *                         4               European 30/360
				 * @return float|string
				 */
				public static function discount(
		$settlement,
		$maturity,
		$price,
		$redemption,
		$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
	) {
		$settlement = Functions::flattenSingleValue($settlement);
		$maturity = Functions::flattenSingleValue($maturity);
		$price = Functions::flattenSingleValue($price);
		$redemption = Functions::flattenSingleValue($redemption);
		$basis = Functions::flattenSingleValue($basis) ?? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD;

		try {
			$settlement = SecurityValidations::validateSettlementDate($settlement);
			$maturity = SecurityValidations::validateMaturityDate($maturity);
			SecurityValidations::validateSecurityPeriod($settlement, $maturity);
			$price = SecurityValidations::validatePrice($price);
			$redemption = SecurityValidations::validateRedemption($redemption);
			$basis = SecurityValidations::validateBasis($basis);
		} catch (Exception $e) {
			return $e->getMessage();
		}

		if ($price <= 0.0) {
			return ExcelError::NAN();
		}

		$daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis));
		if (!is_numeric($daysBetweenSettlementAndMaturity)) {
			//    return date error
			return StringHelper::convertToString($daysBetweenSettlementAndMaturity);
		}

		return (1 - $price / $redemption) / $daysBetweenSettlementAndMaturity;
	}

	/**
				 * 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.
				 *                              The security settlement date is the date after the issue date when the security
				 *                                  is traded to the buyer.
				 * @param mixed $maturity The security's maturity date.
				 *                            The maturity date is the date when the security expires.
				 * @param mixed $investment the amount invested in the security
				 * @param mixed $redemption the amount to be received at maturity
				 * @param mixed $basis The type of day count to use.
				 *                         0 or omitted    US (NASD) 30/360
				 *                         1               Actual/actual
				 *                         2               Actual/360
				 *                         3               Actual/365
				 *                         4               European 30/360
				 * @return float|string
				 */
				public static function interest(
		$settlement,
		$maturity,
		$investment,
		$redemption,
		$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
	) {
		$settlement = Functions::flattenSingleValue($settlement);
		$maturity = Functions::flattenSingleValue($maturity);
		$investment = Functions::flattenSingleValue($investment);
		$redemption = Functions::flattenSingleValue($redemption);
		$basis = Functions::flattenSingleValue($basis) ?? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD;

		try {
			$settlement = SecurityValidations::validateSettlementDate($settlement);
			$maturity = SecurityValidations::validateMaturityDate($maturity);
			SecurityValidations::validateSecurityPeriod($settlement, $maturity);
			$investment = SecurityValidations::validateFloat($investment);
			$redemption = SecurityValidations::validateRedemption($redemption);
			$basis = SecurityValidations::validateBasis($basis);
		} catch (Exception $e) {
			return $e->getMessage();
		}

		if ($investment <= 0) {
			return ExcelError::NAN();
		}

		$daysBetweenSettlementAndMaturity = Functions::scalar(DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis));
		if (!is_numeric($daysBetweenSettlementAndMaturity)) {
			//    return date error
			return StringHelper::convertToString($daysBetweenSettlementAndMaturity);
		}

		return (($redemption / $investment) - 1) / ($daysBetweenSettlementAndMaturity);
	}
}

```
