ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AccruedInterest.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
11 {
13 
15 
47  public static function periodic(
48  $issue,
49  $firstInterest,
50  $settlement,
51  $rate,
52  $parValue = 1000,
53  $frequency = FinancialConstants::FREQUENCY_ANNUAL,
54  $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD,
55  $calcMethod = self::ACCRINT_CALCMODE_ISSUE_TO_SETTLEMENT
56  ) {
57  $issue = Functions::flattenSingleValue($issue);
58  $firstInterest = Functions::flattenSingleValue($firstInterest);
59  $settlement = Functions::flattenSingleValue($settlement);
60  $rate = Functions::flattenSingleValue($rate);
61  $parValue = ($parValue === null) ? 1000 : Functions::flattenSingleValue($parValue);
62  $frequency = ($frequency === null)
63  ? FinancialConstants::FREQUENCY_ANNUAL
64  : Functions::flattenSingleValue($frequency);
65  $basis = ($basis === null)
66  ? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
68 
69  try {
71  $settlement = SecurityValidations::validateSettlementDate($settlement);
73  $rate = SecurityValidations::validateRate($rate);
74  $parValue = SecurityValidations::validateParValue($parValue);
75  $frequency = SecurityValidations::validateFrequency($frequency);
76  $basis = SecurityValidations::validateBasis($basis);
77  } catch (Exception $e) {
78  return $e->getMessage();
79  }
80 
81  $daysBetweenIssueAndSettlement = YearFrac::fraction($issue, $settlement, $basis);
82  if (!is_numeric($daysBetweenIssueAndSettlement)) {
83  // return date error
84  return $daysBetweenIssueAndSettlement;
85  }
86  $daysBetweenFirstInterestAndSettlement = YearFrac::fraction($firstInterest, $settlement, $basis);
87  if (!is_numeric($daysBetweenFirstInterestAndSettlement)) {
88  // return date error
89  return $daysBetweenFirstInterestAndSettlement;
90  }
91 
92  return $parValue * $rate * $daysBetweenIssueAndSettlement;
93  }
94 
117  public static function atMaturity(
118  $issue,
119  $settlement,
120  $rate,
121  $parValue = 1000,
122  $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
123  ) {
124  $issue = Functions::flattenSingleValue($issue);
125  $settlement = Functions::flattenSingleValue($settlement);
126  $rate = Functions::flattenSingleValue($rate);
127  $parValue = ($parValue === null) ? 1000 : Functions::flattenSingleValue($parValue);
128  $basis = ($basis === null)
129  ? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
131 
132  try {
134  $settlement = SecurityValidations::validateSettlementDate($settlement);
135  SecurityValidations::validateSecurityPeriod($issue, $settlement);
136  $rate = SecurityValidations::validateRate($rate);
137  $parValue = SecurityValidations::validateParValue($parValue);
138  $basis = SecurityValidations::validateBasis($basis);
139  } catch (Exception $e) {
140  return $e->getMessage();
141  }
142 
143  $daysBetweenIssueAndSettlement = YearFrac::fraction($issue, $settlement, $basis);
144  if (!is_numeric($daysBetweenIssueAndSettlement)) {
145  // return date error
146  return $daysBetweenIssueAndSettlement;
147  }
148 
149  return $parValue * $rate * $daysBetweenIssueAndSettlement;
150  }
151 }
static atMaturity( $issue, $settlement, $rate, $parValue=1000, $basis=FinancialConstants::BASIS_DAYS_PER_YEAR_NASD)
ACCRINTM.
static fraction($startDate, $endDate, $method=0)
YEARFRAC.
Definition: YearFrac.php:37
static periodic( $issue, $firstInterest, $settlement, $rate, $parValue=1000, $frequency=FinancialConstants::FREQUENCY_ANNUAL, $basis=FinancialConstants::BASIS_DAYS_PER_YEAR_NASD, $calcMethod=self::ACCRINT_CALCMODE_ISSUE_TO_SETTLEMENT)
ACCRINT.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649