Skip to content

Commit

Permalink
– added manufactureInstance method to the CalculatorFactoryAbstract
Browse files Browse the repository at this point in the history
  • Loading branch information
uruba committed Sep 4, 2015
1 parent 6790e34 commit 4938f16
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 144 deletions.
52 changes: 32 additions & 20 deletions src/Calculators/Factories/AnnuityCalculatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ class AnnuityCalculatorFactory extends CalculatorFactoryAbstract {
* @return AnnuityCalculator
*/
public function newYearlyAnnuity($annuitySinglePaymentAmount, $annuityNoOfCompoundingPeriods, $annuityInterest) {
return new AnnuityCalculator(
$annuitySinglePaymentAmount,
$annuityNoOfCompoundingPeriods,
TimeUtils::getDaysFromYears(1),
$annuityInterest);
return $this->manufactureInstance(
[
$annuitySinglePaymentAmount,
$annuityNoOfCompoundingPeriods,
TimeUtils::getDaysFromYears(1),
$annuityInterest
]
);
}

/**
Expand All @@ -33,11 +36,14 @@ public function newYearlyAnnuity($annuitySinglePaymentAmount, $annuityNoOfCompou
* @return AnnuityCalculator
*/
public function newMonthlyAnnuity($annuitySinglePaymentAmount, $annuityNoOfCompoundingPeriods, $annuityInterest) {
return new AnnuityCalculator(
$annuitySinglePaymentAmount,
$annuityNoOfCompoundingPeriods,
TimeUtils::getDaysFromMonths(1),
$annuityInterest);
return $this->manufactureInstance(
[
$annuitySinglePaymentAmount,
$annuityNoOfCompoundingPeriods,
TimeUtils::getDaysFromMonths(1),
$annuityInterest
]
);
}

/**
Expand All @@ -47,11 +53,14 @@ public function newMonthlyAnnuity($annuitySinglePaymentAmount, $annuityNoOfCompo
* @return AnnuityCalculator
*/
public function newDailyAnnuity($annuitySinglePaymentAmount, $annuityNoOfCompoundingPeriods, $annuityInterest) {
return new AnnuityCalculator(
$annuitySinglePaymentAmount,
$annuityNoOfCompoundingPeriods,
1,
$annuityInterest);
return $this->manufactureInstance(
[
$annuitySinglePaymentAmount,
$annuityNoOfCompoundingPeriods,
1,
$annuityInterest
]
);
}

/**
Expand All @@ -60,11 +69,14 @@ public function newDailyAnnuity($annuitySinglePaymentAmount, $annuityNoOfCompoun
* @return AnnuityCalculator
*/
public function newPerpetuity($annuitySinglePaymentAmount, $annuityInterest) {
return new AnnuityCalculator(
$annuitySinglePaymentAmount,
0,
0,
$annuityInterest);
return $this->manufactureInstance(
[
$annuitySinglePaymentAmount,
0,
0,
$annuityInterest
]
);
}
}
}
73 changes: 44 additions & 29 deletions src/Calculators/Factories/BondDurationCalculatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ class BondDurationCalculatorFactory extends CalculatorFactoryAbstract {
* @return BondDurationCalculator
*/
public function newAnnualCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bondAnnualYield, $bondYearsToMaturity) {
return new BondDurationCalculator(
$bondFaceValue,
$bondAnnualCouponRate,
$bondAnnualYield,
$bondYearsToMaturity);
return $this->manufactureInstance(
[
$bondFaceValue,
$bondAnnualCouponRate,
$bondAnnualYield,
$bondYearsToMaturity
]
);
}

/**
Expand All @@ -37,12 +40,15 @@ public function newAnnualCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bon
* @return BondDurationCalculator
*/
public function newSemiAnnualCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bondAnnualYield, $bondYearsToMaturity) {
return new BondDurationCalculator(
$bondFaceValue,
$bondAnnualCouponRate,
$bondAnnualYield,
$bondYearsToMaturity,
2);
return $this->manufactureInstance(
[
$bondFaceValue,
$bondAnnualCouponRate,
$bondAnnualYield,
$bondYearsToMaturity,
2
]
);
}


Expand All @@ -54,12 +60,15 @@ public function newSemiAnnualCouponsBond($bondFaceValue, $bondAnnualCouponRate,
* @return BondDurationCalculator
*/
public function newQuarterlyCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bondAnnualYield, $bondYearsToMaturity) {
return new BondDurationCalculator(
$bondFaceValue,
$bondAnnualCouponRate,
$bondAnnualYield,
$bondYearsToMaturity,
4);
return $this->manufactureInstance(
[
$bondFaceValue,
$bondAnnualCouponRate,
$bondAnnualYield,
$bondYearsToMaturity,
4
]
);
}


