# Mutual Fund — NAV History

**Controller:** `App\Http\Controllers\MfNavHistoryController`  
**Model:** `App\Models\MfNavHistory`  
**Table:** `mf_nav_history`  
**Middleware:** `jwt.auth`, `check.token`, `dynamic.permission`

Unique per fund: (`fund_id`, `as_of_date`).

---

## Create vs update

**Create** accepts only:

- `fund_id` (required so the row is tied to a fund)
- `as_of_date`
- `nav`
- `composite_nav`
- `buy_price`
- `sell_price`

Calculated from the **previous NAV** of the same fund (`as_of_date` strictly before this row):

| Field | Formula |
|-------|---------|
| `day_change` | `nav - previous.nav` |
| `day_change_percentage` | `(day_change / previous.nav) * 100` |
| `investor_return` | same as `day_change_percentage` |

If there is no previous NAV (first row), those three are `0`.  
`aum_bdt` is `null` on create. `source_type` is set to `CMS`.

**Update** accepts **all** columns so a user can correct a wrong calculated value.

If this row is the latest `as_of_date` for the fund, the fund snapshot is also updated: `current_nav`, `composite_nav`, `current_buy_price`, `current_sell_price`, `latest_nav_date`.

---

## Endpoints

| Action | Method | Path | Route name |
|--------|--------|------|------------|
| List | GET | `/api/mf-nav-history/mf-nav-history-index` | `mf-nav-history-index` |
| Show | GET | `/api/mf-nav-history/mf-nav-history-show/{id}` | `mf-nav-history-show/{id}` |
| Dropdown | GET | `/api/mf-nav-history/mf-nav-history-dropdown` | `mf-nav-history-dropdown` |
| Create | POST | `/api/mf-nav-history/mf-nav-history-store` | `mf-nav-history-store` |
| Update | POST | `/api/mf-nav-history/mf-nav-history-update/{id}` | `mf-nav-history-update/{id}` |
| Delete | DELETE | `/api/mf-nav-history/mf-nav-history-delete/{id}` | `mf-nav-history-delete/{id}` |

Update is **POST**, not PUT.

**Index filters:** `per_page`, `fund_id`, `source_type` (`SCRAPE`/`API`/`CMS`), `from`, `to`.

**Dropdown:** optional `fund_id`. Returns `id`, `fund_id`, `as_of_date`, `nav`, `buy_price`, `sell_price`.

## Related docs

- cURL: `mf_nav_history_api_curl.md`
- Postman: `mf_nav_history.postman_collection.json`
