Skip to content

Commit ed5c916

Browse files
committed
fix annotations
1 parent d154d09 commit ed5c916

File tree

1 file changed

+3
-40
lines changed

1 file changed

+3
-40
lines changed

tabs/post_trade_analysis.py

+3-40
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636

3737
markout_periods = ['t0', 't5', 't10', 't30', 't60']
38+
markout_colors = ['#FF0000', '#00FF00', '#0000FF', '#FFA500', '#800080']
3839

3940

4041
def process_trades_df(raw_trades_df: pd.DataFrame) -> pd.DataFrame:
@@ -373,7 +374,6 @@ def plot_cumulative_pnl_for_user_account(user_trades_df, filter_ua):
373374
)
374375

375376
# Add markout traces to fourth subplot
376-
colors = ['#FF0000', '#00FF00', '#0000FF', '#FFA500', '#800080']
377377
for i, period in enumerate(markout_periods):
378378
# Filter out NaN values before creating histogram
379379
premium_data = user_trades_df[f'userPremium{period}'].dropna()
@@ -386,54 +386,17 @@ def plot_cumulative_pnl_for_user_account(user_trades_df, filter_ua):
386386
y=user_trades_df[f'userPremium{period}Dollar'].cumsum(),
387387
mode='lines+markers',
388388
name=f'Markout {period}',
389-
line=dict(width=1, color=colors[i]),
389+
line=dict(width=1, color=markout_colors[i]),
390390
marker=dict(size=marker_size)),
391391
row=4, col=1
392392
)
393393

394-
# Calculate metrics on filtered data
395-
mean_val = premium_data.mean()
396-
std_val = premium_data.std()
397-
median_val = premium_data.median()
398-
skew_val = premium_data.skew()
399-
400-
# Get histogram data to find max y value
401-
hist, bins = np.histogram(premium_data, bins=100, density=False)
402-
max_y = np.max(hist) if len(hist) > 0 else 0
403-
max_x = np.max(bins) if len(bins) > 0 else 0
404-
405-
# Add metrics as annotations
406-
fig1.add_annotation(
407-
text=f"Mean: {mean_val:.4f}<br>Std: {std_val:.4f}<br>Median: {median_val:.4f}<br>Skew: {skew_val:.4f}",
408-
xref=f"x{i+1}",
409-
yref=f"y{i+1}",
410-
x=max_x,
411-
y=max_y,
412-
showarrow=False,
413-
align="right",
414-
row=4,
415-
col=1
416-
)
417-
else:
418-
# Add empty subplot with message if no valid data
419-
fig1.add_annotation(
420-
text="No valid data",
421-
xref=f"x{i+1}",
422-
yref=f"y{i+1}",
423-
x=0.5,
424-
y=0.5,
425-
showarrow=False,
426-
row=4,
427-
col=1
428-
)
429-
430394
# Second figure for histograms
431395
fig2 = make_subplots(rows=1, cols=len(markout_periods),
432396
subplot_titles=[f'Markout {period}' for period in markout_periods],
433397
horizontal_spacing=0.05
434398
)
435399

436-
colors = ['#FF0000', '#00FF00', '#0000FF', '#FFA500', '#800080']
437400

438401
for i, period in enumerate(markout_periods):
439402
# Filter out NaN values before creating histogram
@@ -447,7 +410,7 @@ def plot_cumulative_pnl_for_user_account(user_trades_df, filter_ua):
447410
x=premium_data, # Use filtered data
448411
name=f'Markout {period}',
449412
nbinsx=100,
450-
marker_color=colors[i],
413+
marker_color=markout_colors[i],
451414
opacity=0.5,
452415
showlegend=False
453416
),

0 commit comments

Comments
 (0)