ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TreasuryBill.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
11 {
26  public static function bondEquivalentYield($settlement, $maturity, $discount)
27  {
28  $settlement = Functions::flattenSingleValue($settlement);
29  $maturity = Functions::flattenSingleValue($maturity);
30  $discount = Functions::flattenSingleValue($discount);
31 
32  try {
33  $settlement = FinancialValidations::validateSettlementDate($settlement);
34  $maturity = FinancialValidations::validateMaturityDate($maturity);
35  $discount = FinancialValidations::validateFloat($discount);
36  } catch (Exception $e) {
37  return $e->getMessage();
38  }
39 
40  if ($discount <= 0) {
41  return Functions::NAN();
42  }
43 
44  $daysBetweenSettlementAndMaturity = $maturity - $settlement;
45  $daysPerYear = Helpers::daysPerYear(
46  DateTimeExcel\DateParts::year($maturity),
47  FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL
48  );
49 
50  if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
51  return Functions::NAN();
52  }
53 
54  return (365 * $discount) / (360 - $discount * $daysBetweenSettlementAndMaturity);
55  }
56 
71  public static function price($settlement, $maturity, $discount)
72  {
73  $settlement = Functions::flattenSingleValue($settlement);
74  $maturity = Functions::flattenSingleValue($maturity);
75  $discount = Functions::flattenSingleValue($discount);
76 
77  try {
78  $settlement = FinancialValidations::validateSettlementDate($settlement);
79  $maturity = FinancialValidations::validateMaturityDate($maturity);
80  $discount = FinancialValidations::validateFloat($discount);
81  } catch (Exception $e) {
82  return $e->getMessage();
83  }
84 
85  if ($discount <= 0) {
86  return Functions::NAN();
87  }
88 
89  $daysBetweenSettlementAndMaturity = $maturity - $settlement;
90  $daysPerYear = Helpers::daysPerYear(
91  DateTimeExcel\DateParts::year($maturity),
92  FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL
93  );
94 
95  if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
96  return Functions::NAN();
97  }
98 
99  $price = 100 * (1 - (($discount * $daysBetweenSettlementAndMaturity) / 360));
100  if ($price < 0.0) {
101  return Functions::NAN();
102  }
103 
104  return $price;
105  }
106 
121  public static function yield($settlement, $maturity, $price)
122  {
123  $settlement = Functions::flattenSingleValue($settlement);
124  $maturity = Functions::flattenSingleValue($maturity);
125  $price = Functions::flattenSingleValue($price);
126 
127  try {
128  $settlement = FinancialValidations::validateSettlementDate($settlement);
129  $maturity = FinancialValidations::validateMaturityDate($maturity);
130  $price = FinancialValidations::validatePrice($price);
131  } catch (Exception $e) {
132  return $e->getMessage();
133  }
134 
135  $daysBetweenSettlementAndMaturity = $maturity - $settlement;
136  $daysPerYear = Helpers::daysPerYear(
137  DateTimeExcel\DateParts::year($maturity),
138  FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL
139  );
140 
141  if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
142  return Functions::NAN();
143  }
144 
145  return ((100 - $price) / $price) * (360 / $daysBetweenSettlementAndMaturity);
146  }
147 }
static bondEquivalentYield($settlement, $maturity, $discount)
TBILLEQ.
static yield($settlement, $maturity, $price)
TBILLYIELD.
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
static price($settlement, $maturity, $discount)
TBILLPRICE.