Fix dist-to-breakeven as strike-to-equilibrium spread.
Chain and order panel now show expiry_be minus strike instead of index distance. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import ccxt
|
||||
from lib.options.options_pricing_lib import (
|
||||
expiry_breakeven_from_ask,
|
||||
idx_distance_to_be,
|
||||
strike_distance_to_be,
|
||||
is_shallow_itm,
|
||||
option_moneyness,
|
||||
option_moneyness_label,
|
||||
@@ -906,7 +907,7 @@ def build_option_chain(
|
||||
"mark_px": mark,
|
||||
"ask_estimated": q["ask_estimated"],
|
||||
"expiry_be_px": expiry_be,
|
||||
"dist_expiry_be": idx_distance_to_be(idx, expiry_be),
|
||||
"dist_expiry_be": strike_distance_to_be(strike, expiry_be),
|
||||
"moneyness": mny,
|
||||
"moneyness_label": option_moneyness_label(mny),
|
||||
"ct_mult": _safe_float(meta.get("ctMult")) or 0.01,
|
||||
@@ -1059,7 +1060,7 @@ def quote_option_contract(ex: ccxt.okx, inst_id: str) -> dict[str, Any]:
|
||||
"open_block_msg": "" if can_open else open_block_msg,
|
||||
"index_px": idx,
|
||||
"expiry_be_px": expiry_be,
|
||||
"dist_expiry_be": idx_distance_to_be(idx, expiry_be),
|
||||
"dist_expiry_be": strike_distance_to_be(strike, expiry_be),
|
||||
"ct_mult": _safe_float(meta.get("ctMult")) or 0.01,
|
||||
"min_sz": int(_safe_float(meta.get("minSz")) or 1),
|
||||
"tick_sz": tick_sz,
|
||||
@@ -1810,6 +1811,7 @@ def format_position_row(
|
||||
close_breakeven_idx,
|
||||
expiry_breakeven_px,
|
||||
idx_distance_to_be,
|
||||
strike_distance_to_be,
|
||||
total_premium,
|
||||
)
|
||||
|
||||
@@ -1890,7 +1892,7 @@ def format_position_row(
|
||||
"avail_pos": _safe_float(pos.get("availPos")),
|
||||
"expiry_be_px": expiry_be,
|
||||
"close_be_px": close_be,
|
||||
"dist_expiry_be": idx_distance_to_be(idx_px, expiry_be),
|
||||
"dist_expiry_be": strike_distance_to_be(strike, expiry_be),
|
||||
"dist_close_be": idx_distance_to_be(idx_px, close_be),
|
||||
"raw": pos,
|
||||
}
|
||||
|
||||
@@ -519,12 +519,19 @@ def close_breakeven_idx(
|
||||
|
||||
|
||||
def idx_distance_to_be(idx_px: float | None, be_px: float | None) -> float | None:
|
||||
"""指数距平衡点(正=指数需上涨才到平衡点)."""
|
||||
"""指数距平衡点(正=指数需上涨才到平衡点).用于平掉回本等随盘变化场景."""
|
||||
if idx_px is None or be_px is None:
|
||||
return None
|
||||
return round(float(be_px) - float(idx_px), 2)
|
||||
|
||||
|
||||
def strike_distance_to_be(strike: float | None, be_px: float | None) -> float | None:
|
||||
"""行权价与到期平衡的价差(平衡价 - 行权价).链上「距平衡」列用此值."""
|
||||
if strike is None or be_px is None:
|
||||
return None
|
||||
return round(float(be_px) - float(strike), 2)
|
||||
|
||||
|
||||
def format_options_breakeven_line(
|
||||
*,
|
||||
expiry_be_px: float | None,
|
||||
|
||||
Reference in New Issue
Block a user