Financial functions more rationalization (#1990)

* Additional unit tests and rationalisation for Financial Functions
* Providing a series of sample files for Financial functions
* Refactor the last of the existing Financial functions
* Some more unit tests with default assignments from null arguments

Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com>
This commit is contained in:
Mark Baker 2021-04-12 22:08:58 +02:00 committed by GitHub
parent 49f87de165
commit a34695e0f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
78 changed files with 2242 additions and 1579 deletions

View File

@ -700,236 +700,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial.php path: src/PhpSpreadsheet/Calculation/Financial.php
-
message: "#^Result of && is always true\\.$#"
count: 2
path: src/PhpSpreadsheet/Calculation/Financial.php
-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Amortization\\:\\:validateDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Amortization.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Amortization\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Amortization.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Amortization\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Amortization.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Amortization\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Amortization.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Amortization\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Amortization.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Amortization\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Amortization.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Amortization\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Amortization.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Amortization\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Amortization.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Amortization.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Amortization\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Amortization.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Amortization\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Amortization.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\:\\:validateDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Cumulative\\:\\:validateDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Cumulative\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Cumulative\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Cumulative\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Cumulative\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Cumulative\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Cumulative\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Cumulative\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Cumulative\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Cumulative\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Cumulative.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Interest\\:\\:validateDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Interest\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Interest\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Interest\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Interest\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Interest\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Interest\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Interest\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Interest\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Interest\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Interest\\:\\:schedulePayment\\(\\) has no return typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Interest\\:\\:schedulePayment\\(\\) has no return typehint specified\\.$#"
count: 1 count: 1
@ -970,411 +740,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Interest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Payments\\:\\:validateDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Payments\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Payments\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Payments\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Payments\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Payments\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Payments\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Payments\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Payments\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\Payments\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Constant/Periodic/Payments.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Single\\:\\:validateDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Single\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Single\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Single\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Single\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Single\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Single\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Single\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Single\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Single\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Single.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Binary operation \"\\*\" between float\\|string and int results in an error\\.$#"
count: 2
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Binary operation \"\\*\" between float\\|string and int\\|string results in an error\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:couponFirstPeriodDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:couponFirstPeriodDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:couponFirstPeriodDate\\(\\) has parameter \\$next with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:couponFirstPeriodDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateCouponPeriod\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateCouponPeriod\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateCost\\(\\) has parameter \\$cost with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateSalvage\\(\\) has parameter \\$salvage with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateLife\\(\\) has parameter \\$life with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validatePeriod\\(\\) has parameter \\$period with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateMonth\\(\\) has parameter \\$month with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateFactor\\(\\) has parameter \\$factor with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\InterestRate\\:\\:validateDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/InterestRate.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\InterestRate\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/InterestRate.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\InterestRate\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/InterestRate.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\InterestRate\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/InterestRate.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\InterestRate\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/InterestRate.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\InterestRate\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/InterestRate.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\InterestRate\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/InterestRate.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\InterestRate\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/InterestRate.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/InterestRate.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\InterestRate\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/InterestRate.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\InterestRate\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/InterestRate.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\TreasuryBill\\:\\:validateDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\TreasuryBill\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\TreasuryBill\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\TreasuryBill\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\TreasuryBill\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\TreasuryBill\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\TreasuryBill\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\TreasuryBill\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\TreasuryBill\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\TreasuryBill\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\TreasuryBill\\:\\:price\\(\\) should return float\\|string but returns float\\|int\\<0, max\\>\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
- -
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\InterestAndPrincipal\\:\\:\\$interest has no typehint specified\\.$#" message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\CashFlow\\\\Constant\\\\Periodic\\\\InterestAndPrincipal\\:\\:\\$interest has no typehint specified\\.$#"
count: 1 count: 1
@ -1501,289 +866,74 @@ parameters:
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateDate\\(\\) has no return typehint specified\\.$#" message: "#^Binary operation \"\\*\" between float\\|string and int results in an error\\.$#"
count: 1 count: 2
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#" message: "#^Binary operation \"\\*\" between float\\|string and int\\|string results in an error\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:couponFirstPeriodDate\\(\\) has no return typehint specified\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:couponFirstPeriodDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:couponFirstPeriodDate\\(\\) has parameter \\$next with no typehint specified\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:couponFirstPeriodDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateCouponPeriod\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateIssueDate\\(\\) has no return typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Coupons\\:\\:validateCouponPeriod\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateIssueDate\\(\\) has parameter \\$issue with no typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateCost\\(\\) has parameter \\$cost with no typehint specified\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateSecurityPeriod\\(\\) has parameter \\$maturity with no typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateSalvage\\(\\) has parameter \\$salvage with no typehint specified\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateSecurityPeriod\\(\\) has parameter \\$settlement with no typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateLife\\(\\) has parameter \\$life with no typehint specified\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateRate\\(\\) has parameter \\$rate with no typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validatePeriod\\(\\) has parameter \\$period with no typehint specified\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateParValue\\(\\) has parameter \\$parValue with no typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateMonth\\(\\) has parameter \\$month with no typehint specified\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validatePrice\\(\\) has parameter \\$price with no typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Depreciation\\:\\:validateFactor\\(\\) has parameter \\$factor with no typehint specified\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php path: src/PhpSpreadsheet/Calculation/Financial/Depreciation.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateYield\\(\\) has parameter \\$yield with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateRedemption\\(\\) has parameter \\$redemption with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateDiscount\\(\\) has parameter \\$discount with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\AccruedInterest\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateIssueDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateIssueDate\\(\\) has parameter \\$issue with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateSecurityPeriod\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateSecurityPeriod\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateRate\\(\\) has parameter \\$rate with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateParValue\\(\\) has parameter \\$parValue with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validatePrice\\(\\) has parameter \\$price with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateYield\\(\\) has parameter \\$yield with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateRedemption\\(\\) has parameter \\$redemption with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateDiscount\\(\\) has parameter \\$discount with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Price\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateDate\\(\\) has parameter \\$date with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateSettlementDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateSettlementDate\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateMaturityDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateMaturityDate\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateIssueDate\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateIssueDate\\(\\) has parameter \\$issue with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateSecurityPeriod\\(\\) has parameter \\$maturity with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateSecurityPeriod\\(\\) has parameter \\$settlement with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateRate\\(\\) has parameter \\$rate with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateParValue\\(\\) has parameter \\$parValue with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validatePrice\\(\\) has parameter \\$price with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateYield\\(\\) has parameter \\$yield with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateRedemption\\(\\) has parameter \\$redemption with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateDiscount\\(\\) has parameter \\$discount with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateFrequency\\(\\) has parameter \\$frequency with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\\\Securities\\\\Yields\\:\\:validateBasis\\(\\) has parameter \\$basis with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
- -
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#" message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"

View File

@ -0,0 +1,35 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the accrued interest for a security that pays periodic interest.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Issue Date', DateHelper::getDateValue('01-Jan-2012')],
['First Interest Date', DateHelper::getDateValue('01-Apr-2012')],
['Settlement Date', DateHelper::getDateValue('31-Dec-2013')],
['Annual Coupon Rate', 0.08],
['Par Value', 10000],
['Frequency', 4],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B3')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
$worksheet->getStyle('B4')->getNumberFormat()->setFormatCode('0.00%');
$worksheet->getStyle('B5')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
$worksheet->setCellValue('B10', '=ACCRINT(B1, B2, B3, B4, B5, B6)');
$worksheet->getStyle('B10')->getNumberFormat()->setFormatCode('$#,##0.00');
$helper->log($worksheet->getCell('B10')->getValue());
$helper->log('ACCRINT() Result is ' . $worksheet->getCell('B10')->getFormattedValue());

View File

@ -0,0 +1,33 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the accrued interest for a security that pays interest at maturity.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Issue Date', DateHelper::getDateValue('01-Jan-2012')],
['Settlement Date', DateHelper::getDateValue('31-Dec-2012')],
['Annual Coupon Rate', 0.08],
['Par Value', 10000],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
$worksheet->getStyle('B3')->getNumberFormat()->setFormatCode('0.00%');
$worksheet->getStyle('B4')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
$worksheet->setCellValue('B6', '=ACCRINTM(B1, B2, B3, B4)');
$worksheet->getStyle('B6')->getNumberFormat()->setFormatCode('$#,##0.00');
$helper->log($worksheet->getCell('B6')->getValue());
$helper->log('ACCRINTM() Result is ' . $worksheet->getCell('B6')->getFormattedValue());

View File

@ -0,0 +1,38 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the prorated linear depreciation of an asset for a specified accounting period.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Cost', 150.00],
['Date Purchased', DateHelper::getDateValue('01-Jan-2015')],
['First Period Date', DateHelper::getDateValue('30-Sep-2015')],
['Salvage Value', 20.00],
['Number of Periods', 1],
['Depreciation Rate', 0.20],
['Basis', FinancialConstants::BASIS_DAYS_PER_YEAR_360_EUROPEAN],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1')->getNumberFormat()->setFormatCode('$#,##0.00');
$worksheet->getStyle('B2:B3')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
$worksheet->getStyle('B4')->getNumberFormat()->setFormatCode('$#,##0.00');
$worksheet->getStyle('B6')->getNumberFormat()->setFormatCode('0.00%');
// Now the formula
$worksheet->setCellValue('B10', '=AMORDEGRC(B1, B2, B3, B4, B5, B6, B7)');
$worksheet->getStyle('B10')->getNumberFormat()->setFormatCode('$#,##0.00');
$helper->log($worksheet->getCell('B10')->getValue());
$helper->log('AMORDEGRC() Result is ' . $worksheet->getCell('B10')->getFormattedValue());

View File

@ -0,0 +1,38 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the prorated linear depreciation of an asset for a specified accounting period.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Cost', 150.00],
['Date Purchased', DateHelper::getDateValue('01-Jan-2015')],
['First Period Date', DateHelper::getDateValue('30-Sep-2015')],
['Salvage Value', 20.00],
['Period', 1],
['Depreciation Rate', 0.20],
['Basis', FinancialConstants::BASIS_DAYS_PER_YEAR_360_EUROPEAN],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1')->getNumberFormat()->setFormatCode('$#,##0.00');
$worksheet->getStyle('B2:B3')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
$worksheet->getStyle('B4')->getNumberFormat()->setFormatCode('$#,##0.00');
$worksheet->getStyle('B6')->getNumberFormat()->setFormatCode('0.00%');
// Now the formula
$worksheet->setCellValue('B10', '=AMORLINC(B1, B2, B3, B4, B5, B6, B7)');
$worksheet->getStyle('B10')->getNumberFormat()->setFormatCode('$#,##0.00');
$helper->log($worksheet->getCell('B10')->getValue());
$helper->log('AMORLINC() Result is ' . $worksheet->getCell('B10')->getFormattedValue());

View File

@ -0,0 +1,29 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the number of days from the beginning of a coupon\'s period to the settlement date.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Settlement Date', DateHelper::getDateValue('01-Jan-2011')],
['Maturity Date', DateHelper::getDateValue('25-Oct-2012')],
['Frequency', 4],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
// Now the formula
$worksheet->setCellValue('B6', '=COUPDAYBS(B1, B2, B3)');
$helper->log($worksheet->getCell('B6')->getValue());
$helper->log('COUPDAYBS() Result is ' . $worksheet->getCell('B6')->getFormattedValue());

View File

@ -0,0 +1,29 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the number of days in the coupon period that contains the settlement date.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Settlement Date', DateHelper::getDateValue('01-Jan-2011')],
['Maturity Date', DateHelper::getDateValue('25-Oct-2012')],
['Frequency', 4],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
// Now the formula
$worksheet->setCellValue('B6', '=COUPDAYS(B1, B2, B3)');
$helper->log($worksheet->getCell('B6')->getValue());
$helper->log('COUPDAYS() Result is ' . $worksheet->getCell('B6')->getFormattedValue());

View File

@ -0,0 +1,29 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the number of days from the settlement date to the next coupon date.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Settlement Date', DateHelper::getDateValue('01-Jan-2011')],
['Maturity Date', DateHelper::getDateValue('25-Oct-2012')],
['Frequency', 4],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
// Now the formula
$worksheet->setCellValue('B6', '=COUPDAYSNC(B1, B2, B3)');
$helper->log($worksheet->getCell('B6')->getValue());
$helper->log('COUPDAYSNC() Result is ' . $worksheet->getCell('B6')->getFormattedValue());

View File

@ -0,0 +1,30 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the next coupon date, after the settlement date.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Settlement Date', DateHelper::getDateValue('01-Jan-2011')],
['Maturity Date', DateHelper::getDateValue('25-Oct-2012')],
['Frequency', 4],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
// Now the formula
$worksheet->setCellValue('B6', '=COUPNCD(B1, B2, B3)');
$worksheet->getStyle('B6')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
$helper->log($worksheet->getCell('B6')->getValue());
$helper->log('COUPNCD() Result is ' . $worksheet->getCell('B6')->getFormattedValue());

View File

@ -0,0 +1,30 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the number of coupons payable, between a security\'s settlement date and maturity date,');
$helper->log('rounded up to the nearest whole coupon.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Settlement Date', DateHelper::getDateValue('01-Jan-2011')],
['Maturity Date', DateHelper::getDateValue('25-Oct-2012')],
['Frequency', 4],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
// Now the formula
$worksheet->setCellValue('B6', '=COUPNUM(B1, B2, B3)');
$helper->log($worksheet->getCell('B6')->getValue());
$helper->log('COUPNUM() Result is ' . $worksheet->getCell('B6')->getFormattedValue());

View File

@ -0,0 +1,30 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the previous coupon date, before the settlement date for a security.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Settlement Date', DateHelper::getDateValue('01-Jan-2011')],
['Maturity Date', DateHelper::getDateValue('25-Oct-2012')],
['Frequency', 4],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
// Now the formula
$worksheet->setCellValue('B6', '=COUPPCD(B1, B2, B3)');
$worksheet->getStyle('B6')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
$helper->log($worksheet->getCell('B6')->getValue());
$helper->log('COUPPCD() Result is ' . $worksheet->getCell('B6')->getFormattedValue());

View File

@ -0,0 +1,38 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the cumulative interest paid on a loan or investment, between two specified periods.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Interest Rate (per period)', 0.05 / 12],
['Number of Periods', 5 * 12],
['Present Value', 50000],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1')->getNumberFormat()->setFormatCode('0.00%');
$worksheet->getStyle('B3')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
$baseRow = 5;
for ($year = 1; $year <= 5; ++$year) {
$row = (string) ($baseRow + $year);
$yearStartPeriod = (int) $year * 12 - 11;
$yearEndPeriod = (int) $year * 12;
$worksheet->setCellValue("A{$row}", "Yr {$year}");
$worksheet->setCellValue("B{$row}", "=CUMIPMT(\$B\$1, \$B\$2, \$B\$3, {$yearStartPeriod}, {$yearEndPeriod}, 0)");
$worksheet->getStyle("B{$row}")->getNumberFormat()->setFormatCode('$#,##0.00;-$#,##0.00');
$helper->log($worksheet->getCell("B{$row}")->getValue());
$helper->log("CUMIPMT() Year {$year} Result is " . $worksheet->getCell("B{$row}")->getFormattedValue());
}

View File

@ -0,0 +1,38 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the cumulative payment on the principal of a loan or investment, between two specified periods.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Interest Rate (per period)', 0.05 / 12],
['Number of Periods', 5 * 12],
['Present Value', 50000],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1')->getNumberFormat()->setFormatCode('0.00%');
$worksheet->getStyle('B3')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
$baseRow = 5;
for ($year = 1; $year <= 5; ++$year) {
$row = (string) ($baseRow + $year);
$yearStartPeriod = (int) $year * 12 - 11;
$yearEndPeriod = (int) $year * 12;
$worksheet->setCellValue("A{$row}", "Yr {$year}");
$worksheet->setCellValue("B{$row}", "=CUMPRINC(\$B\$1, \$B\$2, \$B\$3, {$yearStartPeriod}, {$yearEndPeriod}, 0)");
$worksheet->getStyle("B{$row}")->getNumberFormat()->setFormatCode('$#,##0.00;-$#,##0.00');
$helper->log($worksheet->getCell("B{$row}")->getValue());
$helper->log("CUMPRINC() Year {$year} Result is " . $worksheet->getCell("B{$row}")->getFormattedValue());
}

View File

