Skip to content

Commit

Permalink
feat: Display trade strike price
Browse files Browse the repository at this point in the history
  • Loading branch information
namuan committed Dec 23, 2024
1 parent 5175bac commit d5f5876
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions options-trade-plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TradeVisualizationData:
Dict[str, float]
] # Dict containing all Greeks and IV for long positions
trade_date: date
trade_strike: float
front_leg_expiry: date
back_leg_expiry: date

Expand All @@ -62,6 +63,7 @@ def __str__(self) -> str:
f"Short Greeks: {self.short_greeks}\n"
f"Long Greeks: {self.long_greeks}\n"
f"Trade Date: {self.trade_date}\n"
f"Trade Strike: {self.trade_strike}\n"
f"Front Option Expiration: {self.front_leg_expiry}\n"
f"Back Option Expiration: {self.back_leg_expiry}"
)
Expand Down Expand Up @@ -196,6 +198,7 @@ def process_trade_data(trade: Trade) -> TradeVisualizationData:
short_greeks=short_greeks,
long_greeks=long_greeks,
trade_date=trade.trade_date,
trade_strike=trade.legs[0].strike_price,
front_leg_expiry=front_leg_expiry,
back_leg_expiry=back_leg_expiry,
)
Expand Down Expand Up @@ -358,6 +361,9 @@ def create_visualization(self, trade_id: int, db: OptionsDatabase) -> go.Figure:
trade = db.load_trade_with_multiple_legs(trade_id)
data = TradeDataProcessor.process_trade_data(trade)

front_dte = self.calculate_days_between(data.front_leg_expiry, data.trade_date)
back_dte = self.calculate_days_between(data.back_leg_expiry, data.trade_date)

# Create figure with subplot grid: 3 rows in first column, 5 rows in second column
fig = make_subplots(
rows=5,
Expand Down Expand Up @@ -462,7 +468,7 @@ def create_visualization(self, trade_id: int, db: OptionsDatabase) -> go.Figure:
go.Scatter(
x=data.dates,
y=values,
name=f"{position_type.capitalize()} {greek.upper()}",
name=f"{position_type.capitalize()} Put",
line=dict(color=color, width=self.config.line_width),
mode="lines+markers",
marker=dict(size=self.config.marker_size),
Expand All @@ -482,12 +488,10 @@ def create_visualization(self, trade_id: int, db: OptionsDatabase) -> go.Figure:
)

# Update layout
front_dte = self.calculate_days_between(data.front_leg_expiry, data.trade_date)
back_dte = self.calculate_days_between(data.back_leg_expiry, data.trade_date)
fig.update_layout(
height=self.config.figure_height,
title=dict(
text=f"<b>Trade Date:</b> {data.trade_date} <b>Front Expiry:</b> {data.front_leg_expiry} ({front_dte}) <b>Back Expiry:</b> {data.back_leg_expiry} ({back_dte})",
text=f"<b>Trade Date:</b> {data.trade_date} <b>Strike</b> {data.trade_strike} <b>Front Expiry:</b> {data.front_leg_expiry} ({front_dte}) <b>Back Expiry:</b> {data.back_leg_expiry} ({back_dte})",
font=dict(family=self.FONT, size=16, color="#2C3E50"),
x=0.5,
),
Expand Down

0 comments on commit d5f5876

Please sign in to comment.