> For the complete documentation index, see [llms.txt](https://docs.creditcoop.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.creditcoop.xyz/developers/v1-developer-material/functions-and-methods/interestratecredit.sol/accrued-interest-calculation.md).

# Accrued Interest Calculation

Describes how accrued interest is calculated and where and when this happens

### Formulae

<details>

<summary><strong>Interest = (r * x * t) / 1yr / 10000</strong></summary>

r = APR in basis points (e.g. 5% = 500bp)

x = amount of tokens

t = time (in seconds)

1 year = 365.25 days (in seconds)

</details>

<details>

<summary>Full Accrued Interest formula</summary>

`InterestAccrued =`

`(rate.dRate * drawnBalance * timespan) / INTEREST_DENOMINATOR`

`+`

`(rate.fRate * (facilityBalance - drawnBalance) * timespan) / INTEREST_DENOMINATOR`

</details>

### Parameters

<details>

<summary>interestAccrued</summary>

Interest owed by a Borrower but not yet repaid to the Line of Credit contract

</details>

<details>

<summary>Interest denominator = 365.25 days * Base denominator</summary>

</details>

<details>

<summary>Base denominator</summary>

10000 (adjustment factor since rates are expressed in basis points (bps) --> e.g. 5% rate is expressed as 500bp so we need to divide by 100 to get a % and then by another 100 to arrive at the decimal (500/100/100 = 0.05)

</details>

<details>

<summary>One year</summary>

One Julian astronomical year, has 365.25 days: 1 year = 365.25 days = (365.25 days) × (24 hours/day) × (3600 seconds/hour) = 31557600 seconds

</details>

<details>

<summary>dRate</summary>

The annual interest rate charged to a Borrower on borrowed / drawn down funds (in basis points to 4 decimals, e.g. 1000bp = 10% and 1234bp = 12.34% and 1234.56bp = 12.3456%)

</details>

<details>

<summary>drawnBalance</summary>

The balance of funds that a Borrower has drawn down on the Line of Credit

</details>

<details>

<summary>fRate</summary>

The annual interest rate charged to a Borrower on the remaining funds available, but not yet drawn down aka rate charged on the available facility headroom(in basis points to 4 decimals).

</details>

<details>

<summary>facilityBalance</summary>

The remaining balance of funds that a Borrower can still drawn down on the Line of Credit (aka headroom)

</details>

<details>

<summary>timespan= block.timestamp - rate.lastAccrued</summary>

The number of seconds for which interest will be accrued

</details>

<details>

<summary>block.timestamp</summary>

The block timestamp for the block during which interest is calculated, in seconds

</details>

### Contract workflow

Please see [here](/developers/v1-developer-material/functions-and-methods/interestratecredit.sol/interest-accrued-contract-flow.md) for an overview of the contract and function workflow.

The definitions below are useful for that.

<details>

<summary>Principal</summary>

The amount of a Lender's Deposit that has actually been drawn down by the Borrower (USD)

</details>

<details>

<summary>Deposit</summary>

The sum of the total liquidity provided by a Lender in a given token on a Line of Credit

</details>

<details>

<summary>id</summary>

Reference id for the Credit Position made available to a Borrower by a single Lender for a given token on a Line

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.creditcoop.xyz/developers/v1-developer-material/functions-and-methods/interestratecredit.sol/accrued-interest-calculation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
