# Amortize loan

This utility generates an amortization schedule for an installment loan or line of credit draw.
The `atOrigination` field is where you specify various loan or draw-specific inputs such as the
start date, amount to be financed, and duration.
You can specify generic loan type configurations as part of the request body (or omit these
fields and use the default configurations). Alternatively, you can use predefined loan type
configurations by passing in a `loanTypeId`. For a line of credit draw, you can also pass in
a `loanId` in place of a `loanTypeId`. When a `loanId` is provided, the amortization calculation
will reference the configurations of the loan type associated with the `loanId`, and will also
use the line of credit start date and rates associated with the `loanId` if these fields are
not passed in.
When generating an amortization schedule from a predefined loan type, you can pass in either a
`personAddress` or `personAddressId` to check the amortization output against any existing rate
caps associated with the loan type.
Note for the "Predefined Line Of Credit" option only:
- If the loan type is configured to accrue interest as `accrualMethod=compoundWithFees`, there is
a known limitation to the draw amortization calculation logic.
- The draw amortization calculation will be done using the `compound` method and not `compoundWithFees`.
To ensure that the system calculates interest accurately, amortized draws should NOT include any fees.

Endpoint: POST /amortize
Version: 2025-03-26
Security: oauth2, bearerAuth, apiKeyHeader

## Request fields (application/json):

  - `loanTypeId` (string, required)
    The loan type identifier. This is created specifically for each lender's loan product by Peach.

  - `atOrigination` (object, required)

  - `atOrigination.duration` (integer, required)
    The duration of the loan as a number of `paymentFrequency` periods.
For example:
- if `paymentFrequency=monthly` and `duration=6`, it's a loan with 6 months duration and will have 6 due dates.
- if `paymentFrequency=weekly` and `duration=24`, it's a loan with 24 weeks duration and will have 24 due dates.

  - `atOrigination.interestRates` (array, required)
    Interest rates for the loan or the draw. Can be a single interest rate for the entire duration of the loan/draw.
Or, it can be multiple interest rates for partial periods of the loan/draw. If draw-specific rates are not passed,
the draw will use the LOC rates.

  - `atOrigination.interestRates.days` (integer, required)
    Number of calendar days the interest rate applies to. An entry with `days: null` is required
at the end of the list to indicate that the interest rate applies to the end of the loan duration.
For example:
`{"days": 30, "rate": 0.1},`
`{"days": 60, "rate": 0.2},`
`{"days": null, "rate": 0.25}`
The loan will accrue interest of 10% for the first 30 days. Between days 31-90
the loan will accrue interest of 20%. From day 91 until the end, the loan will accrue
interest of 25%.

  - `atOrigination.interestRates.interestType` (string)
    The interest type. The interest type cannot be changed after the loan or draw status changes to `originated` and onward.
`absolute` - interest rates defined as `absolute` will use the value as provided here without adding the Index Interest Rate.
- Negative interest `rate` value is not allowed.
- If the provided `rate` is outside of the range defined on the loan type, the system will accept the `rate` but will return a warning in the response's object `ratesValidation`.

`spread` - interest rates defined as `spread` will calculate an absolute rate by adding the relative loan rate (aka spread)
provided in the `rate` attribute to the Index Interest Rate effective on the date the interest is accrued.
In case the Index Interest Rate is not set, the system will assume that the Index Interest Rate value is zero on the date the interest is accrued.
- Negative interest spread `rate` value is allowed, but the system will default to zero if the addition of the Index Interest Rate still results in a negative rate.
- If the calculated absolute rate, `rate` (aka spread) plus Index Interest Rate, is outside of the range defined on the loan type, the system will accept the `rate` but will return a warning in the response's object `ratesValidation`.
    Enum: "absolute", "spread"

  - `atOrigination.interestRates.rate` (number, required)
    The annual interest rate for the period defined. The format is decimal.
For example, 0.01 is a 1% annual rate, 0.2 is a 20% annual rate.

  - `atOrigination.promoRates` (array)
    The promotional interest rates (aka rate discounts) for the loan or the draw.
Can be a single promo rate for the entire duration of the loan/draw.
Or, it can be multiple promo rates for partial periods of the loan/draw.
For example, if the `interestRate` is 20% for the first 90 days and the `promoRate` has value
5% for 30 days, then the effective rate for the first 30 days is 15%.
The promo rates are unconditional and will be applied regardless of the loan status.

  - `atOrigination.promoRates.days` (integer)
    Number of calendar days the promo rate applies to. Use `null` to indicate that
