BondCalculatorAbstract::getBondNoOfPayments()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace FinanCalc\Interfaces\Calculator {
4
5
    use FinanCalc\Utils\Helpers;
6
    use FinanCalc\Utils\MathFuncs;
7
8
    /**
9
     * Class BondInstanceAbstract
10
     * @package FinanCalc\Interfaces
11
     */
12
    abstract class BondCalculatorAbstract extends CalculatorAbstract
13
    {
14
        // face value of the bond = 'F'
15
        protected $bondFaceValue;
16
        // coupon rate of the bond per annum = 'c'
17
        protected $bondAnnualCouponRate;
18
        // number of years to the maturity of the bond
19
        protected $bondYearsToMaturity;
20
        // frequency of bond payments (expressed in a divisor of 12 months ~ 1 year)
21
        // e.g.: divisor 2 means semi-annual payments
22
        protected $bondPaymentFrequency;
23
24
        /**
25
         * @param $bondFaceValue
26
         */
27
        public function setBondFaceValue($bondFaceValue)
28
        {
29
            if (Helpers::checkIfPositiveNumberOrThrowAnException($bondFaceValue)) {
30
                $this->setProperty("bondFaceValue", $bondFaceValue);
31
            }
32
        }
33
34
        /**
35
         * @param $bondAnnualCouponRate
36
         */
37
        public function setBondAnnualCouponRate($bondAnnualCouponRate)
38
        {
39
            if (Helpers::checkIfPositiveNumberOrThrowAnException($bondAnnualCouponRate)) {
40
                $this->setProperty("bondAnnualCouponRate", $bondAnnualCouponRate);
41
            }
42
        }
43
44
        /**
45
         * @param $bondYearsToMaturity
46
         */
47
        public function setBondYearsToMaturity($bondYearsToMaturity)
48
        {
49
            if (Helpers::checkIfPositiveNumberOrThrowAnException($bondYearsToMaturity)) {
50
                $this->setProperty("bondYearsToMaturity", $bondYearsToMaturity);
51
            }
52
        }
53
54
        /**
55
         * @param $bondPaymentFrequency
56
         */
57
        public function setBondPaymentFrequency($bondPaymentFrequency)
58
        {
59
            if (Helpers::checkIfPositiveNumberOrThrowAnException($bondPaymentFrequency)) {
60
                $this->setProperty("bondPaymentFrequency", $bondPaymentFrequency);
61
            }
62
        }
63
64
        /**
65
         * @return mixed
66
         */
67
        public function getBondFaceValue()
68
        {
69
            return $this->bondFaceValue;
70
        }
71
72
        /**
73
         * @return mixed
74
         */
75
        public function getBondAnnualCouponRate()
76
        {
77
            return $this->bondAnnualCouponRate;
78
        }
79
80
        /**
81
         * @return mixed
82
         */
83
        public function getBondYearsToMaturity()
84
        {
85
            return $this->bondYearsToMaturity;
86
        }
87
88
        /**
89
         * @return mixed
90
         */
91
        public function getBondPaymentFrequency()
92
        {
93
            return $this->bondPaymentFrequency;
94
        }
95
96
        /**
97
         * @return float
98
         */
99
        public function getCouponPayment()
100
        {
101
            return ($this->bondAnnualCouponRate / $this->bondPaymentFrequency) * $this->bondFaceValue;
102
        }
103
104
        /**
105
         * @return int
106
         */
107
        public function getBondNoOfPayments()
108
        {
109
            // number of payments during the duration of the bond (up to the moment of its maturity)
110
            // is calculated from the number of years of the duration of the bond
111
            // multiplied by the number of payments per year (i.e., payment frequency)
112
            //, floored (to eliminate the last remaining incomplete due period)
113
            return intval(floor(MathFuncs::mul(
114
                $this->bondYearsToMaturity,
115
                $this->bondPaymentFrequency
116
            )));
117
        }
118
    }
119
}
120