48 $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
53 $basis = ($basis === null)
54 ? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
60 self::validateCouponPeriod($settlement, $maturity);
64 return $e->getMessage();
68 if (is_string($daysPerYear)) {
71 $prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS);
73 if ($basis === FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL) {
74 return abs((
float) DateTimeExcel\
Days::between($prev, $settlement));
111 $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
116 $basis = ($basis === null)
117 ? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
123 self::validateCouponPeriod($settlement, $maturity);
127 return $e->getMessage();
131 case FinancialConstants::BASIS_DAYS_PER_YEAR_365:
133 return 365 / $frequency;
134 case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL:
136 if ($frequency == FinancialConstants::FREQUENCY_ANNUAL) {
139 return $daysPerYear / $frequency;
141 $prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS);
142 $next = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_NEXT);
144 return $next - $prev;
147 return 360 / $frequency;
182 $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
187 $basis = ($basis === null)
188 ? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
194 self::validateCouponPeriod($settlement, $maturity);
198 return $e->getMessage();
202 $next = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_NEXT);
204 if ($basis === FinancialConstants::BASIS_DAYS_PER_YEAR_NASD) {
205 $settlementDate = Date::excelToDateTimeObject($settlement);
207 if ($settlementEoM) {
247 $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
252 $basis = ($basis === null)
253 ? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
259 self::validateCouponPeriod($settlement, $maturity);
263 return $e->getMessage();
266 return self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_NEXT);
301 $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
306 $basis = ($basis === null)
307 ? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
313 self::validateCouponPeriod($settlement, $maturity);
317 return $e->getMessage();
323 FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
326 return (
int) ceil((
float) $yearsBetweenSettlementAndMaturity * $frequency);
361 $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
366 $basis = ($basis === null)
367 ? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
373 self::validateCouponPeriod($settlement, $maturity);
377 return $e->getMessage();
380 return self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS);
385 $result->setDate((
int) $result->format(
'Y'), (int) $result->format(
'm'), 1);
386 $result->modify(
"$plusOrMinus $months months");
387 $daysInMonth = (int) $result->format(
't');
388 $result->setDate((
int) $result->format(
'Y'), (int) $result->format(
'm'), $lastDayFlag ? $daysInMonth : min($day, $daysInMonth));
391 private static function couponFirstPeriodDate(
float $settlement,
float $maturity,
int $frequency,
bool $next): float
393 $months = 12 / $frequency;
395 $result = Date::excelToDateTimeObject($maturity);
396 $day = (int)
$result->format(
'd');
399 while ($settlement < Date::PHPToExcel(
$result)) {
400 self::monthsDiff(
$result, $months,
'-', $day, $lastDayFlag);
402 if ($next ===
true) {
403 self::monthsDiff(
$result, $months,
'+', $day, $lastDayFlag);
406 return (
float) Date::PHPToExcel(
$result);
411 if ($settlement >= $maturity) {
static isLastDayOfMonth(DateTimeInterface $date)
isLastDayOfMonth.
static monthsDiff(DateTime $result, int $months, string $plusOrMinus, int $day, bool $lastDayFlag)
static COUPDAYSNC( $settlement, $maturity, $frequency, $basis=FinancialConstants::BASIS_DAYS_PER_YEAR_NASD)
COUPDAYSNC.
const PERIOD_DATE_PREVIOUS
static year($dateValue)
YEAR.
static COUPNCD( $settlement, $maturity, $frequency, $basis=FinancialConstants::BASIS_DAYS_PER_YEAR_NASD)
COUPNCD.
static COUPDAYS( $settlement, $maturity, $frequency, $basis=FinancialConstants::BASIS_DAYS_PER_YEAR_NASD)
COUPDAYS.
static fraction($startDate, $endDate, $method=0)
YEARFRAC.
static validateMaturityDate($maturity)
static COUPPCD( $settlement, $maturity, $frequency, $basis=FinancialConstants::BASIS_DAYS_PER_YEAR_NASD)
COUPPCD.
static validateSettlementDate($settlement)
static validateCouponPeriod(float $settlement, float $maturity)
static couponFirstPeriodDate(float $settlement, float $maturity, int $frequency, bool $next)
static between($endDate, $startDate)
DAYS.
static daysPerYear($year, $basis=0)
daysPerYear.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
static COUPNUM( $settlement, $maturity, $frequency, $basis=FinancialConstants::BASIS_DAYS_PER_YEAR_NASD)
COUPNUM.
static validateFrequency($frequency)
static COUPDAYBS( $settlement, $maturity, $frequency, $basis=FinancialConstants::BASIS_DAYS_PER_YEAR_NASD)
COUPDAYBS.
static validateBasis($basis)