the promo rate applies to the end of the loan duration.
For example:
`{"days": 30 ,"rate": 0.1},`
`{"days": null, "rate": 0.01}`
The loan will receive interest discount of 10% for the first 30 days.
From day 31 until the end, the loan will receive interest discount of 1%.

  - `atOrigination.promoRates.rate` (number)
    The annual promo rate for the period defined. Loans cannot accrue negative interest rate.
If the promo rate is greater than the interest rate, a loan will accrue 0% interest rate.
The format is decimal. For example, 0.01 is a 1% annual rate, 0.15 is a 15% annual rate.

  - `atOrigination.totalInterestCapAmount` (number)
    The maximum amount of interest the borrower will ever pay. If not applicable, set to `null`.

  - `loanId` (string)
    An identifier of a loan for which to track interactions

  - `amortizationMethod` (string)
    Loan amortization method.
`equalPayments` - the system will amortize the loan or draw making recurring payments equal (except maybe for the last payment).
Most installment loans are expected to use this method.
`interestPaymentsBalloonPrincipal` - the system will amortize the loan or draw making recurring payments equal to interest only
and the last payment will include the entire principal. Keep in mind that if you set `interest.periodAccrualDurationType=actual`,
the recurring payment amounts will be different every period for monthly and twice monthly frequencies. This is because a month
can have 28, 29, 30 or 31 days and interest accrued will vary based on the number of days in the month.
There are additional limitations to be aware for `interestPaymentsBalloonPrincipal`. For installment loans, Autopay can only be
aligned to due dates. It means that `autoPay.allowedFrequency.isDueDatesAvailable` must be set to `false`. This way the system
will only allow Autopay to be aligned to the loan frequency and due dates.
    Enum: "equalPayments", "interestPaymentsBalloonPrincipal", "custom"

  - `assetType` (string)
    The generic asset types that are supported.
    Enum: "personalClosedEndUnsecured", "personalOpenEndUnsecured", "personalClosedEndSecured", "personalOpenEndSecured", "motorMVRISC", "motorDirect", "motorLease", "businessClosedEndUnsecured", "businessOpenEndUnsecured", "businessClosedEndSecured", "businessOpenEndSecured"

  - `maxAPR` (number)
    Indicates whether the loan has a maximum APR

  - `periodAccrualDurationType` (string)
    `fixed` - each period is assumed to be fixed number of calendar days.
For `monthly` frequency we assume 30 days between any two consecutive due dates.
For `twiceMonthly` frequency we assume 15 days between any two consecutive due dates.
For `overyTwoWeeks` frequency we assume 14 days between any two consecutive due dates.
For `weekly` frequency we assume 7 days between any two consecutive due dates.
`actual` - we calculate actual number of days in a period. For example, for `monthly` frequency
number days in a period can be 28, 29, 30 or 31.
For line of credit we only support `actual`.
    Enum: "fixed", "actual"

  - `periodType` (string)
    Enum: "periodBegin", "periodEnd"

  - `singleTermUnitPeriod` (string)
    Enum: "days", "months", "sixMonths", "years"

  - `drawFeeChargeLogic` (string)
    Indicates how to allow the fee.
`onTopPeriodicPayment` - the fee will be added on top of the upcoming amortized payment. It means that the upcoming
payment will be higher than others.
For example: first payment amount is $50 periodic payment plus $10 origination fee, total of $60. Second and onward payments' amount is $50.
`blendWithPeriodicPayment` - the fee will part of the upcoming periodic payment. It means that all expected payments
will be equal (except for the last one.)
For example: first payment amount is $50, $10 of which is the origination fee and $40 is amortized payment. Second and onward payments' amount is $50.
`chargedAtOrigination` - the fee was charged at time of the origination. The fee will not be allocated to future amortized payments.
    Enum: "onTopPeriodicPayment", "blendWithPeriodicPayment", "chargedAtOrigination"

  - `statementCloseToDueDatePeriod` (integer)
    Number of calendar days between statement close date and a due date.
Typically, 14 or 21 days. Applicable for line of credit only.

## Response 200 fields (application/json):

  - `message` (string)
    Description of the server action or error.

  - `status` (integer)
    HTTP status code.

  - `data` (object)

  - `data.aprEffective` (number)
    The calculated effective APR for the loan.

  - `data.aprEffectiveExceedsMax` (boolean)
    The effective APR exceeds the maximum APR.

  - `data.aprNominal` (number)
    The calculated nominal APR for the loan.

  - `data.aprNominalExceedsMax` (boolean)
    The nominal APR exceeds the maximum APR.

  - `data.forgoneInterestAmount` (number)
    Forgone interest amount due to the specified `interestCapAmount`.