Expand All @@ -71,12 +80,15 @@ public function newQuarterlyCouponsBond($bondFaceValue, $bondAnnualCouponRate, $
* @return BondDurationCalculator
*/
public function newMonthlyCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bondAnnualYield, $bondYearsToMaturity) {
return new BondDurationCalculator(
$bondFaceValue,
$bondAnnualCouponRate,
$bondAnnualYield,
$bondYearsToMaturity,
12);
return $this->manufactureInstance(
[
$bondFaceValue,
$bondAnnualCouponRate,
$bondAnnualYield,
$bondYearsToMaturity,
12
]
);
}


Expand All @@ -89,12 +101,15 @@ public function newMonthlyCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bo
* @return BondDurationCalculator
*/
public function newCustomCouponFrequencyBond($bondFaceValue, $bondAnnualCouponRate, $bondAnnualYield, $bondYearsToMaturity, $bondPaymentFrequency) {
return new BondDurationCalculator(
$bondFaceValue,
$bondAnnualCouponRate,
$bondAnnualYield,
$bondYearsToMaturity,
$bondPaymentFrequency);
return $this->manufactureInstance(
[
$bondFaceValue,
$bondAnnualCouponRate,
$bondAnnualYield,
$bondYearsToMaturity,
$bondPaymentFrequency
]
);
}

}
Expand Down
73 changes: 44 additions & 29 deletions src/Calculators/Factories/BondFairValueCalculatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ class BondFairValueCalculatorFactory extends CalculatorFactoryAbstract {
* @return BondFairValueCalculator
*/
public function newAnnualCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bondVIR, $bondYearsToMaturity) {
return new BondFairValueCalculator(
$bondFaceValue,
$bondAnnualCouponRate,
$bondVIR,
$bondYearsToMaturity);
return $this->manufactureInstance(
[
$bondFaceValue,
$bondAnnualCouponRate,
$bondVIR,
$bondYearsToMaturity
]
);
}

/**
Expand All @@ -36,12 +39,15 @@ public function newAnnualCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bon
* @return BondFairValueCalculator
*/
public function newSemiAnnualCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bondVIR, $bondYearsToMaturity) {
return new BondFairValueCalculator(
$bondFaceValue,
$bondAnnualCouponRate,
$bondVIR,
$bondYearsToMaturity,
2);
return $this->manufactureInstance(
[
$bondFaceValue,
$bondAnnualCouponRate,
$bondVIR,
$bondYearsToMaturity,
2
]
);
}

/**
Expand All @@ -52,12 +58,15 @@ public function newSemiAnnualCouponsBond($bondFaceValue, $bondAnnualCouponRate,
* @return BondFairValueCalculator
*/
public function newQuarterlyCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bondVIR, $bondYearsToMaturity) {
return new BondFairValueCalculator(
$bondFaceValue,
$bondAnnualCouponRate,
$bondVIR,
$bondYearsToMaturity,
4);
return $this->manufactureInstance(
[
$bondFaceValue,
$bondAnnualCouponRate,
$bondVIR,
$bondYearsToMaturity,
4
]
);
}

/**
Expand All @@ -68,12 +77,15 @@ public function newQuarterlyCouponsBond($bondFaceValue, $bondAnnualCouponRate, $
* @return BondFairValueCalculator
*/
public function newMonthlyCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bondVIR, $bondYearsToMaturity) {
return new BondFairValueCalculator(
$bondFaceValue,
$bondAnnualCouponRate,
$bondVIR,
$bondYearsToMaturity,
12);
return $this->manufactureInstance(
[
$bondFaceValue,
$bondAnnualCouponRate,
$bondVIR,
$bondYearsToMaturity,
12
]
);
}

/**
Expand All @@ -85,12 +97,15 @@ public function newMonthlyCouponsBond($bondFaceValue, $bondAnnualCouponRate, $bo
* @return BondFairValueCalculator
*/
public function newCustomCouponFrequencyBond($bondFaceValue, $bondAnnualCouponRate, $bondVIR, $bondYearsToMaturity, $bondPaymentFrequency) {
return new BondFairValueCalculator(
$bondFaceValue,
$bondAnnualCouponRate,
$bondVIR,
$bondYearsToMaturity,
$bondPaymentFrequency);
return $this->manufactureInstance(
[
$bondFaceValue,
$bondAnnualCouponRate,
$bondVIR,
$bondYearsToMaturity,
$bondPaymentFrequency
]
);
}
}
}
Loading

0 comments on commit 4938f16

Please sign in to comment.