2828from typing import Any , Literal
2929
3030import numpy as np
31- from numpy .typing import NDArray
3231
3332__all__ = [
3433 "FORECASTEX_EXCHANGE_FEE" ,
8483# === Shared helpers ===
8584
8685
87- def _floats (name : str , value : ArrayInput ) -> NDArray [ np .float64 ] :
86+ def _floats (name : str , value : ArrayInput ) -> np .ndarray :
8887 array = np .asarray (value , dtype = np .float64 )
8988 if not np .all (np .isfinite (array )):
9089 raise ValueError (f"{ name } must be finite" )
9190 return array
9291
9392
94- def _prices (value : ArrayInput ) -> NDArray [ np .float64 ] :
93+ def _prices (value : ArrayInput ) -> np .ndarray :
9594 price = _floats ("price" , value )
9695 if np .any ((price < 0.0 ) | (price > 1.0 )):
9796 raise ValueError ("price must be in [0, 1] dollars per contract" )
9897 return price
9998
10099
101- def _contracts (value : ArrayInput ) -> NDArray [ np .float64 ] :
100+ def _contracts (value : ArrayInput ) -> np .ndarray :
102101 contracts = _floats ("contracts" , value )
103102 if np .any (contracts < 0.0 ):
104103 raise ValueError ("contracts must be non-negative; pass the direction as side" )
105104 return contracts
106105
107106
108- def _labels (name : str , value : ArrayInput , allowed : tuple [str , ...]) -> NDArray [ np .str_ ] :
107+ def _labels (name : str , value : ArrayInput , allowed : tuple [str , ...]) -> np .ndarray :
109108 labels = np .asarray (value , dtype = np .str_ )
110109 unknown = sorted (set (np .unique (labels ).tolist ()) - set (allowed ))
111110 if unknown :
112111 raise ValueError (f"{ name } must be one of { allowed } , got { unknown } " )
113112 return labels
114113
115114
116- def _snap (units : NDArray [ np .float64 ] ) -> NDArray [ np .float64 ] :
115+ def _snap (units : np .ndarray ) -> np .ndarray :
117116 """Remove floating-point noise from values that are integers in exact arithmetic.
118117
119118 ``0.07 * 100 * 0.25 * 1e6`` evaluates to ``1750000.0000000002``; ceiling it
@@ -140,7 +139,7 @@ def _kalshi_components(
140139 fee_type : ArrayInput ,
141140 fee_multiplier : ArrayInput ,
142141 rounding : str ,
143- ) -> tuple [NDArray [ np .float64 ], NDArray [ np .float64 ] , float ]:
142+ ) -> tuple [np .ndarray , np .ndarray , float ]:
144143 """Return trade fee and rounding fee per fill in micro-dollars, and the precision."""
145144 p = _prices (price )
146145 c = _contracts (contracts )
@@ -186,7 +185,7 @@ def kalshi_fee(
186185 fee_type : ArrayInput = "quadratic" ,
187186 fee_multiplier : ArrayInput = 1.0 ,
188187 rounding : KalshiRounding = "exact" ,
189- ) -> NDArray [ np .float64 ] :
188+ ) -> np .ndarray :
190189 """Kalshi trading fee per fill, with each fill treated as its own order.
191190
192191 Taker fee: ``round_up(M * 0.07 * C * P * (1 - P))`` with ``C`` contracts at
@@ -246,7 +245,7 @@ def kalshi_order_fees(
246245 fee_type : ArrayInput = "quadratic" ,
247246 fee_multiplier : ArrayInput = 1.0 ,
248247 rounding : KalshiRounding = "cent" ,
249- ) -> NDArray [ np .float64 ] :
248+ ) -> np .ndarray :
250249 """Net Kalshi fee per fill for the fills of one order, in execution order.
251250
252251 Each fill pays its trade fee plus a rounding fee that aligns the balance to
@@ -355,7 +354,7 @@ def forecastex_fee(
355354 * ,
356355 exchange_fee : ArrayInput = FORECASTEX_EXCHANGE_FEE ,
357356 broker_commission : ArrayInput = 0.0 ,
358- ) -> NDArray [ np .float64 ] :
357+ ) -> np .ndarray :
359358 """ForecastEx fee per fill: a flat amount per contract per side.
360359
361360 ForecastEx charges 0.01 per contract per side at execution, "independent of
@@ -436,7 +435,7 @@ def polymarket_us_fee(
436435 fee_coefficient : ArrayInput = POLYMARKET_US_TAKER_COEFFICIENT ,
437436 maker_rebate_coefficient : ArrayInput = POLYMARKET_US_MAKER_REBATE_COEFFICIENT ,
438437 rounding : PolymarketUSRounding = "exact" ,
439- ) -> NDArray [ np .float64 ] :
438+ ) -> np .ndarray :
440439 """Polymarket US fee per fill; a maker rebate is a negative fee.
441440
442441 Taker: ``theta * C * p * (1 - p)`` with ``theta = 0.0695`` (1,000 contracts
0 commit comments