# Currency-Converted Index

`D03-F04-A06` · Index and Benchmark Engineering → Return Variants · archetype `record-transform` · difficulty 3/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/index-and-benchmark-engineering/return-variants/currency-converted-index/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { calculate } from "fintech-algorithms/index-and-benchmark-engineering/return-variants/currency-converted-index";
```

## Signature

```ts
calculate(data)
```

Restates an index in another currency by compounding local returns with FX returns. Unhedged: the holder takes the currency exposure, and this is the variant that shows it.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `data` | `{ localReturns: number[]; fxReturns: number[]; baseLevel: number; quote: string }` | yes | `quote` names the direction of the FX quotation. Getting that direction backwards inverts the currency effect, and the result still looks plausible. `baseLevel` is the index value at the start of the series; it scales the level but never the returns. |

## Returns

`{ baseCurrencyReturns, levels, endingLevel, quote }`

Converted returns and levels, with the quote convention echoed back for checking.

## Errors

- When the return series differ in length — throws

## Complexity

Time `O(n)`, space `O(n)`.

## Worked example

This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

### Input

`data`:

```json
{
  "localReturns": [0.01, -0.004, 0.006, 0.002, -0.003],
  "fxReturns": [0.002, 0.001, -0.003, 0.004, -0.001],
  "baseLevel": 1000,
  "quote": "base currency per local currency"
}
```

### Call

```ts
calculate(data)
```

### Returns

object with 4 fields: baseCurrencyReturns, levels, endingLevel, quote

```json
{
  "baseCurrencyReturns": [0.01202, -0.003004, 0.002982, 0.006008, -0.003997],
  "levels": [1000, 1012.02, 1008.979892, 1011.98867, 1018.068698, 1013.999477],
  "endingLevel": 1013.999477,
  "quote": "base currency per local currency"
}
```

## Verification and provenance

Tier: **verified** (via input-expected).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/index-and-benchmark-engineering/return-variants/currency-converted-index/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/index-and-benchmark-engineering/return-variants/currency-converted-index/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/index-and-benchmark-engineering/llms.txt
