ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Rates.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
10 class Rates
11 {
36  public static function discount(
37  $settlement,
38  $maturity,
39  $price,
40  $redemption,
41  $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
42  ) {
43  $settlement = Functions::flattenSingleValue($settlement);
44  $maturity = Functions::flattenSingleValue($maturity);
45  $price = Functions::flattenSingleValue($price);
46  $redemption = Functions::flattenSingleValue($redemption);
47  $basis = ($basis === null)
48  ? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
50 
51  try {
52  $settlement = SecurityValidations::validateSettlementDate($settlement);
53  $maturity = SecurityValidations::validateMaturityDate($maturity);
54  SecurityValidations::validateSecurityPeriod($settlement, $maturity);
55  $price = SecurityValidations::validatePrice($price);
56  $redemption = SecurityValidations::validateRedemption($redemption);
57  $basis = SecurityValidations::validateBasis($basis);
58  } catch (Exception $e) {
59  return $e->getMessage();
60  }
61 
62  if ($price <= 0.0) {
63  return Functions::NAN();
64  }
65 
66  $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
67  if (!is_numeric($daysBetweenSettlementAndMaturity)) {
68  // return date error
69  return $daysBetweenSettlementAndMaturity;
70  }
71 
72  return (1 - $price / $redemption) / $daysBetweenSettlementAndMaturity;
73  }
74 
99  public static function interest(
100  $settlement,
101  $maturity,
102  $investment,
103  $redemption,
104  $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
105  ) {
106  $settlement = Functions::flattenSingleValue($settlement);
107  $maturity = Functions::flattenSingleValue($maturity);
108  $investment = Functions::flattenSingleValue($investment);
109  $redemption = Functions::flattenSingleValue($redemption);
110  $basis = ($basis === null)
111  ? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
113 
114  try {
115  $settlement = SecurityValidations::validateSettlementDate($settlement);
116  $maturity = SecurityValidations::validateMaturityDate($maturity);
117  SecurityValidations::validateSecurityPeriod($settlement, $maturity);
118  $investment = SecurityValidations::validateFloat($investment);
119  $redemption = SecurityValidations::validateRedemption($redemption);
120  $basis = SecurityValidations::validateBasis($basis);
121  } catch (Exception $e) {
122  return $e->getMessage();
123  }
124 
125  if ($investment <= 0) {
126  return Functions::NAN();
127  }
128 
129  $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
130  if (!is_numeric($daysBetweenSettlementAndMaturity)) {
131  // return date error
132  return $daysBetweenSettlementAndMaturity;
133  }
134 
135  return (($redemption / $investment) - 1) / ($daysBetweenSettlementAndMaturity);
136  }
137 }
static discount( $settlement, $maturity, $price, $redemption, $basis=FinancialConstants::BASIS_DAYS_PER_YEAR_NASD)
DISC.
Definition: Rates.php:36
static fraction($startDate, $endDate, $method=0)
YEARFRAC.
Definition: YearFrac.php:37
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649
static interest( $settlement, $maturity, $investment, $redemption, $basis=FinancialConstants::BASIS_DAYS_PER_YEAR_NASD)
INTRATE.
Definition: Rates.php:99