@ -0,0 +1,50 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the depreciation of an asset, using the Fixed Declining Balance Method,');
$helper->log('for each period of the asset\'s lifetime.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Cost Value', 10000],
['Salvage', 1000],
['Life', 5, 'Years'],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
$baseRow = 5;
for ($year = 1; $year <= 5; ++$year) {
$row = (string) ($baseRow + $year);
$worksheet->setCellValue("A{$row}", "Depreciation after Yr {$year}");
$worksheet->setCellValue("B{$row}", "=DB(\$B\$1, \$B\$2, \$B\$3, {$year})");
$worksheet->getStyle("B{$row}")->getNumberFormat()->setFormatCode('$#,##0.00;-$#,##0.00');
$helper->log($worksheet->getCell("B{$row}")->getValue());
$helper->log("DB() Year {$year} Result is " . $worksheet->getCell("B{$row}")->getFormattedValue());
}
$helper->log('And with depreciation only starting after 6 months.');
$baseRow = 12;
for ($year = 1; $year <= 6; ++$year) {
$row = (string) ($baseRow + $year);
$worksheet->setCellValue("A{$row}", "Depreciation after Yr {$year}");
$worksheet->setCellValue("B{$row}", "=DB(\$B\$1, \$B\$2, \$B\$3, {$year}, 6)");
$worksheet->getStyle("B{$row}")->getNumberFormat()->setFormatCode('$#,##0.00;-$#,##0.00');
$helper->log($worksheet->getCell("B{$row}")->getValue());
$helper->log("DB() Year {$year} Result is " . $worksheet->getCell("B{$row}")->getFormattedValue());
}

View File

@ -0,0 +1,36 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the depreciation of an asset, using the Double Declining Balance Method,');
$helper->log('for each period of the asset\'s lifetime.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Cost Value', 10000],
['Salvage', 1000],
['Life', 5, 'Years'],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
$baseRow = 5;
for ($year = 1; $year <= 5; ++$year) {
$row = (string) ($baseRow + $year);
$worksheet->setCellValue("A{$row}", "Depreciation after Yr {$year}");
$worksheet->setCellValue("B{$row}", "=DDB(\$B\$1, \$B\$2, \$B\$3, {$year})");
$worksheet->getStyle("B{$row}")->getNumberFormat()->setFormatCode('$#,##0.00;-$#,##0.00');
$helper->log($worksheet->getCell("B{$row}")->getValue());
$helper->log("DDB() Year {$year} Result is " . $worksheet->getCell("B{$row}")->getFormattedValue());
}

View File

@ -0,0 +1,32 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the the Discount Rate for a security.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Settlement Date', DateHelper::getDateValue('01-Apr-2016')],
['Maturity Date', DateHelper::getDateValue('31-Mar-2021')],
['Par Value', 95.00],
['Redemption Value', 100.00],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
$worksheet->getStyle('B3:B4')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
$worksheet->setCellValue('B7', '=DISC(B1, B2, B3, B4)');
$worksheet->getStyle('B7')->getNumberFormat()->setFormatCode('0.00%');
$helper->log($worksheet->getCell('B7')->getValue());
$helper->log('DISC() Result is ' . $worksheet->getCell('B7')->getFormattedValue());

View File

@ -0,0 +1,30 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the dollar value in fractional notation, into a dollar value expressed as a decimal.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
[1.01, 16],
[1.1, 16],
[1.03, 32],
[1.3, 32],
[1.12, 32],
];
$worksheet->fromArray($arguments, null, 'A1');
// Now the formula
for ($row = 1; $row <= 5; ++$row) {
$worksheet->setCellValue("C{$row}", "=DOLLARDE(A{$row}, B{$row})");
$helper->log($worksheet->getCell("C{$row}")->getValue());
$helper->log('DOLLARDE() Result is ' . $worksheet->getCell("C{$row}")->getFormattedValue());
}

View File

@ -0,0 +1,30 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the dollar value expressed as a decimal number, into a dollar price, expressed as a fraction.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
[1.0625, 16],
[1.625, 16],
[1.09375, 32],
[1.9375, 32],
[1.375, 32],
];
$worksheet->fromArray($arguments, null, 'A1');
// Now the formula
for ($row = 1; $row <= 5; ++$row) {
$worksheet->setCellValue("C{$row}", "=DOLLARFR(A{$row}, B{$row})");
$helper->log($worksheet->getCell("C{$row}")->getValue());
$helper->log('DOLLARFR() Result is ' . $worksheet->getCell("C{$row}")->getFormattedValue());
}

View File

@ -0,0 +1,31 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the effective annual interest rate for a given nominal interest rate and number of');
$helper->log('compounding periods per year.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
[0.10, 4],
[0.10, 2],
[0.025, 2],
];
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B3')->getNumberFormat()->setFormatCode('0.00%');
// Now the formula
for ($row = 1; $row <= 3; ++$row) {
$worksheet->setCellValue("C{$row}", "=EFFECT(A{$row}, B{$row})");
$worksheet->getStyle("C{$row}")->getNumberFormat()->setFormatCode('0.00%');
$helper->log($worksheet->getCell("C{$row}")->getValue());
$helper->log('EFFECT() Result is ' . $worksheet->getCell("C{$row}")->getFormattedValue());
}

View File

@ -0,0 +1,36 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the Future Value of an investment with periodic constant payments and a constant interest rate.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Interest Rate', 0.05, 0.10],
['Pament Frequency', 12, 4],
['Duration (Years)', 5, 4],
['Investment', -1000.00, -2000.00],
['Payment Type', 0, 1],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:C1')->getNumberFormat()->setFormatCode('0.00%');
$worksheet->getStyle('B4:C4')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
$worksheet->setCellValue('B8', '=FV(B1/B2, B3*B2, B4)');
$worksheet->setCellValue('C8', '=FV(C1/C2, C3*C2, C4, null, C5)');
$worksheet->getStyle('B8:C8')->getNumberFormat()->setFormatCode('$#,##0.00');
$helper->log($worksheet->getCell('B8')->getValue());
$helper->log('FV() Result is ' . $worksheet->getCell('B8')->getFormattedValue());
$helper->log($worksheet->getCell('C6')->getValue());
$helper->log('FV() Result is ' . $worksheet->getCell('C8')->getFormattedValue());

View File

@ -0,0 +1,36 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the Future Value of an initial principal, after applying a series of compound interest rates.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Principal'],
[10000.00],
[null],
['Schedule'],
[0.05],
[0.05],
[0.035],
[0.035],
[0.035],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('A2')->getNumberFormat()->setFormatCode('$#,##0.00');
$worksheet->getStyle('A5:A9')->getNumberFormat()->setFormatCode('0.00%');
// Now the formula
$worksheet->setCellValue('B1', '=FVSCHEDULE(A2, A5:A9)');
$worksheet->getStyle('B1')->getNumberFormat()->setFormatCode('$#,##0.00');
$helper->log($worksheet->getCell('B1')->getValue());
$helper->log('FVSCHEDULE() Result is ' . $worksheet->getCell('B1')->getFormattedValue());

View File

@ -0,0 +1,32 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the interest rate for a fully invested security.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Settlement Date', DateHelper::getDateValue('01-Apr-2005')],
['Maturity Date', DateHelper::getDateValue('31-Mar-2010')],
['Investment', 1000.00],
['Investment', 2125.00],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
$worksheet->getStyle('B3:B4')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
$worksheet->setCellValue('B7', '=INTRATE(B1, B2, B3, B4)');
$worksheet->getStyle('B7')->getNumberFormat()->setFormatCode('0.00%');
$helper->log($worksheet->getCell('B7')->getValue());
$helper->log('INTRATE() Result is ' . $worksheet->getCell('B7')->getFormattedValue());

View File

@ -0,0 +1,37 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the interest payment, during a specific period of a loan or investment that is paid in,');
$helper->log('constant periodic payments, with a constant interest rate.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Interest Rate', 0.05],
['Number of Years', 5],
['Present Value', 50000.00],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1')->getNumberFormat()->setFormatCode('0.00%');
$worksheet->getStyle('B3')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
$baseRow = 6;
for ($month = 1; $month <= 12; ++$month) {
$row = (string) ($baseRow + $month);
$worksheet->setCellValue("A{$row}", "Payment for Mth {$month}");
$worksheet->setCellValue("B{$row}", "=IPMT(\$B\$1/12, {$month}, \$B\$2*12, \$B\$3)");
$worksheet->getStyle("B{$row}")->getNumberFormat()->setFormatCode('$#,##0.00;-$#,##0.00');
$helper->log($worksheet->getCell("B{$row}")->getValue());
$helper->log("IPMT() Month {$month} Result is " . $worksheet->getCell("B{$row}")->getFormattedValue());
}

View File

@ -0,0 +1,38 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the Internal Rate of Return for a supplied series of periodic cash flows.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Initial Investment', -100.00],
['Year 1 Income', 20.00],
['Year 2 Income', 24.00, 'IRR after 3 Years'],
['Year 3 Income', 28.80],
['Year 4 Income', 34.56, 'IRR after 5 Years'],
['Year 5 Income', 41.47],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B6')->getNumberFormat()->setFormatCode('$#,##0.00;-$#,##0.00');
// Now the formula
$worksheet->setCellValue('C4', '=IRR(B1:B4)');
$worksheet->getStyle('C4')->getNumberFormat()->setFormatCode('0.00%');
$helper->log($worksheet->getCell('C4')->getValue());
$helper->log('IRR() Result is ' . $worksheet->getCell('C4')->getFormattedValue());
$worksheet->setCellValue('C6', '=IRR(B1:B6)');
$worksheet->getStyle('C6')->getNumberFormat()->setFormatCode('0.00%');
$helper->log($worksheet->getCell('C6')->getValue());
$helper->log('IRR() Result is ' . $worksheet->getCell('C6')->getFormattedValue());

View File

@ -0,0 +1,36 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the interest paid during a specific period of a loan or investment.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Interest Rate', 0.05],
['Number of Years', 5],
['Present Value', 50000.00],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1')->getNumberFormat()->setFormatCode('0.00%');
$worksheet->getStyle('B3')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
$baseRow = 6;
for ($month = 1; $month <= 12; ++$month) {
$row = (string) ($baseRow + $month);
$worksheet->setCellValue("A{$row}", "Payment for Mth {$month}");
$worksheet->setCellValue("B{$row}", "=ISPMT(\$B\$1/12, {$month}, \$B\$2*12, \$B\$3)");
$worksheet->getStyle("B{$row}")->getNumberFormat()->setFormatCode('$#,##0.00;-$#,##0.00');
$helper->log($worksheet->getCell("B{$row}")->getValue());
$helper->log("ISPMT() Month {$month} Result is " . $worksheet->getCell("B{$row}")->getFormattedValue());
}

View File

@ -0,0 +1,42 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the Modified Internal Rate of Return for a supplied series of periodic cash flows.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Initial Investment', -100.00],
['Year 1 Income', 18.00],
['Year 2 Income', 22.50, 'MIRR after 3 Years'],
['Year 3 Income', 28.00],
['Year 4 Income', 35.50, 'MIRR after 5 Years'],
['Year 5 Income', 45.00],
[null],
['Finance Rate', 0.055],
['Re-invest Rate', 0.05],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B6')->getNumberFormat()->setFormatCode('$#,##0.00;-$#,##0.00');
$worksheet->getStyle('B8:B9')->getNumberFormat()->setFormatCode('0.00%');
// Now the formula
$worksheet->setCellValue('C4', '=MIRR(B1:B4, B8, B9)');
$worksheet->getStyle('C4')->getNumberFormat()->setFormatCode('0.00%');
$helper->log($worksheet->getCell('C4')->getValue());
$helper->log('MIRR() Result is ' . $worksheet->getCell('C4')->getFormattedValue());
$worksheet->setCellValue('C6', '=MIRR(B1:B6, B8, B9)');
$worksheet->getStyle('C6')->getNumberFormat()->setFormatCode('0.00%');
$helper->log($worksheet->getCell('C6')->getValue());
$helper->log('MIRR() Result is ' . $worksheet->getCell('C6')->getFormattedValue());

View File

@ -0,0 +1,31 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the nominal interest rate for a given effective interest rate and number of');
$helper->log('compounding periods per year.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
[0.10, 4],
[0.10, 2],
[0.025, 12],
];
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:B3')->getNumberFormat()->setFormatCode('0.00%');
// Now the formula
for ($row = 1; $row <= 3; ++$row) {
$worksheet->setCellValue("C{$row}", "=NOMINAL(A{$row}, B{$row})");
$worksheet->getStyle("C{$row}")->getNumberFormat()->setFormatCode('0.00%');
$helper->log($worksheet->getCell("C{$row}")->getValue());
$helper->log('NOMINAL() Result is ' . $worksheet->getCell("C{$row}")->getFormattedValue());
}

View File

@ -0,0 +1,39 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the number of periods required to pay off a loan, for a constant periodic payment');
$helper->log('and a constant interest rate.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Interest Rate', 0.04, 0.06],
['Payments per Year', 1, 4],
['Payment Amount', -6000.00, -2000],
['Present Value', 50000, 60000],
['Future Value', null, 30000],
['Payment Type', null, FinancialConstants::PAYMENT_BEGINNING_OF_PERIOD],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:C1')->getNumberFormat()->setFormatCode('0.00%');
$worksheet->getStyle('B3:C5')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
$worksheet->setCellValue('B8', '=NPER(B1/B2, B3, B4)');
$helper->log($worksheet->getCell('B8')->getValue());
$helper->log('NPER() Result is ' . $worksheet->getCell('B8')->getFormattedValue());
$worksheet->setCellValue('C8', '=NPER(C1/C2, C3, C4, C5, C6)');
$helper->log($worksheet->getCell('C8')->getValue());
$helper->log('NPER() Result is ' . $worksheet->getCell('C8')->getFormattedValue());

View File

@ -0,0 +1,43 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$helper->log('Returns the Net Present Value of an investment, based on a supplied discount rate,');
$helper->log('and a series of future payments and income.');
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$arguments = [
['Annual Discount Rate', 0.02, 0.05],
['Initial Investment Cost', -5000.00, -10000],
['Return from Year 1', 800.00, 2000.00],
['Return from Year 2', 950.00, 2400.00],
['Return from Year 3', 1080.00, 2900.00],
['Return from Year 4', 1220.00, 3500.00],
['Return from Year 5', 1500.00, 4100.00],
];
// Some basic formatting for the data
$worksheet->fromArray($arguments, null, 'A1');
$worksheet->getStyle('B1:C1')->getNumberFormat()->setFormatCode('0.00%');
$worksheet->getStyle('B2:C7')->getNumberFormat()->setFormatCode('$#,##0.00');
// Now the formula
// When initial investment is made at the end of the first period
$worksheet->setCellValue('B10', '=NPV(B1, B2:B7)');
$worksheet->getStyle('B10')->getNumberFormat()->setFormatCode('$#,##0.00');
$helper->log($worksheet->getCell('B10')->getValue());
$helper->log('NPV() Result is ' . $worksheet->getCell('B10')->getFormattedValue());
// When initial investment is made at the start of the first period
$worksheet->setCellValue('C10', '=NPV(C1, C3:C7) + C2');
$worksheet->getStyle('C10')->getNumberFormat()->setFormatCode('$#,##0.00');
$helper->log($worksheet->getCell('C10')->getValue());
$helper->log('NPV() Result is ' . $worksheet->getCell('C10')->getFormattedValue());

View File

