ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Yields.php
Go to the documentation of this file.
1 <?php
2 
4 
10 
11 class Yields
12 {
34  public static function yieldDiscounted(
35  $settlement,
36  $maturity,
37  $price,
38  $redemption,
39  $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
40  ) {
41  $settlement = Functions::flattenSingleValue($settlement);
42  $maturity = Functions::flattenSingleValue($maturity);
43  $price = Functions::flattenSingleValue($price);
44  $redemption = Functions::flattenSingleValue($redemption);
45  $basis = ($basis === null)
46  ? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
48 
49  try {
50  $settlement = SecurityValidations::validateSettlementDate($settlement);
51  $maturity = SecurityValidations::validateMaturityDate($maturity);
52  SecurityValidations::validateSecurityPeriod($settlement, $maturity);
53  $price = SecurityValidations::validatePrice($price);
54  $redemption = SecurityValidations::validateRedemption($redemption);
55  $basis = SecurityValidations::validateBasis($basis);
56  } catch (Exception $e) {
57  return $e->getMessage();
58  }
59 
60  $daysPerYear = Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis);
61  if (!is_numeric($daysPerYear)) {
62  return $daysPerYear;
63  }
64  $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
65  if (!is_numeric($daysBetweenSettlementAndMaturity)) {
66  // return date error
67  return $daysBetweenSettlementAndMaturity;
68  }
69  $daysBetweenSettlementAndMaturity *= $daysPerYear;
70 
71  return (($redemption - $price) / $price) * ($daysPerYear / $daysBetweenSettlementAndMaturity);
72  }
73 
96  public static function yieldAtMaturity(
97  $settlement,
98  $maturity,
99  $issue,
100  $rate,
101  $price,
102  $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
103  ) {
104  $settlement = Functions::flattenSingleValue($settlement);
105  $maturity = Functions::flattenSingleValue($maturity);
106  $issue = Functions::flattenSingleValue($issue);
107  $rate = Functions::flattenSingleValue($rate);
108  $price = Functions::flattenSingleValue($price);
109  $basis = ($basis === null)
110  ? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
112 
113  try {
114  $settlement = SecurityValidations::validateSettlementDate($settlement);
115  $maturity = SecurityValidations::validateMaturityDate($maturity);
116  SecurityValidations::validateSecurityPeriod($settlement, $maturity);
118  $rate = SecurityValidations::validateRate($rate);
119  $price = SecurityValidations::validatePrice($price);
120  $basis = SecurityValidations::validateBasis($basis);
121  } catch (Exception $e) {
122  return $e->getMessage();
123  }
124 
125  $daysPerYear = Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis);
126  if (!is_numeric($daysPerYear)) {
127  return $daysPerYear;
128  }
129  $daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::fraction($issue, $settlement, $basis);
130  if (!is_numeric($daysBetweenIssueAndSettlement)) {
131  // return date error
132  return $daysBetweenIssueAndSettlement;
133  }
134  $daysBetweenIssueAndSettlement *= $daysPerYear;
135  $daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::fraction($issue, $maturity, $basis);
136  if (!is_numeric($daysBetweenIssueAndMaturity)) {
137  // return date error
138  return $daysBetweenIssueAndMaturity;
139  }
140  $daysBetweenIssueAndMaturity *= $daysPerYear;
141  $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
142  if (!is_numeric($daysBetweenSettlementAndMaturity)) {
143  // return date error
144  return $daysBetweenSettlementAndMaturity;
145  }
146  $daysBetweenSettlementAndMaturity *= $daysPerYear;
147 
148  return ((1 + (($daysBetweenIssueAndMaturity / $daysPerYear) * $rate) -
149  (($price / 100) + (($daysBetweenIssueAndSettlement / $daysPerYear) * $rate))) /
150  (($price / 100) + (($daysBetweenIssueAndSettlement / $daysPerYear) * $rate))) *
151  ($daysPerYear / $daysBetweenSettlementAndMaturity);
152  }
153 }
static yieldAtMaturity( $settlement, $maturity, $issue, $rate, $price, $basis=FinancialConstants::BASIS_DAYS_PER_YEAR_NASD)
YIELDMAT.
Definition: Yields.php:96
static fraction($startDate, $endDate, $method=0)
YEARFRAC.
Definition: YearFrac.php:37
static yieldDiscounted( $settlement, $maturity, $price, $redemption, $basis=FinancialConstants::BASIS_DAYS_PER_YEAR_NASD)
YIELDDISC.
Definition: Yields.php:34
static daysPerYear($year, $basis=0)
daysPerYear.
Definition: Helpers.php:27
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649