Last active
August 11, 2019 20:09
-
-
Save Yerazhas/bdc5bcc54898ddb8a0da532964cc4c8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol CapitalStrategy { | |
| func capital(loan: Loan) -> Double | |
| func riskFactor() -> Double | |
| } | |
| extension CapitalStrategy { | |
| func riskFactor() -> Double { | |
| return 0.0 | |
| } | |
| } | |
| class RevolverCapitalStrategy: CapitalStrategy { | |
| func capital(loan: Loan) -> Double { | |
| return 250 * riskFactor() | |
| } | |
| } | |
| class TermLoanCapitalStrategy: CapitalStrategy { | |
| func capital(loan: Loan) -> Double { | |
| if loan.expiryDate != nil && loan.maturityDate != nil { | |
| return 10.0 * loan.duration() * riskFactor() | |
| } | |
| if loan.expiryDate != nil && loan.maturityDate == nil { | |
| if loan.getUnusedPercentage() > 1.0 { | |
| return 150.0 * loan.getUnusedPercentage() | |
| } else { | |
| return 200.0 * loan.getUnusedPercentage() | |
| } | |
| } | |
| return 0.0 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment