# `DeltaCalc.Fees`
[🔗](https://github.com/ZenHive/delta_calc/blob/v0.3.0/lib/delta_calc/fees.ex#L1)

Pure fee and slippage math for effective fill prices, roundtrip costs, and
funding-adjusted breakeven levels.

Fee and slippage rates are caller-supplied — no exchange clients or I/O.

## API Functions
| Function | Arity | Description | Param Kinds |
| --- | --- | --- | --- |
| `funding_adjusted_breakeven` | 3 | Compute breakeven price after roundtrip fees and accrued funding. | `entry_price: value`, `params: value`, `accrued_funding: value` |
| `roundtrip_cost` | 1 | Return total open+close fee cost for a position. | `params: value` |
| `effective_exit` | 2 | Adjust a fill price for exit fees and optional slippage. | `fill_price: value`, `params: value` |
| `effective_entry` | 2 | Adjust a fill price for entry fees and optional slippage. | `fill_price: value`, `params: value` |

# `breakeven_params`

```elixir
@type breakeven_params() :: %{
  :size =&gt; decimal_input(),
  :open_fee_rate =&gt; decimal_input(),
  :close_fee_rate =&gt; decimal_input(),
  optional(:exit_price) =&gt; decimal_input(),
  optional(:side) =&gt; side()
}
```

Inputs for funding-adjusted breakeven (extends roundtrip with size and side).

# `decimal_input`

```elixir
@type decimal_input() :: DeltaCalc.Decimal.input()
```

# `fill_params`

```elixir
@type fill_params() :: %{
  :fee_rate =&gt; decimal_input(),
  optional(:slippage_bps) =&gt; decimal_input(),
  optional(:side) =&gt; side()
}
```

Fee and slippage inputs for effective fill prices.

# `roundtrip_params`

```elixir
@type roundtrip_params() :: %{
  optional(:notional) =&gt; decimal_input(),
  optional(:entry_price) =&gt; decimal_input(),
  optional(:size) =&gt; decimal_input(),
  optional(:exit_price) =&gt; decimal_input(),
  open_fee_rate: decimal_input(),
  close_fee_rate: decimal_input()
}
```

Inputs for roundtrip fee cost.

# `side`

```elixir
@type side() :: :long | :short
```

Side for entry/exit price adjustments and breakeven.

# `effective_entry`

```elixir
@spec effective_entry(decimal_input(), fill_params()) :: Decimal.t()
```

Return the effective entry price after folding in fee rate and slippage.

Long entries (buys) increase; short entries (sells) decrease.

# `effective_exit`

```elixir
@spec effective_exit(decimal_input(), fill_params()) :: Decimal.t()
```

Return the effective exit price after folding in fee rate and slippage.

Long exits (sells) decrease; short exits (buys) increase.

# `funding_adjusted_breakeven`

```elixir
@spec funding_adjusted_breakeven(
  decimal_input(),
  breakeven_params(),
  decimal_input()
) :: Decimal.t()
```

Return the breakeven price accounting for open/close fee rates and accrued funding.

Uses the exact two-leg fee model: close fees apply to the breakeven exit notional.
Returns `entry_price` unchanged when `size` is zero.

# `roundtrip_cost`

```elixir
@spec roundtrip_cost(roundtrip_params()) :: Decimal.t()
```

Return the total fee cost to open and close a position.

Pass `:notional` directly, or `:entry_price` and `:size` (with optional
`:exit_price` for the close leg; defaults to entry price).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
