DeltaCalc.Fees (DeltaCalc v0.3.0)

Copy Markdown View Source

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

FunctionArityDescriptionParam Kinds
funding_adjusted_breakeven3Compute breakeven price after roundtrip fees and accrued funding.entry_price: value, params: value, accrued_funding: value
roundtrip_cost1Return total open+close fee cost for a position.params: value
effective_exit2Adjust a fill price for exit fees and optional slippage.fill_price: value, params: value
effective_entry2Adjust a fill price for entry fees and optional slippage.fill_price: value, params: value

Summary

Types

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

Fee and slippage inputs for effective fill prices.

Inputs for roundtrip fee cost.

Side for entry/exit price adjustments and breakeven.

Functions

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

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

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

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

Types

breakeven_params()

@type breakeven_params() :: %{
  :size => decimal_input(),
  :open_fee_rate => decimal_input(),
  :close_fee_rate => decimal_input(),
  optional(:exit_price) => decimal_input(),
  optional(:side) => side()
}

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

decimal_input()

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

fill_params()

@type fill_params() :: %{
  :fee_rate => decimal_input(),
  optional(:slippage_bps) => decimal_input(),
  optional(:side) => side()
}

Fee and slippage inputs for effective fill prices.

roundtrip_params()

@type roundtrip_params() :: %{
  optional(:notional) => decimal_input(),
  optional(:entry_price) => decimal_input(),
  optional(:size) => decimal_input(),
  optional(:exit_price) => decimal_input(),
  open_fee_rate: decimal_input(),
  close_fee_rate: decimal_input()
}

Inputs for roundtrip fee cost.

side()

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

Side for entry/exit price adjustments and breakeven.

Functions

effective_entry(fill_price, params)

@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(fill_price, params)

@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(entry_price, params, accrued_funding)

@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(params)

@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).