35
35
36
36
37
37
markout_periods = ['t0' , 't5' , 't10' , 't30' , 't60' ]
38
+ markout_colors = ['#FF0000' , '#00FF00' , '#0000FF' , '#FFA500' , '#800080' ]
38
39
39
40
40
41
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):
373
374
)
374
375
375
376
# Add markout traces to fourth subplot
376
- colors = ['#FF0000' , '#00FF00' , '#0000FF' , '#FFA500' , '#800080' ]
377
377
for i , period in enumerate (markout_periods ):
378
378
# Filter out NaN values before creating histogram
379
379
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):
386
386
y = user_trades_df [f'userPremium{ period } Dollar' ].cumsum (),
387
387
mode = 'lines+markers' ,
388
388
name = f'Markout { period } ' ,
389
- line = dict (width = 1 , color = colors [i ]),
389
+ line = dict (width = 1 , color = markout_colors [i ]),
390
390
marker = dict (size = marker_size )),
391
391
row = 4 , col = 1
392
392
)
393
393
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
-
430
394
# Second figure for histograms
431
395
fig2 = make_subplots (rows = 1 , cols = len (markout_periods ),
432
396
subplot_titles = [f'Markout { period } ' for period in markout_periods ],
433
397
horizontal_spacing = 0.05
434
398
)
435
399
436
- colors = ['#FF0000' , '#00FF00' , '#0000FF' , '#FFA500' , '#800080' ]
437
400
438
401
for i , period in enumerate (markout_periods ):
439
402
# Filter out NaN values before creating histogram
@@ -447,7 +410,7 @@ def plot_cumulative_pnl_for_user_account(user_trades_df, filter_ua):
447
410
x = premium_data , # Use filtered data
448
411
name = f'Markout { period } ' ,
449
412
nbinsx = 100 ,
450
- marker_color = colors [i ],
413
+ marker_color = markout_colors [i ],
451
414
opacity = 0.5 ,
452
415
showlegend = False
453
416
),
0 commit comments