@ -855,7 +855,7 @@ class Calculation
], ],
'DISC' => [ 'DISC' => [
'category' => Category::CATEGORY_FINANCIAL, 'category' => Category::CATEGORY_FINANCIAL,
'functionCall' => [Financial::class, 'DISC'], 'functionCall' => [Financial\Securities\Rates::class, 'discount'],
'argumentCount' => '4,5', 'argumentCount' => '4,5',
], ],
'DMAX' => [ 'DMAX' => [
@ -1429,7 +1429,7 @@ class Calculation
], ],
'INTRATE' => [ 'INTRATE' => [
'category' => Category::CATEGORY_FINANCIAL, 'category' => Category::CATEGORY_FINANCIAL,
'functionCall' => [Financial::class, 'INTRATE'], 'functionCall' => [Financial\Securities\Rates::class, 'interest'],
'argumentCount' => '4,5', 'argumentCount' => '4,5',
], ],
'IPMT' => [ 'IPMT' => [
@ -2078,7 +2078,7 @@ class Calculation
], ],
'RECEIVED' => [ 'RECEIVED' => [
'category' => Category::CATEGORY_FINANCIAL, 'category' => Category::CATEGORY_FINANCIAL,
'functionCall' => [Financial::class, 'RECEIVED'], 'functionCall' => [Financial\Securities\Price::class, 'received'],
'argumentCount' => '4-5', 'argumentCount' => '4-5',
], ],
'REPLACE' => [ 'REPLACE' => [

View File

@ -16,7 +16,7 @@ class Helpers
* *
* @return bool TRUE if the year is a leap year, otherwise FALSE * @return bool TRUE if the year is a leap year, otherwise FALSE
*/ */
public static function isLeapYear($year) public static function isLeapYear($year): bool
{ {
return (($year % 4) === 0) && (($year % 100) !== 0) || (($year % 400) === 0); return (($year % 4) === 0) && (($year % 100) !== 0) || (($year % 400) === 0);
} }
@ -28,7 +28,7 @@ class Helpers
* *
* @return float Excel date/time serial value * @return float Excel date/time serial value
*/ */
public static function getDateValue($dateValue, bool $allowBool = true) public static function getDateValue($dateValue, bool $allowBool = true): float
{ {
if (is_object($dateValue)) { if (is_object($dateValue)) {
$retval = Date::PHPToExcel($dateValue); $retval = Date::PHPToExcel($dateValue);

View File

@ -10,6 +10,9 @@ use PhpOffice\PhpSpreadsheet\Calculation\Financial\InterestRate;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\TreasuryBill; use PhpOffice\PhpSpreadsheet\Calculation\Financial\TreasuryBill;
/**
* @deprecated 1.18.0
*/
class Financial class Financial
{ {
const FINANCIAL_MAX_ITERATIONS = 128; const FINANCIAL_MAX_ITERATIONS = 128;
@ -30,12 +33,12 @@ class Financial
* Use the periodic() method in the Financial\Securities\AccruedInterest class instead * Use the periodic() method in the Financial\Securities\AccruedInterest class instead
* *
* @param mixed $issue the security's issue date * @param mixed $issue the security's issue date
* @param mixed $firstinterest the security's first interest date * @param mixed $firstInterest the security's first interest date
* @param mixed $settlement The security's settlement date. * @param mixed $settlement The security's settlement date.
* The security settlement date is the date after the issue date * The security settlement date is the date after the issue date
* when the security is traded to the buyer. * when the security is traded to the buyer.
* @param mixed $rate the security's annual coupon rate * @param mixed $rate the security's annual coupon rate
* @param mixed $par The security's par value. * @param mixed $parValue The security's par value.
* If you omit par, ACCRINT uses $1,000. * If you omit par, ACCRINT uses $1,000.
* @param mixed $frequency The number of coupon payments per year. * @param mixed $frequency The number of coupon payments per year.
* Valid frequency values are: * Valid frequency values are:
@ -56,20 +59,20 @@ class Financial
*/ */
public static function ACCRINT( public static function ACCRINT(
$issue, $issue,
$firstinterest, $firstInterest,
$settlement, $settlement,
$rate, $rate,
$par = 1000, $parValue = 1000,
$frequency = 1, $frequency = 1,
$basis = 0, $basis = 0,
$calcMethod = true $calcMethod = true
) { ) {
return Securities\AccruedInterest::periodic( return Securities\AccruedInterest::periodic(
$issue, $issue,
$firstinterest, $firstInterest,
$settlement, $settlement,
$rate, $rate,
$par, $parValue,
$frequency, $frequency,
$basis, $basis,
$calcMethod $calcMethod
@ -92,7 +95,7 @@ class Financial
* @param mixed $issue The security's issue date * @param mixed $issue The security's issue date
* @param mixed $settlement The security's settlement (or maturity) date * @param mixed $settlement The security's settlement (or maturity) date
* @param mixed $rate The security's annual coupon rate * @param mixed $rate The security's annual coupon rate
* @param mixed $par The security's par value. * @param mixed $parValue The security's par value.
* If you omit par, ACCRINT uses $1,000. * If you omit par, ACCRINT uses $1,000.
* @param mixed $basis The type of day count to use. * @param mixed $basis The type of day count to use.
* 0 or omitted US (NASD) 30/360 * 0 or omitted US (NASD) 30/360
@ -103,9 +106,9 @@ class Financial
* *
* @return float|string Result, or a string containing an error * @return float|string Result, or a string containing an error
*/ */
public static function ACCRINTM($issue, $settlement, $rate, $par = 1000, $basis = 0) public static function ACCRINTM($issue, $settlement, $rate, $parValue = 1000, $basis = 0)
{ {
return Securities\AccruedInterest::atMaturity($issue, $settlement, $rate, $par, $basis); return Securities\AccruedInterest::atMaturity($issue, $settlement, $rate, $parValue, $basis);
} }
/** /**
@ -543,6 +546,11 @@ class Financial
* Excel Function: * Excel Function:
* DISC(settlement,maturity,price,redemption[,basis]) * DISC(settlement,maturity,price,redemption[,basis])
* *
* @Deprecated 1.18.0
*
* @see Financial\Securities\Rates::discount()
* Use the discount() method in the Financial\Securities\Rates class instead
*
* @param mixed $settlement The security's settlement date. * @param mixed $settlement The security's settlement date.
* The security settlement date is the date after the issue * The security settlement date is the date after the issue
* date when the security is traded to the buyer. * date when the security is traded to the buyer.
@ -561,30 +569,7 @@ class Financial
*/ */
public static function DISC($settlement, $maturity, $price, $redemption, $basis = 0) public static function DISC($settlement, $maturity, $price, $redemption, $basis = 0)
{ {
$settlement = Functions::flattenSingleValue($settlement); return Financial\Securities\Rates::discount($settlement, $maturity, $price, $redemption, $basis);
$maturity = Functions::flattenSingleValue($maturity);
$price = Functions::flattenSingleValue($price);
$redemption = Functions::flattenSingleValue($redemption);
$basis = Functions::flattenSingleValue($basis);
// Validate
if ((is_numeric($price)) && (is_numeric($redemption)) && (is_numeric($basis))) {
$price = (float) $price;
$redemption = (float) $redemption;
$basis = (int) $basis;
if (($price <= 0) || ($redemption <= 0)) {
return Functions::NAN();
}
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
}
return (1 - $price / $redemption) / $daysBetweenSettlementAndMaturity;
}
return Functions::VALUE();
} }
/** /**
@ -724,8 +709,14 @@ class Financial
* Excel Function: * Excel Function:
* INTRATE(settlement,maturity,investment,redemption[,basis]) * INTRATE(settlement,maturity,investment,redemption[,basis])
* *
* @Deprecated 1.18.0
*
* @see Financial\Securities\Rates::interest()
* Use the interest() method in the Financial\Securities\Rates class instead
*
* @param mixed $settlement The security's settlement date. * @param mixed $settlement The security's settlement date.
* The security settlement date is the date after the issue date when the security is traded to the buyer. * The security settlement date is the date after the issue date when the security
* is traded to the buyer.
* @param mixed $maturity The security's maturity date. * @param mixed $maturity The security's maturity date.
* The maturity date is the date when the security expires. * The maturity date is the date when the security expires.
* @param int $investment the amount invested in the security * @param int $investment the amount invested in the security
@ -741,30 +732,7 @@ class Financial
*/ */
public static function INTRATE($settlement, $maturity, $investment, $redemption, $basis = 0) public static function INTRATE($settlement, $maturity, $investment, $redemption, $basis = 0)
{ {
$settlement = Functions::flattenSingleValue($settlement); return Financial\Securities\Rates::interest($settlement, $maturity, $investment, $redemption, $basis);
$maturity = Functions::flattenSingleValue($maturity);
$investment = Functions::flattenSingleValue($investment);
$redemption = Functions::flattenSingleValue($redemption);
$basis = Functions::flattenSingleValue($basis);
// Validate
if ((is_numeric($investment)) && (is_numeric($redemption)) && (is_numeric($basis))) {
$investment = (float) $investment;
$redemption = (float) $redemption;
$basis = (int) $basis;
if (($investment <= 0) || ($redemption <= 0)) {
return Functions::NAN();
}
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
}
return (($redemption / $investment) - 1) / ($daysBetweenSettlementAndMaturity);
}
return Functions::VALUE();
} }
/** /**
@ -1174,7 +1142,12 @@ class Financial
/** /**
* RECEIVED. * RECEIVED.
* *
* Returns the price per $100 face value of a discounted security. * Returns the amount received at maturity for a fully invested Security.
*
* @Deprecated 1.18.0
*
* @see Financial\Securities\Price::received()
* Use the received() method in the Financial\Securities\Price class instead
* *
* @param mixed $settlement The security's settlement date. * @param mixed $settlement The security's settlement date.
* The security settlement date is the date after the issue date when the security * The security settlement date is the date after the issue date when the security
@ -1194,27 +1167,7 @@ class Financial
*/ */
public static function RECEIVED($settlement, $maturity, $investment, $discount, $basis = 0) public static function RECEIVED($settlement, $maturity, $investment, $discount, $basis = 0)
{ {
$settlement = Functions::flattenSingleValue($settlement); return Financial\Securities\Price::received($settlement, $maturity, $investment, $discount, $basis);
$maturity = Functions::flattenSingleValue($maturity);
$investment = (float) Functions::flattenSingleValue($investment);
$discount = (float) Functions::flattenSingleValue($discount);
$basis = (int) Functions::flattenSingleValue($basis);
// Validate
if ((is_numeric($investment)) && (is_numeric($discount)) && (is_numeric($basis))) {
if (($investment <= 0) || ($discount <= 0)) {
return Functions::NAN();
}
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
}
return $investment / (1 - ($discount * $daysBetweenSettlementAndMaturity));
}
return Functions::VALUE();
} }
/** /**

View File

@ -4,12 +4,11 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Amortization class Amortization
{ {
use BaseValidations;
/** /**
* AMORDEGRC. * AMORDEGRC.
* *
@ -40,24 +39,33 @@ class Amortization
* *
* @return float|string (string containing the error type if there is an error) * @return float|string (string containing the error type if there is an error)
*/ */
public static function AMORDEGRC($cost, $purchased, $firstPeriod, $salvage, $period, $rate, $basis = 0) public static function AMORDEGRC(
{ $cost,
$purchased,
$firstPeriod,
$salvage,
$period,
$rate,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$cost = Functions::flattenSingleValue($cost); $cost = Functions::flattenSingleValue($cost);
$purchased = Functions::flattenSingleValue($purchased); $purchased = Functions::flattenSingleValue($purchased);
$firstPeriod = Functions::flattenSingleValue($firstPeriod); $firstPeriod = Functions::flattenSingleValue($firstPeriod);
$salvage = Functions::flattenSingleValue($salvage); $salvage = Functions::flattenSingleValue($salvage);
$period = floor(Functions::flattenSingleValue($period)); $period = Functions::flattenSingleValue($period);
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$basis = ($basis === null) ? 0 : (int) Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$cost = self::validateFloat($cost); $cost = FinancialValidations::validateFloat($cost);
$purchased = self::validateDate($purchased); $purchased = FinancialValidations::validateDate($purchased);
$firstPeriod = self::validateDate($firstPeriod); $firstPeriod = FinancialValidations::validateDate($firstPeriod);
$salvage = self::validateFloat($salvage); $salvage = FinancialValidations::validateFloat($salvage);
$period = self::validateFloat($period); $period = FinancialValidations::validateInt($period);
$rate = self::validateFloat($rate); $rate = FinancialValidations::validateFloat($rate);
$basis = self::validateBasis($basis); $basis = FinancialValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -118,24 +126,33 @@ class Amortization
* *
* @return float|string (string containing the error type if there is an error) * @return float|string (string containing the error type if there is an error)
*/ */
public static function AMORLINC($cost, $purchased, $firstPeriod, $salvage, $period, $rate, $basis = 0) public static function AMORLINC(
{ $cost,
$purchased,
$firstPeriod,
$salvage,
$period,
$rate,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$cost = Functions::flattenSingleValue($cost); $cost = Functions::flattenSingleValue($cost);
$purchased = Functions::flattenSingleValue($purchased); $purchased = Functions::flattenSingleValue($purchased);
$firstPeriod = Functions::flattenSingleValue($firstPeriod); $firstPeriod = Functions::flattenSingleValue($firstPeriod);
$salvage = Functions::flattenSingleValue($salvage); $salvage = Functions::flattenSingleValue($salvage);
$period = Functions::flattenSingleValue($period); $period = Functions::flattenSingleValue($period);
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$basis = ($basis === null) ? 0 : (int) Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$cost = self::validateFloat($cost); $cost = FinancialValidations::validateFloat($cost);
$purchased = self::validateDate($purchased); $purchased = FinancialValidations::validateDate($purchased);
$firstPeriod = self::validateDate($firstPeriod); $firstPeriod = FinancialValidations::validateDate($firstPeriod);
$salvage = self::validateFloat($salvage); $salvage = FinancialValidations::validateFloat($salvage);
$period = self::validateFloat($period); $period = FinancialValidations::validateFloat($period);
$rate = self::validateFloat($rate); $rate = FinancialValidations::validateFloat($rate);
$basis = self::validateBasis($basis); $basis = FinancialValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -149,7 +166,10 @@ class Amortization
return $yearFrac; return $yearFrac;
} }
if (($basis == 1) && ($yearFrac < 1) && (DateTimeExcel\Helpers::isLeapYear($purchasedYear))) { if (
($basis == FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL) &&
($yearFrac < 1) && (DateTimeExcel\Helpers::isLeapYear($purchasedYear))
) {
$yearFrac *= 365 / 366; $yearFrac *= 365 / 366;
} }

View File

@ -1,72 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities\Constants as SecuritiesConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
trait BaseValidations
{
protected static function validateDate($date)
{
return DateTimeExcel\Helpers::getDateValue($date);
}
protected static function validateSettlementDate($settlement)
{
return self::validateDate($settlement);
}
protected static function validateMaturityDate($maturity)
{
return self::validateDate($maturity);
}
protected static function validateFloat($value): float
{
if (!is_numeric($value)) {
throw new Exception(Functions::VALUE());
}
return (float) $value;
}
protected static function validateInt($value): int
{
if (!is_numeric($value)) {
throw new Exception(Functions::VALUE());
}
return (int) floor($value);
}
protected static function validateFrequency($frequency): int
{
$frequency = self::validateInt($frequency);
if (
($frequency !== SecuritiesConstants::FREQUENCY_ANNUAL) &&
($frequency !== SecuritiesConstants::FREQUENCY_SEMI_ANNUAL) &&
($frequency !== SecuritiesConstants::FREQUENCY_QUARTERLY)
) {
throw new Exception(Functions::NAN());
}
return $frequency;
}
protected static function validateBasis($basis): int
{
if (!is_numeric($basis)) {
throw new Exception(Functions::VALUE());
}
$basis = (int) $basis;
if (($basis < 0) || ($basis > 4)) {
throw new Exception(Functions::NAN());
}
return $basis;
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\FinancialValidations;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class CashFlowValidations extends FinancialValidations
{
/**
* @param mixed $rate
*/
public static function validateRate($rate): float
{
$rate = self::validateFloat($rate);
if ($rate < 0.0) {
throw new Exception(Functions::NAN());
}
return $rate;
}
/**
* @param mixed $type
*/
public static function validatePeriodType($type): int
{
$rate = self::validateInt($type);
if (
$type !== FinancialConstants::PAYMENT_END_OF_PERIOD &&
$type !== FinancialConstants::PAYMENT_BEGINNING_OF_PERIOD
) {
throw new Exception(Functions::NAN());
}
return $rate;
}
/**
* @param mixed $presentValue
*/
public static function validatePresentValue($presentValue): float
{
return self::validateFloat($presentValue);
}
/**
* @param mixed $futureValue
*/
public static function validateFutureValue($futureValue): float
{
return self::validateFloat($futureValue);
}
}

View File

@ -3,13 +3,12 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Constant; namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Constant;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\BaseValidations; use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Periodic class Periodic
{ {
use BaseValidations;
/** /**
* FV. * FV.
* *
@ -31,29 +30,29 @@ class Periodic
* *
* @return float|string * @return float|string
*/ */
public static function futureValue($rate, $numberOfPeriods, $payment = 0, $presentValue = 0, $type = 0) public static function futureValue(
{ $rate,
$numberOfPeriods,
$payment = 0.0,
$presentValue = 0.0,
$type = FinancialConstants::PAYMENT_END_OF_PERIOD
) {
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$numberOfPeriods = Functions::flattenSingleValue($numberOfPeriods); $numberOfPeriods = Functions::flattenSingleValue($numberOfPeriods);
$payment = ($payment === null) ? 0.0 : Functions::flattenSingleValue($payment); $payment = ($payment === null) ? 0.0 : Functions::flattenSingleValue($payment);
$presentValue = ($presentValue === null) ? 0.0 : Functions::flattenSingleValue($presentValue); $presentValue = ($presentValue === null) ? 0.0 : Functions::flattenSingleValue($presentValue);
$type = ($type === null) ? 0 : Functions::flattenSingleValue($type); $type = ($type === null) ? FinancialConstants::PAYMENT_END_OF_PERIOD : Functions::flattenSingleValue($type);
try { try {
$rate = self::validateFloat($rate); $rate = CashFlowValidations::validateFloat($rate);
$numberOfPeriods = self::validateInt($numberOfPeriods); $numberOfPeriods = CashFlowValidations::validateInt($numberOfPeriods);
$payment = self::validateFloat($payment); $payment = CashFlowValidations::validateFloat($payment);
$presentValue = self::validateFloat($presentValue); $presentValue = CashFlowValidations::validatePresentValue($presentValue);
$type = self::validateInt($type); $type = CashFlowValidations::validatePeriodType($type);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
// Validate parameters
if ($numberOfPeriods < 0 || ($type !== 0 && $type !== 1)) {
return Functions::NAN();
}
return self::calculateFutureValue($rate, $numberOfPeriods, $payment, $presentValue, $type); return self::calculateFutureValue($rate, $numberOfPeriods, $payment, $presentValue, $type);
} }
@ -70,26 +69,31 @@ class Periodic
* *
* @return float|string Result, or a string containing an error * @return float|string Result, or a string containing an error
*/ */
public static function presentValue($rate, $numberOfPeriods, $payment = 0, $futureValue = 0, $type = 0) public static function presentValue(
{ $rate,
$numberOfPeriods,
$payment = 0.0,
$futureValue = 0.0,
$type = FinancialConstants::PAYMENT_END_OF_PERIOD
) {
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$numberOfPeriods = Functions::flattenSingleValue($numberOfPeriods); $numberOfPeriods = Functions::flattenSingleValue($numberOfPeriods);
$payment = ($payment === null) ? 0.0 : Functions::flattenSingleValue($payment); $payment = ($payment === null) ? 0.0 : Functions::flattenSingleValue($payment);
$futureValue = ($futureValue === null) ? 0.0 : Functions::flattenSingleValue($futureValue); $futureValue = ($futureValue === null) ? 0.0 : Functions::flattenSingleValue($futureValue);
$type = ($type === null) ? 0 : Functions::flattenSingleValue($type); $type = ($type === null) ? FinancialConstants::PAYMENT_END_OF_PERIOD : Functions::flattenSingleValue($type);
try { try {
$rate = self::validateFloat($rate); $rate = CashFlowValidations::validateRate($rate);
$numberOfPeriods = self::validateInt($numberOfPeriods); $numberOfPeriods = CashFlowValidations::validateInt($numberOfPeriods);
$payment = self::validateFloat($payment); $payment = CashFlowValidations::validateFloat($payment);
$futureValue = self::validateFloat($futureValue); $futureValue = CashFlowValidations::validateFutureValue($futureValue);
$type = self::validateInt($type); $type = CashFlowValidations::validatePeriodType($type);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
// Validate parameters // Validate parameters
if ($numberOfPeriods < 0 || ($type !== 0 && $type !== 1)) { if ($numberOfPeriods < 0) {
return Functions::NAN(); return Functions::NAN();
} }
@ -109,26 +113,31 @@ class Periodic
* *
* @return float|string Result, or a string containing an error * @return float|string Result, or a string containing an error
*/ */
public static function periods($rate, $payment, $presentValue, $futureValue = 0, $type = 0) public static function periods(
{ $rate,
$payment,
$presentValue,
$futureValue = 0.0,
$type = FinancialConstants::PAYMENT_END_OF_PERIOD
) {
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$payment = Functions::flattenSingleValue($payment); $payment = Functions::flattenSingleValue($payment);
$presentValue = Functions::flattenSingleValue($presentValue); $presentValue = Functions::flattenSingleValue($presentValue);
$futureValue = ($futureValue === null) ? 0.0 : Functions::flattenSingleValue($futureValue); $futureValue = ($futureValue === null) ? 0.0 : Functions::flattenSingleValue($futureValue);
$type = ($type === null) ? 0 : Functions::flattenSingleValue($type); $type = ($type === null) ? FinancialConstants::PAYMENT_END_OF_PERIOD : Functions::flattenSingleValue($type);
try { try {
$rate = self::validateFloat($rate); $rate = CashFlowValidations::validateRate($rate);
$payment = self::validateFloat($payment); $payment = CashFlowValidations::validateFloat($payment);
$presentValue = self::validateFloat($presentValue); $presentValue = CashFlowValidations::validatePresentValue($presentValue);
$futureValue = self::validateFloat($futureValue); $futureValue = CashFlowValidations::validateFutureValue($futureValue);
$type = self::validateInt($type); $type = CashFlowValidations::validatePeriodType($type);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
// Validate parameters // Validate parameters
if ($payment == 0.0 || ($type != 0 && $type != 1)) { if ($payment == 0.0) {
return Functions::NAN(); return Functions::NAN();
} }

View File

@ -3,14 +3,12 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Constant\Periodic; namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Constant\Periodic;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial; use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities\Constants; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Cumulative class Cumulative
{ {
use Financial\BaseValidations;
/** /**
* CUMIPMT. * CUMIPMT.
* *
@ -31,30 +29,33 @@ class Cumulative
* *
* @return float|string * @return float|string
*/ */
public static function interest($rate, $periods, $presentValue, $start, $end, $type = Constants::END_OF_PERIOD) public static function interest(
{ $rate,
$periods,
$presentValue,
$start,
$end,
$type = FinancialConstants::PAYMENT_END_OF_PERIOD
) {
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$periods = Functions::flattenSingleValue($periods); $periods = Functions::flattenSingleValue($periods);
$presentValue = Functions::flattenSingleValue($presentValue); $presentValue = Functions::flattenSingleValue($presentValue);
$start = Functions::flattenSingleValue($start); $start = Functions::flattenSingleValue($start);
$end = Functions::flattenSingleValue($end); $end = Functions::flattenSingleValue($end);
$type = ($type === null) ? 0 : Functions::flattenSingleValue($type); $type = ($type === null) ? FinancialConstants::PAYMENT_END_OF_PERIOD : Functions::flattenSingleValue($type);
try { try {
$rate = self::validateFloat($rate); $rate = CashFlowValidations::validateRate($rate);
$periods = self::validateInt($periods); $periods = CashFlowValidations::validateInt($periods);
$presentValue = self::validateFloat($presentValue); $presentValue = CashFlowValidations::validatePresentValue($presentValue);
$start = self::validateInt($start); $start = CashFlowValidations::validateInt($start);
$end = self::validateInt($end); $end = CashFlowValidations::validateInt($end);
$type = self::validateInt($type); $type = CashFlowValidations::validatePeriodType($type);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
// Validate parameters // Validate parameters
if ($type !== Constants::END_OF_PERIOD && $type !== Constants::BEGINNING_OF_PERIOD) {
return Functions::NAN();
}
if ($start < 1 || $start > $end) { if ($start < 1 || $start > $end) {
return Functions::NAN(); return Functions::NAN();
} }
@ -93,30 +94,33 @@ class Cumulative
* *
* @return float|string * @return float|string
*/ */
public static function principal($rate, $periods, $presentValue, $start, $end, $type = 0) public static function principal(
{ $rate,
$periods,
$presentValue,
$start,
$end,
$type = FinancialConstants::PAYMENT_END_OF_PERIOD
) {
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$periods = Functions::flattenSingleValue($periods); $periods = Functions::flattenSingleValue($periods);
$presentValue = Functions::flattenSingleValue($presentValue); $presentValue = Functions::flattenSingleValue($presentValue);
$start = Functions::flattenSingleValue($start); $start = Functions::flattenSingleValue($start);
$end = Functions::flattenSingleValue($end); $end = Functions::flattenSingleValue($end);
$type = ($type === null) ? 0 : Functions::flattenSingleValue($type); $type = ($type === null) ? FinancialConstants::PAYMENT_END_OF_PERIOD : Functions::flattenSingleValue($type);
try { try {
$rate = self::validateFloat($rate); $rate = CashFlowValidations::validateRate($rate);
$periods = self::validateInt($periods); $periods = CashFlowValidations::validateInt($periods);
$presentValue = self::validateFloat($presentValue); $presentValue = CashFlowValidations::validatePresentValue($presentValue);
$start = self::validateInt($start); $start = CashFlowValidations::validateInt($start);
$end = self::validateInt($end); $end = CashFlowValidations::validateInt($end);
$type = self::validateInt($type); $type = CashFlowValidations::validatePeriodType($type);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
// Validate parameters // Validate parameters
if ($type !== 0 && $type !== 1) {
return Functions::NAN();
}
if ($start < 1 || $start > $end) { if ($start < 1 || $start > $end) {
return Functions::VALUE(); return Functions::VALUE();
} }

View File

@ -3,13 +3,12 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Constant\Periodic; namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Constant\Periodic;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\BaseValidations; use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Interest class Interest
{ {
use BaseValidations;
private const FINANCIAL_MAX_ITERATIONS = 128; private const FINANCIAL_MAX_ITERATIONS = 128;
private const FINANCIAL_PRECISION = 1.0e-08; private const FINANCIAL_PRECISION = 1.0e-08;
@ -32,30 +31,33 @@ class Interest
* *
* @return float|string * @return float|string
*/ */
public static function payment($interestRate, $period, $numberOfPeriods, $presentValue, $futureValue = 0, $type = 0) public static function payment(
{ $interestRate,
$period,
$numberOfPeriods,
$presentValue,
$futureValue = 0,
$type = FinancialConstants::PAYMENT_END_OF_PERIOD
) {
$interestRate = Functions::flattenSingleValue($interestRate); $interestRate = Functions::flattenSingleValue($interestRate);
$period = Functions::flattenSingleValue($period); $period = Functions::flattenSingleValue($period);
$numberOfPeriods = Functions::flattenSingleValue($numberOfPeriods); $numberOfPeriods = Functions::flattenSingleValue($numberOfPeriods);
$presentValue = Functions::flattenSingleValue($presentValue); $presentValue = Functions::flattenSingleValue($presentValue);
$futureValue = Functions::flattenSingleValue($futureValue); $futureValue = ($futureValue === null) ? 0.0 : Functions::flattenSingleValue($futureValue);
$type = Functions::flattenSingleValue($type); $type = ($type === null) ? FinancialConstants::PAYMENT_END_OF_PERIOD : Functions::flattenSingleValue($type);
try { try {
$interestRate = self::validateFloat($interestRate); $interestRate = CashFlowValidations::validateRate($interestRate);
$period = self::validateInt($period); $period = CashFlowValidations::validateInt($period);
$numberOfPeriods = self::validateInt($numberOfPeriods); $numberOfPeriods = CashFlowValidations::validateInt($numberOfPeriods);
$presentValue = self::validateFloat($presentValue); $presentValue = CashFlowValidations::validatePresentValue($presentValue);
$futureValue = self::validateFloat($futureValue); $futureValue = CashFlowValidations::validateFutureValue($futureValue);
$type = self::validateInt($type); $type = CashFlowValidations::validatePeriodType($type);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
// Validate parameters // Validate parameters
if ($type != 0 && $type != 1) {
return Functions::NAN();
}
if ($period <= 0 || $period > $numberOfPeriods) { if ($period <= 0 || $period > $numberOfPeriods) {
return Functions::NAN(); return Functions::NAN();
} }
@ -94,17 +96,19 @@ class Interest
$principleRemaining = Functions::flattenSingleValue($principleRemaining); $principleRemaining = Functions::flattenSingleValue($principleRemaining);
try { try {
$interestRate = self::validateFloat($interestRate); $interestRate = CashFlowValidations::validateRate($interestRate);
$period = self::validateInt($period); $period = CashFlowValidations::validateInt($period);
$numberOfPeriods = self::validateInt($numberOfPeriods); $numberOfPeriods = CashFlowValidations::validateInt($numberOfPeriods);
$principleRemaining = self::validateFloat($principleRemaining); $principleRemaining = CashFlowValidations::validateFloat($principleRemaining);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
// Validate parameters
if ($period <= 0 || $period > $numberOfPeriods) { if ($period <= 0 || $period > $numberOfPeriods) {
return Functions::NAN(); return Functions::NAN();
} }
// Return value // Return value
$returnValue = 0; $returnValue = 0;
@ -148,22 +152,28 @@ class Interest
* *
* @return float|string * @return float|string
*/ */
public static function rate($numberOfPeriods, $payment, $presentValue, $futureValue = 0.0, $type = 0, $guess = 0.1) public static function rate(
{ $numberOfPeriods,
$payment,
$presentValue,
$futureValue = 0.0,
$type = FinancialConstants::PAYMENT_END_OF_PERIOD,
$guess = 0.1
) {
$numberOfPeriods = Functions::flattenSingleValue($numberOfPeriods); $numberOfPeriods = Functions::flattenSingleValue($numberOfPeriods);
$payment = Functions::flattenSingleValue($payment); $payment = Functions::flattenSingleValue($payment);
$presentValue = Functions::flattenSingleValue($presentValue); $presentValue = Functions::flattenSingleValue($presentValue);
$futureValue = ($futureValue === null) ? 0.0 : Functions::flattenSingleValue($futureValue); $futureValue = ($futureValue === null) ? 0.0 : Functions::flattenSingleValue($futureValue);
$type = ($type === null) ? 0 : Functions::flattenSingleValue($type); $type = ($type === null) ? FinancialConstants::PAYMENT_END_OF_PERIOD : Functions::flattenSingleValue($type);
$guess = ($guess === null) ? 0.1 : Functions::flattenSingleValue($guess); $guess = ($guess === null) ? 0.1 : Functions::flattenSingleValue($guess);
try { try {
$numberOfPeriods = self::validateInt($numberOfPeriods); $numberOfPeriods = CashFlowValidations::validateInt($numberOfPeriods);
$payment = self::validateFloat($payment); $payment = CashFlowValidations::validateFloat($payment);
$presentValue = self::validateFloat($presentValue); $presentValue = CashFlowValidations::validatePresentValue($presentValue);
$futureValue = self::validateFloat($futureValue); $futureValue = CashFlowValidations::validateFutureValue($futureValue);
$type = self::validateInt($type); $type = CashFlowValidations::validatePeriodType($type);
$guess = self::validateFloat($guess); $guess = CashFlowValidations::validateFloat($guess);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -188,7 +198,7 @@ class Interest
private static function rateNextGuess($rate, $numberOfPeriods, $payment, $presentValue, $futureValue, $type) private static function rateNextGuess($rate, $numberOfPeriods, $payment, $presentValue, $futureValue, $type)
{ {
if ($rate == 0) { if ($rate == 0.0) {
return Functions::NAN(); return Functions::NAN();
} }
$tt1 = ($rate + 1) ** $numberOfPeriods; $tt1 = ($rate + 1) ** $numberOfPeriods;

View File

@ -2,6 +2,8 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Constant\Periodic; namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Constant\Periodic;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
class InterestAndPrincipal class InterestAndPrincipal
{ {
protected $interest; protected $interest;
@ -14,14 +16,14 @@ class InterestAndPrincipal
int $numberOfPeriods = 0, int $numberOfPeriods = 0,
float $presentValue = 0, float $presentValue = 0,
float $futureValue = 0, float $futureValue = 0,
int $type = 0 int $type = FinancialConstants::PAYMENT_END_OF_PERIOD
) { ) {
$payment = Payments::annuity($rate, $numberOfPeriods, $presentValue, $futureValue, $type); $payment = Payments::annuity($rate, $numberOfPeriods, $presentValue, $futureValue, $type);
$capital = $presentValue; $capital = $presentValue;
$interest = 0.0; $interest = 0.0;
$principal = 0.0; $principal = 0.0;
for ($i = 1; $i <= $period; ++$i) { for ($i = 1; $i <= $period; ++$i) {
$interest = ($type && $i == 1) ? 0 : -$capital * $rate; $interest = ($type === FinancialConstants::PAYMENT_BEGINNING_OF_PERIOD && $i == 1) ? 0 : -$capital * $rate;
$principal = $payment - $interest; $principal = $payment - $interest;
$capital += $principal; $capital += $principal;
} }

View File

@ -3,13 +3,12 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Constant\Periodic; namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Constant\Periodic;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\BaseValidations; use PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\CashFlowValidations;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Payments class Payments
{ {
use BaseValidations;
/** /**
* PMT. * PMT.
* *
@ -23,29 +22,29 @@ class Payments
* *
* @return float|string Result, or a string containing an error * @return float|string Result, or a string containing an error
*/ */
public static function annuity($interestRate, $numberOfPeriods, $presentValue, $futureValue = 0, $type = 0) public static function annuity(
{ $interestRate,
$numberOfPeriods,
$presentValue,
$futureValue = 0,
$type = FinancialConstants::PAYMENT_END_OF_PERIOD
) {
$interestRate = Functions::flattenSingleValue($interestRate); $interestRate = Functions::flattenSingleValue($interestRate);
$numberOfPeriods = Functions::flattenSingleValue($numberOfPeriods); $numberOfPeriods = Functions::flattenSingleValue($numberOfPeriods);
$presentValue = Functions::flattenSingleValue($presentValue); $presentValue = Functions::flattenSingleValue($presentValue);
$futureValue = ($futureValue === null) ? 0.0 : Functions::flattenSingleValue($futureValue); $futureValue = ($futureValue === null) ? 0.0 : Functions::flattenSingleValue($futureValue);
$type = ($type === null) ? 0 : Functions::flattenSingleValue($type); $type = ($type === null) ? FinancialConstants::PAYMENT_END_OF_PERIOD : Functions::flattenSingleValue($type);
try { try {
$interestRate = self::validateFloat($interestRate); $interestRate = CashFlowValidations::validateRate($interestRate);
$numberOfPeriods = self::validateInt($numberOfPeriods); $numberOfPeriods = CashFlowValidations::validateInt($numberOfPeriods);
$presentValue = self::validateFloat($presentValue); $presentValue = CashFlowValidations::validatePresentValue($presentValue);
$futureValue = self::validateFloat($futureValue); $futureValue = CashFlowValidations::validateFutureValue($futureValue);
$type = self::validateInt($type); $type = CashFlowValidations::validatePeriodType($type);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
// Validate parameters
if ($type != 0 && $type != 1) {
return Functions::NAN();
}
// Calculate // Calculate
if ($interestRate != 0.0) { if ($interestRate != 0.0) {
return (-$futureValue - $presentValue * (1 + $interestRate) ** $numberOfPeriods) / return (-$futureValue - $presentValue * (1 + $interestRate) ** $numberOfPeriods) /
@ -76,30 +75,27 @@ class Payments
$numberOfPeriods, $numberOfPeriods,
$presentValue, $presentValue,
$futureValue = 0, $futureValue = 0,
$type = 0 $type = FinancialConstants::PAYMENT_END_OF_PERIOD
) { ) {
$interestRate = Functions::flattenSingleValue($interestRate); $interestRate = Functions::flattenSingleValue($interestRate);
$period = Functions::flattenSingleValue($period); $period = Functions::flattenSingleValue($period);
$numberOfPeriods = Functions::flattenSingleValue($numberOfPeriods); $numberOfPeriods = Functions::flattenSingleValue($numberOfPeriods);
$presentValue = Functions::flattenSingleValue($presentValue); $presentValue = Functions::flattenSingleValue($presentValue);
$futureValue = ($futureValue === null) ? 0.0 : Functions::flattenSingleValue($futureValue); $futureValue = ($futureValue === null) ? 0.0 : Functions::flattenSingleValue($futureValue);
$type = ($type === null) ? 0 : Functions::flattenSingleValue($type); $type = ($type === null) ? FinancialConstants::PAYMENT_END_OF_PERIOD : Functions::flattenSingleValue($type);
try { try {
$interestRate = self::validateFloat($interestRate); $interestRate = CashFlowValidations::validateRate($interestRate);
$period = self::validateInt($period); $period = CashFlowValidations::validateInt($period);
$numberOfPeriods = self::validateInt($numberOfPeriods); $numberOfPeriods = CashFlowValidations::validateInt($numberOfPeriods);
$presentValue = self::validateFloat($presentValue); $presentValue = CashFlowValidations::validatePresentValue($presentValue);
$futureValue = self::validateFloat($futureValue); $futureValue = CashFlowValidations::validateFutureValue($futureValue);
$type = self::validateInt($type); $type = CashFlowValidations::validatePeriodType($type);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
// Validate parameters // Validate parameters
if ($type != 0 && $type != 1) {
return Functions::NAN();
}
if ($period <= 0 || $period > $numberOfPeriods) { if ($period <= 0 || $period > $numberOfPeriods) {
return Functions::NAN(); return Functions::NAN();
} }

View File

@ -3,13 +3,10 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow; namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\BaseValidations;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Single class Single
{ {
use BaseValidations;
/** /**
* FVSCHEDULE. * FVSCHEDULE.
* *
@ -30,10 +27,10 @@ class Single
$schedule = Functions::flattenArray($schedule); $schedule = Functions::flattenArray($schedule);
try { try {
$principal = self::validateFloat($principal); $principal = CashFlowValidations::validateFloat($principal);
foreach ($schedule as $rate) { foreach ($schedule as $rate) {
$rate = self::validateFloat($rate); $rate = CashFlowValidations::validateFloat($rate);
$principal *= 1 + $rate; $principal *= 1 + $rate;
} }
} catch (Exception $e) { } catch (Exception $e) {
@ -48,22 +45,22 @@ class Single
* *
* Calculates the number of periods required for an investment to reach a specified value. * Calculates the number of periods required for an investment to reach a specified value.
* *
* @param float $rate Interest rate per period * @param mixed $rate Interest rate per period
* @param float $presentValue Present Value * @param mixed $presentValue Present Value
* @param float $futureValue Future Value * @param mixed $futureValue Future Value
* *
* @return float|string Result, or a string containing an error * @return float|string Result, or a string containing an error
*/ */
public static function periods($rate = 0.0, $presentValue = 0.0, $futureValue = 0.0) public static function periods($rate, $presentValue, $futureValue)
{ {
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$presentValue = Functions::flattenSingleValue($presentValue); $presentValue = Functions::flattenSingleValue($presentValue);
$futureValue = Functions::flattenSingleValue($futureValue); $futureValue = Functions::flattenSingleValue($futureValue);
try { try {
$rate = self::validateFloat($rate); $rate = CashFlowValidations::validateRate($rate);
$presentValue = self::validateFloat($presentValue); $presentValue = CashFlowValidations::validatePresentValue($presentValue);
$futureValue = self::validateFloat($futureValue); $futureValue = CashFlowValidations::validateFutureValue($futureValue);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -94,9 +91,9 @@ class Single
$futureValue = Functions::flattenSingleValue($futureValue); $futureValue = Functions::flattenSingleValue($futureValue);
try { try {
$periods = self::validateFloat($periods); $periods = CashFlowValidations::validateFloat($periods);
$presentValue = self::validateFloat($presentValue); $presentValue = CashFlowValidations::validatePresentValue($presentValue);
$futureValue = self::validateFloat($futureValue); $futureValue = CashFlowValidations::validateFutureValue($futureValue);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -0,0 +1,19 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
class Constants
{
public const BASIS_DAYS_PER_YEAR_NASD = 0;
public const BASIS_DAYS_PER_YEAR_ACTUAL = 1;
public const BASIS_DAYS_PER_YEAR_360 = 2;
public const BASIS_DAYS_PER_YEAR_365 = 3;
public const BASIS_DAYS_PER_YEAR_360_EUROPEAN = 4;
public const FREQUENCY_ANNUAL = 1;
public const FREQUENCY_SEMI_ANNUAL = 2;
public const FREQUENCY_QUARTERLY = 4;
public const PAYMENT_END_OF_PERIOD = 0;
public const PAYMENT_BEGINNING_OF_PERIOD = 1;
}

View File

@ -4,17 +4,12 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\Date;
class Coupons class Coupons
{ {
use BaseValidations;
public const FREQUENCY_ANNUAL = 1;
public const FREQUENCY_SEMI_ANNUAL = 2;
public const FREQUENCY_QUARTERLY = 4;
private const PERIOD_DATE_PREVIOUS = false; private const PERIOD_DATE_PREVIOUS = false;
private const PERIOD_DATE_NEXT = true; private const PERIOD_DATE_NEXT = true;
@ -45,19 +40,25 @@ class Coupons
* *
* @return float|string * @return float|string
*/ */
public static function COUPDAYBS($settlement, $maturity, $frequency, $basis = Helpers::DAYS_PER_YEAR_NASD) public static function COUPDAYBS(
{ $settlement,
$maturity,
$frequency,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity); $maturity = Functions::flattenSingleValue($maturity);
$frequency = Functions::flattenSingleValue($frequency); $frequency = Functions::flattenSingleValue($frequency);
$basis = ($basis === null) ? 0 : Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = FinancialValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = FinancialValidations::validateMaturityDate($maturity);
self::validateCouponPeriod($settlement, $maturity); self::validateCouponPeriod($settlement, $maturity);
$frequency = self::validateFrequency($frequency); $frequency = FinancialValidations::validateFrequency($frequency);
$basis = self::validateBasis($basis); $basis = FinancialValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -68,7 +69,7 @@ class Coupons
} }
$prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS); $prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS);
if ($basis === Helpers::DAYS_PER_YEAR_ACTUAL) { if ($basis === FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL) {
return abs(DateTimeExcel\Days::funcDays($prev, $settlement)); return abs(DateTimeExcel\Days::funcDays($prev, $settlement));
} }
@ -102,30 +103,36 @@ class Coupons
* *
* @return float|string * @return float|string
*/ */
public static function COUPDAYS($settlement, $maturity, $frequency, $basis = Helpers::DAYS_PER_YEAR_NASD) public static function COUPDAYS(
{ $settlement,
$maturity,
$frequency,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity); $maturity = Functions::flattenSingleValue($maturity);
$frequency = Functions::flattenSingleValue($frequency); $frequency = Functions::flattenSingleValue($frequency);
$basis = ($basis === null) ? 0 : Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = FinancialValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = FinancialValidations::validateMaturityDate($maturity);
self::validateCouponPeriod($settlement, $maturity); self::validateCouponPeriod($settlement, $maturity);
$frequency = self::validateFrequency($frequency); $frequency = FinancialValidations::validateFrequency($frequency);
$basis = self::validateBasis($basis); $basis = FinancialValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
switch ($basis) { switch ($basis) {
case Helpers::DAYS_PER_YEAR_365: case FinancialConstants::BASIS_DAYS_PER_YEAR_365:
// Actual/365 // Actual/365
return 365 / $frequency; return 365 / $frequency;
case Helpers::DAYS_PER_YEAR_ACTUAL: case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL:
// Actual/actual // Actual/actual
if ($frequency == self::FREQUENCY_ANNUAL) { if ($frequency == FinancialConstants::FREQUENCY_ANNUAL) {
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis); $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
return $daysPerYear / $frequency; return $daysPerYear / $frequency;
@ -167,19 +174,25 @@ class Coupons
* *
* @return float|string * @return float|string
*/ */
public static function COUPDAYSNC($settlement, $maturity, $frequency, $basis = Helpers::DAYS_PER_YEAR_NASD) public static function COUPDAYSNC(
{ $settlement,
$maturity,
$frequency,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity); $maturity = Functions::flattenSingleValue($maturity);
$frequency = Functions::flattenSingleValue($frequency); $frequency = Functions::flattenSingleValue($frequency);
$basis = ($basis === null) ? 0 : Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = FinancialValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = FinancialValidations::validateMaturityDate($maturity);
self::validateCouponPeriod($settlement, $maturity); self::validateCouponPeriod($settlement, $maturity);
$frequency = self::validateFrequency($frequency); $frequency = FinancialValidations::validateFrequency($frequency);
$basis = self::validateBasis($basis); $basis = FinancialValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -187,7 +200,7 @@ class Coupons
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis); $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
$next = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_NEXT); $next = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_NEXT);
if ($basis === Helpers::DAYS_PER_YEAR_NASD) { if ($basis === FinancialConstants::BASIS_DAYS_PER_YEAR_NASD) {
$settlementDate = Date::excelToDateTimeObject($settlement); $settlementDate = Date::excelToDateTimeObject($settlement);
$settlementEoM = Helpers::isLastDayOfMonth($settlementDate); $settlementEoM = Helpers::isLastDayOfMonth($settlementDate);
if ($settlementEoM) { if ($settlementEoM) {
@ -226,19 +239,25 @@ class Coupons
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
* depending on the value of the ReturnDateType flag * depending on the value of the ReturnDateType flag
*/ */
public static function COUPNCD($settlement, $maturity, $frequency, $basis = Helpers::DAYS_PER_YEAR_NASD) public static function COUPNCD(
{ $settlement,
$maturity,
$frequency,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity); $maturity = Functions::flattenSingleValue($maturity);
$frequency = Functions::flattenSingleValue($frequency); $frequency = Functions::flattenSingleValue($frequency);
$basis = ($basis === null) ? 0 : Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = FinancialValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = FinancialValidations::validateMaturityDate($maturity);
self::validateCouponPeriod($settlement, $maturity); self::validateCouponPeriod($settlement, $maturity);
$frequency = self::validateFrequency($frequency); $frequency = FinancialValidations::validateFrequency($frequency);
$basis = self::validateBasis($basis); $basis = FinancialValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -274,19 +293,25 @@ class Coupons
* *
* @return int|string * @return int|string
*/ */
public static function COUPNUM($settlement, $maturity, $frequency, $basis = Helpers::DAYS_PER_YEAR_NASD) public static function COUPNUM(
{ $settlement,
$maturity,
$frequency,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity); $maturity = Functions::flattenSingleValue($maturity);
$frequency = Functions::flattenSingleValue($frequency); $frequency = Functions::flattenSingleValue($frequency);
$basis = ($basis === null) ? 0 : Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = FinancialValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = FinancialValidations::validateMaturityDate($maturity);
self::validateCouponPeriod($settlement, $maturity); self::validateCouponPeriod($settlement, $maturity);
$frequency = self::validateFrequency($frequency); $frequency = FinancialValidations::validateFrequency($frequency);
$basis = self::validateBasis($basis); $basis = FinancialValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -294,7 +319,7 @@ class Coupons
$yearsBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac( $yearsBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac(
$settlement, $settlement,
$maturity, $maturity,
Helpers::DAYS_PER_YEAR_NASD FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
); );
return (int) ceil($yearsBetweenSettlementAndMaturity * $frequency); return (int) ceil($yearsBetweenSettlementAndMaturity * $frequency);
@ -328,19 +353,25 @@ class Coupons
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
* depending on the value of the ReturnDateType flag * depending on the value of the ReturnDateType flag
*/ */
public static function COUPPCD($settlement, $maturity, $frequency, $basis = Helpers::DAYS_PER_YEAR_NASD) public static function COUPPCD(
{ $settlement,
$maturity,
$frequency,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity); $maturity = Functions::flattenSingleValue($maturity);
$frequency = Functions::flattenSingleValue($frequency); $frequency = Functions::flattenSingleValue($frequency);
$basis = ($basis === null) ? 0 : Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = FinancialValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = FinancialValidations::validateMaturityDate($maturity);
self::validateCouponPeriod($settlement, $maturity); self::validateCouponPeriod($settlement, $maturity);
$frequency = self::validateFrequency($frequency); $frequency = FinancialValidations::validateFrequency($frequency);
$basis = self::validateBasis($basis); $basis = FinancialValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Depreciation class Depreciation
{ {
use BaseValidations;
/** /**
* DB. * DB.
* *
@ -127,7 +125,10 @@ class Depreciation
$previousDepreciation = 0; $previousDepreciation = 0;
$depreciation = 0; $depreciation = 0;
for ($per = 1; $per <= $period; ++$per) { for ($per = 1; $per <= $period; ++$per) {
$depreciation = min(($cost - $previousDepreciation) * ($factor / $life), ($cost - $salvage - $previousDepreciation)); $depreciation = min(
($cost - $previousDepreciation) * ($factor / $life),
($cost - $salvage - $previousDepreciation)
);
$previousDepreciation += $depreciation; $previousDepreciation += $depreciation;
} }
@ -205,7 +206,7 @@ class Depreciation
private static function validateCost($cost, bool $negativeValueAllowed = false): float private static function validateCost($cost, bool $negativeValueAllowed = false): float
{ {
$cost = self::validateFloat($cost); $cost = FinancialValidations::validateFloat($cost);
if ($cost < 0.0 && $negativeValueAllowed === false) { if ($cost < 0.0 && $negativeValueAllowed === false) {
throw new Exception(Functions::NAN()); throw new Exception(Functions::NAN());
} }
@ -215,7 +216,7 @@ class Depreciation
private static function validateSalvage($salvage, bool $negativeValueAllowed = false): float private static function validateSalvage($salvage, bool $negativeValueAllowed = false): float
{ {
$salvage = self::validateFloat($salvage); $salvage = FinancialValidations::validateFloat($salvage);
if ($salvage < 0.0 && $negativeValueAllowed === false) { if ($salvage < 0.0 && $negativeValueAllowed === false) {
throw new Exception(Functions::NAN()); throw new Exception(Functions::NAN());
} }
@ -225,7 +226,7 @@ class Depreciation
private static function validateLife($life, bool $negativeValueAllowed = false): float private static function validateLife($life, bool $negativeValueAllowed = false): float
{ {
$life = self::validateFloat($life); $life = FinancialValidations::validateFloat($life);
if ($life < 0.0 && $negativeValueAllowed === false) { if ($life < 0.0 && $negativeValueAllowed === false) {
throw new Exception(Functions::NAN()); throw new Exception(Functions::NAN());
} }
@ -235,7 +236,7 @@ class Depreciation
private static function validatePeriod($period, bool $negativeValueAllowed = false): float private static function validatePeriod($period, bool $negativeValueAllowed = false): float
{ {
$period = self::validateFloat($period); $period = FinancialValidations::validateFloat($period);
if ($period <= 0.0 && $negativeValueAllowed === false) { if ($period <= 0.0 && $negativeValueAllowed === false) {
throw new Exception(Functions::NAN()); throw new Exception(Functions::NAN());
} }
@ -245,7 +246,7 @@ class Depreciation
private static function validateMonth($month): int private static function validateMonth($month): int
{ {
$month = self::validateInt($month); $month = FinancialValidations::validateInt($month);
if ($month < 1) { if ($month < 1) {
throw new Exception(Functions::NAN()); throw new Exception(Functions::NAN());
} }
@ -255,7 +256,7 @@ class Depreciation
private static function validateFactor($factor): float private static function validateFactor($factor): float
{ {
$factor = self::validateFloat($factor); $factor = FinancialValidations::validateFloat($factor);
if ($factor <= 0.0) { if ($factor <= 0.0) {
throw new Exception(Functions::NAN()); throw new Exception(Functions::NAN());
} }

View File

@ -1,20 +1,42 @@
<?php <?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities; namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities\Constants as SecuritiesConstants; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
trait BaseValidations class FinancialValidations
{ {
protected static function validateDate($date) /**
* @param mixed $date
*/
public static function validateDate($date): float
{ {
return DateTimeExcel\Helpers::getDateValue($date); return DateTimeExcel\Helpers::getDateValue($date);
} }
protected static function validateFloat($value): float /**
* @param mixed $settlement
*/
public static function validateSettlementDate($settlement): float
{
return self::validateDate($settlement);
}
/**
* @param mixed $maturity
*/
public static function validateMaturityDate($maturity): float
{
return self::validateDate($maturity);
}
/**
* @param mixed $value
*/
public static function validateFloat($value): float
{ {
if (!is_numeric($value)) { if (!is_numeric($value)) {
throw new Exception(Functions::VALUE()); throw new Exception(Functions::VALUE());
@ -23,29 +45,22 @@ trait BaseValidations
return (float) $value; return (float) $value;
} }
protected static function validateSettlementDate($settlement) /**
* @param mixed $value
*/
public static function validateInt($value): int
{ {
return self::validateDate($settlement); if (!is_numeric($value)) {
throw new Exception(Functions::VALUE());
} }
protected static function validateMaturityDate($maturity) return (int) floor((float) $value);
{
return self::validateDate($maturity);
} }
protected static function validateIssueDate($issue) /**
{ * @param mixed $rate
return self::validateDate($issue); */
} public static function validateRate($rate): float
protected static function validateSecurityPeriod($settlement, $maturity): void
{
if ($settlement >= $maturity) {
throw new Exception(Functions::NAN());
}
}
protected static function validateRate($rate): float
{ {
$rate = self::validateFloat($rate); $rate = self::validateFloat($rate);
if ($rate < 0.0) { if ($rate < 0.0) {
@ -55,67 +70,16 @@ trait BaseValidations
return $rate; return $rate;
} }
protected static function validateParValue($parValue): float /**
* @param mixed $frequency
*/
public static function validateFrequency($frequency): int
{ {
$parValue = self::validateFloat($parValue); $frequency = self::validateInt($frequency);
if ($parValue < 0.0) {
throw new Exception(Functions::NAN());
}
return $parValue;
}
protected static function validatePrice($price): float
{
$price = self::validateFloat($price);
if ($price < 0.0) {
throw new Exception(Functions::NAN());
}
return $price;
}
protected static function validateYield($yield): float
{
$yield = self::validateFloat($yield);
if ($yield < 0.0) {
throw new Exception(Functions::NAN());
}
return $yield;
}
protected static function validateRedemption($redemption): float
{
$redemption = self::validateFloat($redemption);
if ($redemption <= 0.0) {
throw new Exception(Functions::NAN());
}
return $redemption;
}
protected static function validateDiscount($discount): float
{
$discount = self::validateFloat($discount);
if ($discount <= 0.0) {
throw new Exception(Functions::NAN());
}
return $discount;
}
protected static function validateFrequency($frequency): int
{
if (!is_numeric($frequency)) {
throw new Exception(Functions::VALUE());
}
$frequency = (int) $frequency;
if ( if (
($frequency !== SecuritiesConstants::FREQUENCY_ANNUAL) && ($frequency !== FinancialConstants::FREQUENCY_ANNUAL) &&
($frequency !== SecuritiesConstants::FREQUENCY_SEMI_ANNUAL) && ($frequency !== FinancialConstants::FREQUENCY_SEMI_ANNUAL) &&
($frequency !== SecuritiesConstants::FREQUENCY_QUARTERLY) ($frequency !== FinancialConstants::FREQUENCY_QUARTERLY)
) { ) {
throw new Exception(Functions::NAN()); throw new Exception(Functions::NAN());
} }
@ -123,7 +87,10 @@ trait BaseValidations
return $frequency; return $frequency;
} }
protected static function validateBasis($basis): int /**
* @param mixed $basis
*/
public static function validateBasis($basis): int
{ {
if (!is_numeric($basis)) { if (!is_numeric($basis)) {
throw new Exception(Functions::VALUE()); throw new Exception(Functions::VALUE());
@ -136,4 +103,56 @@ trait BaseValidations
return $basis; return $basis;
} }
/**
* @param mixed $price
*/
public static function validatePrice($price): float
{
$price = self::validateFloat($price);
if ($price < 0.0) {
throw new Exception(Functions::NAN());
}
return $price;
}
/**
* @param mixed $parValue
*/
public static function validateParValue($parValue): float
{
$parValue = self::validateFloat($parValue);
if ($parValue < 0.0) {
throw new Exception(Functions::NAN());
}
return $parValue;
}
/**
* @param mixed $yield
*/
public static function validateYield($yield): float
{
$yield = self::validateFloat($yield);
if ($yield < 0.0) {
throw new Exception(Functions::NAN());
}
return $yield;
}
/**
* @param mixed $discount
*/
public static function validateDiscount($discount): float
{
$discount = self::validateFloat($discount);
if ($discount <= 0.0) {
throw new Exception(Functions::NAN());
}
return $discount;
}
} }

View File

@ -4,16 +4,11 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
use DateTimeInterface; use DateTimeInterface;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Helpers class Helpers
{ {
public const DAYS_PER_YEAR_NASD = 0;
public const DAYS_PER_YEAR_ACTUAL = 1;
public const DAYS_PER_YEAR_360 = 2;
public const DAYS_PER_YEAR_365 = 3;
public const DAYS_PER_YEAR_360_EUROPEAN = 4;
/** /**
* daysPerYear. * daysPerYear.
* *
@ -36,13 +31,13 @@ class Helpers
} }
switch ($basis) { switch ($basis) {
case self::DAYS_PER_YEAR_NASD: case FinancialConstants::BASIS_DAYS_PER_YEAR_NASD:
case self::DAYS_PER_YEAR_360: case FinancialConstants::BASIS_DAYS_PER_YEAR_360:
case self::DAYS_PER_YEAR_360_EUROPEAN: case FinancialConstants::BASIS_DAYS_PER_YEAR_360_EUROPEAN:
return 360; return 360;
case self::DAYS_PER_YEAR_365: case FinancialConstants::BASIS_DAYS_PER_YEAR_365:
return 365; return 365;
case self::DAYS_PER_YEAR_ACTUAL: case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL:
return (DateTimeExcel\Helpers::isLeapYear($year)) ? 366 : 365; return (DateTimeExcel\Helpers::isLeapYear($year)) ? 366 : 365;
} }
@ -55,10 +50,8 @@ class Helpers
* Returns a boolean TRUE/FALSE indicating if this date is the last date of the month * Returns a boolean TRUE/FALSE indicating if this date is the last date of the month
* *
* @param DateTimeInterface $date The date for testing * @param DateTimeInterface $date The date for testing
*
* @return bool
*/ */
public static function isLastDayOfMonth(DateTimeInterface $date) public static function isLastDayOfMonth(DateTimeInterface $date): bool
{ {
return $date->format('d') === $date->format('t'); return $date->format('d') === $date->format('t');
} }

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class InterestRate class InterestRate
{ {
use BaseValidations;
/** /**
* EFFECT. * EFFECT.
* *
@ -29,8 +27,8 @@ class InterestRate
$periodsPerYear = Functions::flattenSingleValue($periodsPerYear); $periodsPerYear = Functions::flattenSingleValue($periodsPerYear);
try { try {
$nominalRate = self::validateFloat($nominalRate); $nominalRate = FinancialValidations::validateFloat($nominalRate);
$periodsPerYear = self::validateInt($periodsPerYear); $periodsPerYear = FinancialValidations::validateInt($periodsPerYear);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -58,8 +56,8 @@ class InterestRate
$periodsPerYear = Functions::flattenSingleValue($periodsPerYear); $periodsPerYear = Functions::flattenSingleValue($periodsPerYear);
try { try {
$effectiveRate = self::validateFloat($effectiveRate); $effectiveRate = FinancialValidations::validateFloat($effectiveRate);
$periodsPerYear = self::validateInt($periodsPerYear); $periodsPerYear = FinancialValidations::validateInt($periodsPerYear);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -4,12 +4,11 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\YearFrac; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\YearFrac;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class AccruedInterest class AccruedInterest
{ {
use BaseValidations;
public const ACCRINT_CALCMODE_ISSUE_TO_SETTLEMENT = true; public const ACCRINT_CALCMODE_ISSUE_TO_SETTLEMENT = true;
public const ACCRINT_CALCMODE_FIRST_INTEREST_TO_SETTLEMENT = false; public const ACCRINT_CALCMODE_FIRST_INTEREST_TO_SETTLEMENT = false;
@ -23,7 +22,7 @@ class AccruedInterest
* ACCRINT(issue,firstinterest,settlement,rate,par,frequency[,basis][,calc_method]) * ACCRINT(issue,firstinterest,settlement,rate,par,frequency[,basis][,calc_method])
* *
* @param mixed $issue the security's issue date * @param mixed $issue the security's issue date
* @param mixed $firstinterest the security's first interest date * @param mixed $firstInterest the security's first interest date
* @param mixed $settlement The security's settlement date. * @param mixed $settlement The security's settlement date.
* The security settlement date is the date after the issue date * The security settlement date is the date after the issue date
* when the security is traded to the buyer. * when the security is traded to the buyer.
@ -47,30 +46,34 @@ class AccruedInterest
*/ */
public static function periodic( public static function periodic(
$issue, $issue,
$firstinterest, $firstInterest,
$settlement, $settlement,
$rate, $rate,
$parValue = 1000, $parValue = 1000,
$frequency = 1, $frequency = FinancialConstants::FREQUENCY_ANNUAL,
$basis = 0, $basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD,
$calcMethod = self::ACCRINT_CALCMODE_ISSUE_TO_SETTLEMENT $calcMethod = self::ACCRINT_CALCMODE_ISSUE_TO_SETTLEMENT
) { ) {
$issue = Functions::flattenSingleValue($issue); $issue = Functions::flattenSingleValue($issue);
$firstinterest = Functions::flattenSingleValue($firstinterest); $firstInterest = Functions::flattenSingleValue($firstInterest);
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$parValue = ($parValue === null) ? 1000 : Functions::flattenSingleValue($parValue); $parValue = ($parValue === null) ? 1000 : Functions::flattenSingleValue($parValue);
$frequency = ($frequency === null) ? 1 : Functions::flattenSingleValue($frequency); $frequency = ($frequency === null)
$basis = ($basis === null) ? 0 : Functions::flattenSingleValue($basis); ? FinancialConstants::FREQUENCY_ANNUAL
: Functions::flattenSingleValue($frequency);
$basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$issue = self::validateIssueDate($issue); $issue = SecurityValidations::validateIssueDate($issue);
$settlement = self::validateSettlementDate($settlement); $settlement = SecurityValidations::validateSettlementDate($settlement);
self::validateSecurityPeriod($issue, $settlement); SecurityValidations::validateSecurityPeriod($issue, $settlement);
$rate = self::validateRate($rate); $rate = SecurityValidations::validateRate($rate);
$parValue = self::validateParValue($parValue); $parValue = SecurityValidations::validateParValue($parValue);
$frequency = self::validateFrequency($frequency); $frequency = SecurityValidations::validateFrequency($frequency);
$basis = self::validateBasis($basis); $basis = SecurityValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -80,7 +83,7 @@ class AccruedInterest
// return date error // return date error
return $daysBetweenIssueAndSettlement; return $daysBetweenIssueAndSettlement;
} }
$daysBetweenFirstInterestAndSettlement = YearFrac::funcYearFrac($firstinterest, $settlement, $basis); $daysBetweenFirstInterestAndSettlement = YearFrac::funcYearFrac($firstInterest, $settlement, $basis);
if (!is_numeric($daysBetweenFirstInterestAndSettlement)) { if (!is_numeric($daysBetweenFirstInterestAndSettlement)) {
// return date error // return date error
return $daysBetweenFirstInterestAndSettlement; return $daysBetweenFirstInterestAndSettlement;
@ -101,7 +104,7 @@ class AccruedInterest
* @param mixed $settlement The security's settlement (or maturity) date * @param mixed $settlement The security's settlement (or maturity) date
* @param mixed $rate The security's annual coupon rate * @param mixed $rate The security's annual coupon rate
* @param mixed $parValue The security's par value. * @param mixed $parValue The security's par value.
* If you omit par, ACCRINT uses $1,000. * If you omit parValue, ACCRINT uses $1,000.
* @param mixed $basis The type of day count to use. * @param mixed $basis The type of day count to use.
* 0 or omitted US (NASD) 30/360 * 0 or omitted US (NASD) 30/360
* 1 Actual/actual * 1 Actual/actual
@ -111,21 +114,28 @@ class AccruedInterest
* *
* @return float|string Result, or a string containing an error * @return float|string Result, or a string containing an error
*/ */
public static function atMaturity($issue, $settlement, $rate, $parValue = 1000, $basis = 0) public static function atMaturity(
{ $issue,
$settlement,
$rate,
$parValue = 1000,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$issue = Functions::flattenSingleValue($issue); $issue = Functions::flattenSingleValue($issue);
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$parValue = ($parValue === null) ? 1000 : Functions::flattenSingleValue($parValue); $parValue = ($parValue === null) ? 1000 : Functions::flattenSingleValue($parValue);
$basis = ($basis === null) ? 0 : Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$issue = self::validateIssueDate($issue); $issue = SecurityValidations::validateIssueDate($issue);
$settlement = self::validateSettlementDate($settlement); $settlement = SecurityValidations::validateSettlementDate($settlement);
self::validateSecurityPeriod($issue, $settlement); SecurityValidations::validateSecurityPeriod($issue, $settlement);
$rate = self::validateRate($rate); $rate = SecurityValidations::validateRate($rate);
$parValue = self::validateParValue($parValue); $parValue = SecurityValidations::validateParValue($parValue);
$basis = self::validateBasis($basis); $basis = SecurityValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -1,13 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities;
class Constants
{
public const FREQUENCY_ANNUAL = 1;
public const FREQUENCY_SEMI_ANNUAL = 2;
public const FREQUENCY_QUARTERLY = 4;
public const END_OF_PERIOD = 0;
public const BEGINNING_OF_PERIOD = 1;
}

View File

@ -4,14 +4,13 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Coupons; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Coupons;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Helpers; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Helpers;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Price class Price
{ {
use BaseValidations;
/** /**
* PRICE. * PRICE.
* *
@ -38,25 +37,34 @@ class Price
* *
* @return float|string Result, or a string containing an error * @return float|string Result, or a string containing an error
*/ */
public static function price($settlement, $maturity, $rate, $yield, $redemption, $frequency, $basis = 0) public static function price(
{ $settlement,
$maturity,
$rate,
$yield,
$redemption,
$frequency,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity); $maturity = Functions::flattenSingleValue($maturity);
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$yield = Functions::flattenSingleValue($yield); $yield = Functions::flattenSingleValue($yield);
$redemption = Functions::flattenSingleValue($redemption); $redemption = Functions::flattenSingleValue($redemption);
$frequency = Functions::flattenSingleValue($frequency); $frequency = Functions::flattenSingleValue($frequency);
$basis = Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = SecurityValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = SecurityValidations::validateMaturityDate($maturity);
self::validateSecurityPeriod($settlement, $maturity); SecurityValidations::validateSecurityPeriod($settlement, $maturity);
$rate = self::validateRate($rate); $rate = SecurityValidations::validateRate($rate);
$yield = self::validateYield($yield); $yield = SecurityValidations::validateYield($yield);
$redemption = self::validateRedemption($redemption); $redemption = SecurityValidations::validateRedemption($redemption);
$frequency = self::validateFrequency($frequency); $frequency = SecurityValidations::validateFrequency($frequency);
$basis = self::validateBasis($basis); $basis = SecurityValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -100,21 +108,28 @@ class Price
* *
* @return float|string Result, or a string containing an error * @return float|string Result, or a string containing an error
*/ */
public static function priceDiscounted($settlement, $maturity, $discount, $redemption, $basis = 0) public static function priceDiscounted(
{ $settlement,
$maturity,
$discount,
$redemption,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity); $maturity = Functions::flattenSingleValue($maturity);
$discount = Functions::flattenSingleValue($discount); $discount = Functions::flattenSingleValue($discount);
$redemption = Functions::flattenSingleValue($redemption); $redemption = Functions::flattenSingleValue($redemption);
$basis = Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = SecurityValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = SecurityValidations::validateMaturityDate($maturity);
self::validateSecurityPeriod($settlement, $maturity); SecurityValidations::validateSecurityPeriod($settlement, $maturity);
$discount = self::validateDiscount($discount); $discount = SecurityValidations::validateDiscount($discount);
$redemption = self::validateRedemption($redemption); $redemption = SecurityValidations::validateRedemption($redemption);
$basis = self::validateBasis($basis); $basis = SecurityValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -150,23 +165,31 @@ class Price
* *
* @return float|string Result, or a string containing an error * @return float|string Result, or a string containing an error
*/ */
public static function priceAtMaturity($settlement, $maturity, $issue, $rate, $yield, $basis = 0) public static function priceAtMaturity(
{ $settlement,
$maturity,
$issue,
$rate,
$yield,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity); $maturity = Functions::flattenSingleValue($maturity);
$issue = Functions::flattenSingleValue($issue); $issue = Functions::flattenSingleValue($issue);
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$yield = Functions::flattenSingleValue($yield); $yield = Functions::flattenSingleValue($yield);
$basis = Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = SecurityValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = SecurityValidations::validateMaturityDate($maturity);
self::validateSecurityPeriod($settlement, $maturity); SecurityValidations::validateSecurityPeriod($settlement, $maturity);
$issue = self::validateIssueDate($issue); $issue = SecurityValidations::validateIssueDate($issue);
$rate = self::validateRate($rate); $rate = SecurityValidations::validateRate($rate);
$yield = self::validateYield($yield); $yield = SecurityValidations::validateYield($yield);
$basis = self::validateBasis($basis); $basis = SecurityValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -198,4 +221,63 @@ class Price
(1 + (($daysBetweenSettlementAndMaturity / $daysPerYear) * $yield)) - (1 + (($daysBetweenSettlementAndMaturity / $daysPerYear) * $yield)) -
(($daysBetweenIssueAndSettlement / $daysPerYear) * $rate * 100); (($daysBetweenIssueAndSettlement / $daysPerYear) * $rate * 100);
} }
/**
* RECEIVED.
*
* Returns the amount received at maturity for a fully invested Security.
*
* @param mixed $settlement The security's settlement date.
* The security settlement date is the date after the issue date when the security
* is traded to the buyer.
* @param mixed $maturity The security's maturity date.
* The maturity date is the date when the security expires.
* @param mixed $investment The amount invested in the security
* @param mixed $discount The security's discount rate
* @param mixed $basis The type of day count to use.
* 0 or omitted US (NASD) 30/360
* 1 Actual/actual
* 2 Actual/360
* 3 Actual/365
* 4 European 30/360
*
* @return float|string Result, or a string containing an error
*/
public static function received(
$settlement,
$maturity,
$investment,
$discount,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity);
$investment = Functions::flattenSingleValue($investment);
$discount = Functions::flattenSingleValue($discount);
$basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try {
$settlement = SecurityValidations::validateSettlementDate($settlement);
$maturity = SecurityValidations::validateMaturityDate($maturity);
SecurityValidations::validateSecurityPeriod($settlement, $maturity);
$investment = SecurityValidations::validateFloat($investment);
$discount = SecurityValidations::validateDiscount($discount);
$basis = SecurityValidations::validateBasis($basis);
} catch (Exception $e) {
return $e->getMessage();
}
if ($investment <= 0) {
return Functions::NAN();
}
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
}
return $investment / (1 - ($discount * $daysBetweenSettlementAndMaturity));
}
} }

View File

@ -0,0 +1,137 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Rates
{
/**
* DISC.
*
* Returns the discount rate for a security.
*
* Excel Function:
* DISC(settlement,maturity,price,redemption[,basis])
*
* @param mixed $settlement The security's settlement date.
* The security settlement date is the date after the issue
* date when the security is traded to the buyer.
* @param mixed $maturity The security's maturity date.
* The maturity date is the date when the security expires.
* @param mixed $price The security's price per $100 face value
* @param mixed $redemption The security's redemption value per $100 face value
* @param mixed $basis The type of day count to use.
* 0 or omitted US (NASD) 30/360
* 1 Actual/actual
* 2 Actual/360
* 3 Actual/365
* 4 European 30/360
*
* @return float|string
*/
public static function discount(
$settlement,
$maturity,
$price,
$redemption,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity);
$price = Functions::flattenSingleValue($price);
$redemption = Functions::flattenSingleValue($redemption);
$basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try {
$settlement = SecurityValidations::validateSettlementDate($settlement);
$maturity = SecurityValidations::validateMaturityDate($maturity);
SecurityValidations::validateSecurityPeriod($settlement, $maturity);
$price = SecurityValidations::validatePrice($price);
$redemption = SecurityValidations::validateRedemption($redemption);
$basis = SecurityValidations::validateBasis($basis);
} catch (Exception $e) {
return $e->getMessage();
}
if ($price <= 0.0) {
return Functions::NAN();
}
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
}
return (1 - $price / $redemption) / $daysBetweenSettlementAndMaturity;
}
/**
* INTRATE.
*
* Returns the interest rate for a fully invested security.
*
* Excel Function:
* INTRATE(settlement,maturity,investment,redemption[,basis])
*
* @param mixed $settlement The security's settlement date.
* The security settlement date is the date after the issue date when the security
* is traded to the buyer.
* @param mixed $maturity The security's maturity date.
* The maturity date is the date when the security expires.
* @param mixed $investment the amount invested in the security
* @param mixed $redemption the amount to be received at maturity
* @param mixed $basis The type of day count to use.
* 0 or omitted US (NASD) 30/360
* 1 Actual/actual
* 2 Actual/360
* 3 Actual/365
* 4 European 30/360
*
* @return float|string
*/
public static function interest(
$settlement,
$maturity,
$investment,
$redemption,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity);
$investment = Functions::flattenSingleValue($investment);
$redemption = Functions::flattenSingleValue($redemption);
$basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try {
$settlement = SecurityValidations::validateSettlementDate($settlement);
$maturity = SecurityValidations::validateMaturityDate($maturity);
SecurityValidations::validateSecurityPeriod($settlement, $maturity);
$investment = SecurityValidations::validateFloat($investment);
$redemption = SecurityValidations::validateRedemption($redemption);
$basis = SecurityValidations::validateBasis($basis);
} catch (Exception $e) {
return $e->getMessage();
}
if ($investment <= 0) {
return Functions::NAN();
}
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
}
return (($redemption / $investment) - 1) / ($daysBetweenSettlementAndMaturity);
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\FinancialValidations;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class SecurityValidations extends FinancialValidations
{
/**
* @param mixed $issue
*/
public static function validateIssueDate($issue): float
{
return self::validateDate($issue);
}
/**
* @param mixed $settlement
* @param mixed $maturity
*/
public static function validateSecurityPeriod($settlement, $maturity): void
{
if ($settlement >= $maturity) {
throw new Exception(Functions::NAN());
}
}
/**
* @param mixed $redemption
*/
public static function validateRedemption($redemption): float
{
$redemption = self::validateFloat($redemption);
if ($redemption <= 0.0) {
throw new Exception(Functions::NAN());
}
return $redemption;
}
}

View File

@ -4,13 +4,12 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\Securities;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Helpers; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Helpers;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Yields class Yields
{ {
use BaseValidations;
/** /**
* YIELDDISC. * YIELDDISC.
* *
@ -21,9 +20,9 @@ class Yields
* is traded to the buyer. * is traded to the buyer.
* @param mixed $maturity The security's maturity date. * @param mixed $maturity The security's maturity date.
* The maturity date is the date when the security expires. * The maturity date is the date when the security expires.
* @param int $price The security's price per $100 face value * @param mixed $price The security's price per $100 face value
* @param int $redemption The security's redemption value per $100 face value * @param mixed $redemption The security's redemption value per $100 face value
* @param int $basis The type of day count to use. * @param mixed $basis The type of day count to use.
* 0 or omitted US (NASD) 30/360 * 0 or omitted US (NASD) 30/360
* 1 Actual/actual * 1 Actual/actual
* 2 Actual/360 * 2 Actual/360
@ -32,21 +31,28 @@ class Yields
* *
* @return float|string Result, or a string containing an error * @return float|string Result, or a string containing an error
*/ */
public static function yieldDiscounted($settlement, $maturity, $price, $redemption, $basis = 0) public static function yieldDiscounted(
{ $settlement,
$maturity,
$price,
$redemption,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity); $maturity = Functions::flattenSingleValue($maturity);
$price = Functions::flattenSingleValue($price); $price = Functions::flattenSingleValue($price);
$redemption = Functions::flattenSingleValue($redemption); $redemption = Functions::flattenSingleValue($redemption);
$basis = (int) Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = SecurityValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = SecurityValidations::validateMaturityDate($maturity);
self::validateSecurityPeriod($settlement, $maturity); SecurityValidations::validateSecurityPeriod($settlement, $maturity);
$price = self::validatePrice($price); $price = SecurityValidations::validatePrice($price);
$redemption = self::validateRedemption($redemption); $redemption = SecurityValidations::validateRedemption($redemption);
$basis = self::validateBasis($basis); $basis = SecurityValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -76,9 +82,9 @@ class Yields
* @param mixed $maturity The security's maturity date. * @param mixed $maturity The security's maturity date.
* The maturity date is the date when the security expires. * The maturity date is the date when the security expires.
* @param mixed $issue The security's issue date * @param mixed $issue The security's issue date
* @param int $rate The security's interest rate at date of issue * @param mixed $rate The security's interest rate at date of issue
* @param int $price The security's price per $100 face value * @param mixed $price The security's price per $100 face value
* @param int $basis The type of day count to use. * @param mixed $basis The type of day count to use.
* 0 or omitted US (NASD) 30/360 * 0 or omitted US (NASD) 30/360
* 1 Actual/actual * 1 Actual/actual
* 2 Actual/360 * 2 Actual/360
@ -87,23 +93,31 @@ class Yields
* *
* @return float|string Result, or a string containing an error * @return float|string Result, or a string containing an error
*/ */
public static function yieldAtMaturity($settlement, $maturity, $issue, $rate, $price, $basis = 0) public static function yieldAtMaturity(
{ $settlement,
$maturity,
$issue,
$rate,
$price,
$basis = FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
) {
$settlement = Functions::flattenSingleValue($settlement); $settlement = Functions::flattenSingleValue($settlement);
$maturity = Functions::flattenSingleValue($maturity); $maturity = Functions::flattenSingleValue($maturity);
$issue = Functions::flattenSingleValue($issue); $issue = Functions::flattenSingleValue($issue);
$rate = Functions::flattenSingleValue($rate); $rate = Functions::flattenSingleValue($rate);
$price = Functions::flattenSingleValue($price); $price = Functions::flattenSingleValue($price);
$basis = Functions::flattenSingleValue($basis); $basis = ($basis === null)
? FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
: Functions::flattenSingleValue($basis);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = SecurityValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = SecurityValidations::validateMaturityDate($maturity);
self::validateSecurityPeriod($settlement, $maturity); SecurityValidations::validateSecurityPeriod($settlement, $maturity);
$issue = self::validateIssueDate($issue); $issue = SecurityValidations::validateIssueDate($issue);
$rate = self::validateRate($rate); $rate = SecurityValidations::validateRate($rate);
$price = self::validatePrice($price); $price = SecurityValidations::validatePrice($price);
$basis = self::validateBasis($basis); $basis = SecurityValidations::validateBasis($basis);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -131,7 +145,8 @@ class Yields
} }
$daysBetweenSettlementAndMaturity *= $daysPerYear; $daysBetweenSettlementAndMaturity *= $daysPerYear;
return ((1 + (($daysBetweenIssueAndMaturity / $daysPerYear) * $rate) - (($price / 100) + (($daysBetweenIssueAndSettlement / $daysPerYear) * $rate))) / return ((1 + (($daysBetweenIssueAndMaturity / $daysPerYear) * $rate) -
(($price / 100) + (($daysBetweenIssueAndSettlement / $daysPerYear) * $rate))) /
(($price / 100) + (($daysBetweenIssueAndSettlement / $daysPerYear) * $rate))) * (($price / 100) + (($daysBetweenIssueAndSettlement / $daysPerYear) * $rate))) *
($daysPerYear / $daysBetweenSettlementAndMaturity); ($daysPerYear / $daysBetweenSettlementAndMaturity);
} }

View File

@ -4,12 +4,11 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class TreasuryBill class TreasuryBill
{ {
use BaseValidations;
/** /**
* TBILLEQ. * TBILLEQ.
* *
@ -31,20 +30,22 @@ class TreasuryBill
$discount = Functions::flattenSingleValue($discount); $discount = Functions::flattenSingleValue($discount);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = FinancialValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = FinancialValidations::validateMaturityDate($maturity);
$discount = FinancialValidations::validateFloat($discount);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
// Validate
if (is_numeric($discount)) {
if ($discount <= 0) { if ($discount <= 0) {
return Functions::NAN(); return Functions::NAN();
} }
$daysBetweenSettlementAndMaturity = $maturity - $settlement; $daysBetweenSettlementAndMaturity = $maturity - $settlement;
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($maturity), Helpers::DAYS_PER_YEAR_ACTUAL); $daysPerYear = Helpers::daysPerYear(
DateTimeExcel\Year::funcYear($maturity),
FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL
);
if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) { if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
return Functions::NAN(); return Functions::NAN();
@ -53,9 +54,6 @@ class TreasuryBill
return (365 * $discount) / (360 - $discount * $daysBetweenSettlementAndMaturity); return (365 * $discount) / (360 - $discount * $daysBetweenSettlementAndMaturity);
} }
return Functions::VALUE();
}
/** /**
* TBILLPRICE. * TBILLPRICE.
* *
@ -77,20 +75,22 @@ class TreasuryBill
$discount = Functions::flattenSingleValue($discount); $discount = Functions::flattenSingleValue($discount);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = FinancialValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = FinancialValidations::validateMaturityDate($maturity);
$discount = FinancialValidations::validateFloat($discount);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
// Validate
if (is_numeric($discount)) {
if ($discount <= 0) { if ($discount <= 0) {
return Functions::NAN(); return Functions::NAN();
} }
$daysBetweenSettlementAndMaturity = $maturity - $settlement; $daysBetweenSettlementAndMaturity = $maturity - $settlement;
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($maturity), Helpers::DAYS_PER_YEAR_ACTUAL); $daysPerYear = Helpers::daysPerYear(
DateTimeExcel\Year::funcYear($maturity),
FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL
);
if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) { if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
return Functions::NAN(); return Functions::NAN();
@ -104,9 +104,6 @@ class TreasuryBill
return $price; return $price;
} }
return Functions::VALUE();
}
/** /**
* TBILLYIELD. * TBILLYIELD.
* *
@ -128,20 +125,18 @@ class TreasuryBill
$price = Functions::flattenSingleValue($price); $price = Functions::flattenSingleValue($price);
try { try {
$settlement = self::validateSettlementDate($settlement); $settlement = FinancialValidations::validateSettlementDate($settlement);
$maturity = self::validateMaturityDate($maturity); $maturity = FinancialValidations::validateMaturityDate($maturity);
$price = FinancialValidations::validatePrice($price);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
// Validate
if (is_numeric($price)) {
if ($price <= 0) {
return Functions::NAN();
}
$daysBetweenSettlementAndMaturity = $maturity - $settlement; $daysBetweenSettlementAndMaturity = $maturity - $settlement;
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($maturity), Helpers::DAYS_PER_YEAR_ACTUAL); $daysPerYear = Helpers::daysPerYear(
DateTimeExcel\Year::funcYear($maturity),
FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL
);
if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) { if ($daysBetweenSettlementAndMaturity > $daysPerYear || $daysBetweenSettlementAndMaturity < 0) {
return Functions::NAN(); return Functions::NAN();
@ -149,7 +144,4 @@ class TreasuryBill
return ((100 - $price) / $price) * (360 / $daysBetweenSettlementAndMaturity); return ((100 - $price) / $price) * (360 / $daysBetweenSettlementAndMaturity);
} }
return Functions::VALUE();
}
} }

View File

@ -13,11 +13,15 @@ return [
], ],
[ [
15.5555555555559, 15.5555555555559,
'2008-03-05', '2008-08-31', '2008-05-01', 0.10, 1000, 2, 0, true, '2008-03-05', '2008-08-31', '2008-05-01', 0.10, 1000, 2, null,
],
[
15.5555555555559,
'2008-03-05', '2008-08-31', '2008-05-01', 0.10, 1000, 2, 0,
], ],
[ [
7.22222222222222, 7.22222222222222,
'2008-04-05', '2008-08-31', '2008-05-01', 0.10, 1000, 2, 0, true, '2008-04-05', '2008-08-31', '2008-05-01', 0.10, 1000, 2, 0,
], ],
[ [
200, 200,
@ -29,15 +33,15 @@ return [
], ],
[ [
32.363013698630134, 32.363013698630134,
'2012-01-01', '2012-03-31', '2012-02-15', 0.0525, 5000, 4, 3, 1, '2012-01-01', '2012-03-31', '2012-02-15', 0.0525, 5000, 4, 3,
], ],
[ [
6.472602739726027, 6.472602739726027,
'2012-01-01', '2012-03-31', '2012-02-15', 0.0525, 1000, 4, 3, 1, '2012-01-01', '2012-03-31', '2012-02-15', 0.0525, 1000, 4, 3,
], ],
[ [
18.05555555555555, 18.05555555555555,
'2017-08-05', '2017-11-10', '2017-10-10', 0.05, 2000, 4, 0, 1, '2017-08-05', '2017-11-10', '2017-10-10', 0.05, 2000, 4, 0,
], ],
[ [
'#NUM!', '#NUM!',

View File

@ -11,6 +11,10 @@ return [
800, 800,
'2010-01-01', '2010-12-31', 0.08, 10000, '2010-01-01', '2010-12-31', 0.08, 10000,
], ],
[
800,
'2010-01-01', '2010-12-31', 0.08, 10000, null,
],
[ [
365.958904109589, 365.958904109589,
'2012-01-01', '2013-02-15', 0.065, 5000, 3, '2012-01-01', '2013-02-15', 0.065, 5000, 3,

View File

@ -7,6 +7,14 @@ return [
776, 776,
2400, '2008-08-19', '2008-12-31', 300, 1, 0.15, 1, 2400, '2008-08-19', '2008-12-31', 300, 1, 0.15, 1,
], ],
[
776,
2400, '2008-08-19', '2008-12-31', 300, 1, 0.15, 0,
],
[
776,
2400, '2008-08-19', '2008-12-31', 300, 1, 0.15, null,
],
[ [
820, 820,
2400, '2008-08-19', '2008-12-31', 300, 1, 0.2, 1, 2400, '2008-08-19', '2008-12-31', 300, 1, 0.2, 1,
@ -51,6 +59,10 @@ return [
2813, 2813,
10000, '2012-03-01', '2012-12-31', 1500, 1, 0.3, 1, 10000, '2012-03-01', '2012-12-31', 1500, 1, 0.3, 1,
], ],
[
0.0,
500, '2012-03-01', '2012-12-31', 500, 3, 0.3, 1,
],
[ [
'#VALUE!', '#VALUE!',
'NaN', '2012-03-01', '2020-12-25', 20, 1, 0.2, 4, 'NaN', '2012-03-01', '2020-12-25', 20, 1, 0.2, 4,
@ -67,4 +79,20 @@ return [
'#VALUE!', '#VALUE!',
550, '2012-03-01', '2020-12-25', 'NaN', 1, 0.2, 4, 550, '2012-03-01', '2020-12-25', 'NaN', 1, 0.2, 4,
], ],
[
'#VALUE!',
550, '2012-03-01', '2020-12-25', 20, 'NaN', 0.2, 4,
],
[
'#VALUE!',
550, '2012-03-01', '2020-12-25', 20, 1, 'NaN', 4,
],
[
'#VALUE!',
550, '2012-03-01', '2020-12-25', 20, 1, 0.2, 'NaN',
],
[
'#NUM!',
550, '2012-03-01', '2020-12-25', 20, 1, 0.2, 99,
],
]; ];

View File

@ -11,6 +11,14 @@ return [
576, 576,
2400, '2008-08-19', '2008-12-31', 300, 2, 0.24, 1, 2400, '2008-08-19', '2008-12-31', 300, 2, 0.24, 1,
], ],
[
576,
2400, '2008-08-19', '2008-12-31', 300, 2, 0.24, 0,
],
[
576,
2400, '2008-08-19', '2008-12-31', 300, 2, 0.24, null,
],
[ [
30, 30,
150, '2011-01-01', '2011-09-30', 20, 1, 0.2, 4, 150, '2011-01-01', '2011-09-30', 20, 1, 0.2, 4,
@ -27,8 +35,36 @@ return [
0.0, 0.0,
150, '2011-01-01', '2011-09-30', 20, 5, 0.2, 4, 150, '2011-01-01', '2011-09-30', 20, 5, 0.2, 4,
], ],
[
'#VALUE!',
'NaN', '2011-01-01', '2011-09-30', 20, 1, 0.2, 4,
],
[
'#VALUE!',
150, '2011-01-01', 'notADate', 20, 1, 0.2, 4,
],
[ [
'#VALUE!', '#VALUE!',
150, 'notADate', '2011-09-30', 20, 1, 0.2, 4, 150, 'notADate', '2011-09-30', 20, 1, 0.2, 4,
], ],
[
'#VALUE!',
150, '2011-01-01', '2011-09-30', 'NaN', 1, 0.2, 4,
],
[
'#VALUE!',
150, '2011-01-01', '2011-09-30', 20, 'NaN', 0.2, 4,
],
[
'#VALUE!',
150, '2011-01-01', '2011-09-30', 20, 1, 'NaN', 4,
],
[
'#VALUE!',
150, '2011-01-01', '2011-09-30', 20, 1, 0.2, 'NaN',
],
[
'#NUM!',
550, '2012-03-01', '2020-12-25', 20, 1, 0.2, 99,
],
]; ];

View File

@ -16,6 +16,13 @@ return [
'2012-10-25', '2012-10-25',
4, 4,
], ],
[
66,
'2011-01-01',
'2012-10-25',
4,
null,
],
[ [
71, 71,
'2011-01-25', '2011-01-25',

View File

@ -16,6 +16,13 @@ return [
'2012-10-25', '2012-10-25',
4, 4,
], ],
[
90,
'2011-01-01',
'2012-10-25',
4,
null,
],
[ [
182.5, 182.5,
'25-Jan-2007', '25-Jan-2007',

View File

@ -16,6 +16,13 @@ return [
'2012-10-25', '2012-10-25',
4, 4,
], ],
[
24,
'2011-01-01',
'2012-10-25',
4,
null,
],
[ [
'#VALUE!', '#VALUE!',
'Invalid Date', 'Invalid Date',

View File

@ -16,6 +16,13 @@ return [
'2012-10-25', '2012-10-25',
4, 4,
], ],
[
40568,
'2011-01-01',
'2012-10-25',
4,
null,
],
[ [
'#VALUE!', '#VALUE!',
'Invalid Date', 'Invalid Date',

View File

@ -17,6 +17,13 @@ return [
4, 4,
0, 0,
], ],
[
8,
'2011-01-01',
'2012-10-25',
4,
null,
],
[ [
'#VALUE!', '#VALUE!',
'Invalid Date', 'Invalid Date',

View File

@ -16,6 +16,13 @@ return [
'2012-10-25', '2012-10-25',
4, 4,
], ],
[
40476,
'2011-01-01',
'2012-10-25',
4,
null,
],
[ [
'#VALUE!', '#VALUE!',
'Invalid Date', 'Invalid Date',

View File

@ -21,6 +21,15 @@ return [
1, 1,
0, 0,
], ],
[
-937.5,
0.0075,
360,
125000,
1,
1,
null,
],
[ [
-2299.6141712553544, -2299.6141712553544,
0.004175, 0.004175,

View File

@ -21,6 +21,15 @@ return [
1, 1,
0, 0,
], ],
[
-68.278271180977001,
0.0075,
360,
125000,
1,
1,
null,
],
[ [
-9025.875084814226, -9025.875084814226,
0.004175, 0.004175,

View File

@ -18,6 +18,14 @@ return [
95, 95,
100, 100,
], ],
[
0.01,
'2010-04-01',
'2015-03-31',
95,
100,
null,
],
[ [
'#NUM!', '#NUM!',
'2010-04-01', '2010-04-01',

View File

@ -1,15 +1,15 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Helpers; use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
return [ return [
[360, 2020, Helpers::DAYS_PER_YEAR_NASD], [360, 2020, FinancialConstants::BASIS_DAYS_PER_YEAR_NASD],
[366, 2020, Helpers::DAYS_PER_YEAR_ACTUAL], [366, 2020, FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL],
[365, 2021, Helpers::DAYS_PER_YEAR_ACTUAL], [365, 2021, FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL],
[360, 2020, Helpers::DAYS_PER_YEAR_360], [360, 2020, FinancialConstants::BASIS_DAYS_PER_YEAR_360],
[365, 2020, Helpers::DAYS_PER_YEAR_365], [365, 2020, FinancialConstants::BASIS_DAYS_PER_YEAR_365],
[360, 2020, Helpers::DAYS_PER_YEAR_360_EUROPEAN], [360, 2020, FinancialConstants::BASIS_DAYS_PER_YEAR_360_EUROPEAN],
[Functions::NAN(), 2020, 'Invalid'], [Functions::NAN(), 2020, 'Invalid'],
[Functions::NAN(), 2020, 999], [Functions::NAN(), 2020, 999],
]; ];

View File

@ -91,7 +91,23 @@ return [
'NaN', 'NaN',
], ],
[ [
'#NUM!', -33882857.54639115,
-0.10,
-100,
-100,
0,
1,
],
[
-10000.00,
0.0,
-100,
-100,
0,
1,
],
[
-100.0,
0.10, 0.10,
-1, -1,
-100, -100,

View File

@ -4,7 +4,7 @@
return [ return [
[ [
0.057680000000000002, 0.05768,
'2008-02-15', '2008-02-15',
'2008-05-15', '2008-05-15',
1000000, 1000000,
@ -12,12 +12,20 @@ return [
2, 2,
], ],
[ [
0.22500000000000001, 0.225,
'2005-04-01', '2005-04-01',
'2010-03-31', '2010-03-31',
1000, 1000,
2125, 2125,
], ],
[
0.225,
'2005-04-01',
'2010-03-31',
1000,
2125,
null,
],
[ [
'#VALUE!', '#VALUE!',
'2008-02-15', '2008-02-15',

View File

@ -33,6 +33,10 @@ return [
'#VALUE!', '#VALUE!',
[0.05, 50, 'NaN'], [0.05, 50, 'NaN'],
], ],
[
'#NUM!',
[-0.10, 50, 100],
],
[ [
'#NUM!', '#NUM!',
[0.00, 50, 100], [0.00, 50, 100],

View File

@ -192,6 +192,16 @@ return [
4, 4,
0, 0,
], ],
[
110.9216934,
'01-Apr-2012',
'31-Mar-2020',
0.12,
0.10,
100,
4,
null,
],
[ [
110.9217251, 110.9217251,
'01-Apr-2012', '01-Apr-2012',

View File

@ -5,6 +5,10 @@ return [
90.0, 90.0,
['01-Apr-2017', '31-Mar-2021', 0.025, 100], ['01-Apr-2017', '31-Mar-2021', 0.025, 100],
], ],
[
97.625,
['2008-02-15', '2008-11-30', 0.03, 100, null],
],
[ [
97.6311475409836, 97.6311475409836,
['2008-02-15', '2008-11-30', 0.03, 100, 1], ['2008-02-15', '2008-11-30', 0.03, 100, 1],

View File

@ -5,6 +5,10 @@ return [
99.98449887555694, 99.98449887555694,
'15-Feb-2008', '13-Apr-2008', '11-Nov-2007', 0.061, 0.061, 0, '15-Feb-2008', '13-Apr-2008', '11-Nov-2007', 0.061, 0.061, 0,
], ],
[
99.98449887555694,
'15-Feb-2008', '13-Apr-2008', '11-Nov-2007', 0.061, 0.061, null,
],
[ [
106.8486842105263, 106.8486842105263,
'1-Apr-2017', '31-Mar-2021', '1-Jan-2017', 0.055, 0.035, '1-Apr-2017', '31-Mar-2021', '1-Jan-2017', 0.055, 0.035,

View File

@ -9,8 +9,36 @@ return [
1120.2128404396835, 1120.2128404396835,
'6-Jul-2017', '15-Jan-2020', 1000, 0.0425, '6-Jul-2017', '15-Jan-2020', 1000, 0.0425,
], ],
[
1120.2128404396835,
'6-Jul-2017', '15-Jan-2020', 1000, 0.0425, null,
],
[ [
273037.54266211606, 273037.54266211606,
'15-Feb-2008', '15-Nov-2017', 100000, 0.065, '15-Feb-2008', '15-Nov-2017', 100000, 0.065,
], ],
[
'#VALUE!',
'Invalid Date', '15-Nov-2017', 100000, 0.065, 0,
],
[
'#VALUE!',
'15-Feb-2008', 'Invalid Date', 100000, 0.065, 0,
],
[
'#VALUE!',
'15-Feb-2008', '15-Nov-2017', 'NaN', 0.065, 0,
],
[
'#VALUE!',
'15-Feb-2008', '15-Nov-2017', 100000, 'NaN', 0,
],
[
'#VALUE!',
'15-Feb-2008', '15-Nov-2017', 100000, 0.065, 'NaN',
],
[
'#NUM!',
'15-Feb-2008', '15-Nov-2017', -1000, 0.065, 0,
],
]; ];

View File

@ -9,6 +9,14 @@ return [
0.06220123250590336, 0.06220123250590336,
'1-Jan-2017', '30-Jun-2017', 97, 100, '1-Jan-2017', '30-Jun-2017', 97, 100,
], ],
[
0.06220123250590336,
'1-Jan-2017', '30-Jun-2017', 97, 100, 0,
],
[
0.06220123250590336,
'1-Jan-2017', '30-Jun-2017', 97, 100, null,
],
[ [
'#VALUE!', '#VALUE!',
'Invalid', '30-Jun-2017', 97, 100, 'Invalid', '30-Jun-2017', 97, 100,

View File

@ -5,6 +5,10 @@ return [
0.06095433369153867, 0.06095433369153867,
'15-Mar-2008', '3-Nov-2008', '8-Nov-2007', 0.0625, 100.0123, 0, '15-Mar-2008', '3-Nov-2008', '8-Nov-2007', 0.0625, 100.0123, 0,
], ],
[
0.06095433369153867,
'15-Mar-2008', '3-Nov-2008', '8-Nov-2007', 0.0625, 100.0123, null,
],
[ [
0.04210977320221025, 0.04210977320221025,
'1-Jan-2017', '30-Jun-2018', '01-Jul-2014', 0.055, 101, '1-Jan-2017', '30-Jun-2018', '01-Jul-2014', 0.055, 101,

View File

@ -27,6 +27,16 @@ return [
5, 5,
3, 3,
], ],
[
0.00012286639,
[24, 22, 19, 21, 18, 19, 20, 23],
18,
],
[
0.952209647727,
[24, 22, 19, 21, 18, 19, 20, 23],
22,
],
[ [
'#VALUE!', '#VALUE!',
[1, 2, 3, 3, 4, 4, 8, 10, 12], [1, 2, 3, 3, 4, 4, 8, 10, 12],