> ## Documentation index
> Fetch the complete documentation index at: https://docs.simplycpf.com/llms.txt
> Ask it with GET https://docs.simplycpf.com/ask?q=<keywords or question>. Short keywords rank best.
> Use these to discover all available pages before exploring further.

# Calculation

> Calculate CPF contributions and projections

Endpoints for calculating CPF contributions for single income, batch scenarios, and multi-year projections.

## POST /calculate

Calculate CPF contributions for a single income amount.

### Request Body

```typescript
interface CalculateRequest {
  income: number;    // Required - Monthly gross income (non-negative)
  date?: string;     // Optional - Date in YYYY-MM-DD format (defaults to today)
  age?: number;      // Optional - Age for age-group lookup
}
```

### Response

```typescript
interface CalculateResponse {
  contribution: {
    totalContribution: number;
    employer: number;
    employee: number;
  };
  distribution: {
    OA: number;
    SA: number;
    MA: number;
  };
  afterCpfContribution: number;
}
```

### Example

```bash
curl -X POST https://simplycpf.com/api/cpf/calculate \
  -H "Content-Type: application/json" \
  -d '{"income": 5000, "age": 30}'
```

```json
{
  "contribution": {
    "totalContribution": 1850,
    "employer": 850,
    "employee": 1000
  },
  "distribution": {
    "OA": 1150.14,
    "SA": 299.88,
    "MA": 399.97
  },
  "afterCpfContribution": 4000
}
```

---

## POST /calculate/batch

Calculate CPF contributions for multiple income scenarios (up to 100).

### Request Body

```typescript
interface BatchCalculateRequest {
  scenarios: Array<{
    income: number;    // Required - Monthly income
    date?: string;     // Optional - Date in YYYY-MM-DD
    age?: number;      // Optional - Age for age-group lookup
  }>;
}
```

### Constraints

- Maximum 100 scenarios per request
- Array cannot be empty

### Response

Returns an array of `ComputedResult` objects matching input scenarios.

### Example

```bash
curl -X POST https://simplycpf.com/api/cpf/calculate/batch \
  -H "Content-Type: application/json" \
  -d '{"scenarios": [{"income": 4000}, {"income": 6000}, {"income": 8000}]}'
```

---

## POST /projection

Project yearly OA, SA, MA and RA balances with contributions, interest, retirement milestones and simplified CPF LIFE estimates. Every response also includes a `projections` array of yearly contributions with cumulative totals.

The endpoint accepts two request shapes. Use the full request for balance projections with housing, top-up and transfer assumptions. The short request (`income`, `age`, `years`) is kept for backward compatibility.

### Request Body

```typescript
interface ProjectionRequest {
  monthlyIncome: number;        // Required - Monthly gross income (non-negative)
  startAge?: number;            // Starting age; required if birthDate is omitted
  birthDate?: string;           // MM/YYYY; used when startAge is omitted
  endAge?: number;              // Last age to project (defaults to 65)
  citizenship?: "citizen" | "spr-year1" | "spr-year2" | "spr-year3-plus"; // Defaults to "citizen"
  housingWithdrawal?: number;   // Monthly OA housing withdrawal in SGD
  voluntaryTopUp?: {
    amount: number;             // Positive amount in SGD
    account: "SA" | "MA" | "RA";
    frequency: "monthly" | "yearly";
  };
  oaToSaTransfer?: {
    amount: number;             // Positive amount in SGD
    timing: "now" | "yearly";
  };
}

// Short request (backward compatible)
interface ShortProjectionRequest {
  income: number;    // Required - Monthly income (non-negative)
  age: number;       // Required - Starting age
  years: number;     // Required - Number of years to project (1-50)
}
```

### Constraints

- Provide `startAge` or `birthDate`
- `endAge` must be at least `startAge`
- Maximum 50 years per request (inclusive of start and end age)

### Response

```typescript
interface AccountBalances {
  oa: number;
  sa: number;
  ma: number;
  ra: number;
}

interface ProjectionResponse {
  input: Record<string, unknown>;      // The request fields you sent
  projectionInput: ProjectionRequest;  // Normalised input used for the projection
  yearlyBalances: Array<{
    year: number;                      // Calendar year
    age: number;
    ageGroup: string;
    balances: AccountBalances;         // End-of-year balances
    contributions: { employee: number; employer: number; total: number };
    distribution: AccountBalances;     // Contributions credited to each account
    interestEarned: AccountBalances & { extraInterest: number };
    housingWithdrawal?: number;        // Annual OA housing withdrawal
    voluntaryTopUp?: number;           // Annual voluntary top-up
  }>;
  milestones: {
    age55: AccountBalances;
    age65: AccountBalances;
    age70?: AccountBalances;
  };                                   // Zero when the projection ends before that age
  cpfLifeEstimate: {
    standardMonthly: number;
    escalatingStartMonthly: number;
    basicMonthly: number;
    deferredTo70Monthly: number;
  };
  totalContributed: number;
  totalInterestEarned: number;
  projections: Array<{
    year: number;
    age: number;
    ageGroup: string;
    contribution: {
      employee: number;
      employer: number;
      totalContribution: number;
    };
    cumulative: {
      employee: number;
      employer: number;
      totalContribution: number;
    };
  }>;
}
```

### Example

Project from age 30 to 65 with a $500 monthly housing withdrawal and an $8,000 yearly SA top-up:

```bash
curl -X POST https://simplycpf.com/api/cpf/projection \
  -H "Content-Type: application/json" \
  -d '{
    "monthlyIncome": 5000,
    "startAge": 30,
    "endAge": 65,
    "housingWithdrawal": 500,
    "voluntaryTopUp": { "amount": 8000, "account": "SA", "frequency": "yearly" }
  }'
```

The response includes the CPF LIFE estimate at 65:

```json
{
  "cpfLifeEstimate": {
    "standardMonthly": 4975,
    "escalatingStartMonthly": 3980,
    "basicMonthly": 4478,
    "deferredTo70Monthly": 6716
  }
}
```

Short request, returning the same response shape:

```bash
curl -X POST https://simplycpf.com/api/cpf/projection \
  -H "Content-Type: application/json" \
  -d '{"income": 5000, "age": 30, "years": 5}'
```
