jofaichow commited on
Commit
bc823ad
1 Parent(s): ac8d9e3

0.1.6 - added apcwnm and mcwnm

Browse files
Files changed (1) hide show
  1. app/app.R +104 -17
app/app.R CHANGED
@@ -50,11 +50,11 @@ reformat_data <- function(d_raw) {
50
  col_keep <- c("model", "roundNumber",
51
  "roundOpenTime", "roundResolveTime",
52
  "roundResolved", "selectedStakeValue",
53
- # "corr", "corrPercentile",
54
  "corr20V2", "corr20V2Percentile",
55
  "fncV3", "fncV3Percentile",
56
  "tc", "tcPercentile",
57
  "corrWMetamodel",
 
58
  "roundPayoutFactor", "payout")
59
  d_munged <- d_raw[, col_keep, with = FALSE]
60
 
@@ -75,6 +75,7 @@ reformat_data <- function(d_raw) {
75
  "fncV3", "fncV3_pct",
76
  "tc", "tc_pct",
77
  "corr_meta",
 
78
  "pay_ftr", "payout")
79
 
80
  # Return
@@ -302,7 +303,7 @@ ui <- shinydashboardPlus::dashboardPage(
302
  tabsetPanel(type = "tabs",
303
 
304
 
305
- tabPanel("Net Round Payouts",
306
 
307
  br(),
308
 
@@ -338,8 +339,19 @@ ui <- shinydashboardPlus::dashboardPage(
338
  DTOutput("dt_payout_summary"),
339
 
340
  br()
341
-
342
- ),
 
 
 
 
 
 
 
 
 
 
 
343
 
344
 
345
  tabPanel("Chart (Stacked Payouts)",
@@ -353,9 +365,6 @@ ui <- shinydashboardPlus::dashboardPage(
353
  shinycssloaders::withSpinner(plotlyOutput("plot_payout_stacked")),
354
 
355
  br()
356
- # br(),
357
-
358
- # DTOutput("dt_payout_summary")
359
 
360
  ),
361
 
@@ -461,6 +470,7 @@ ui <- shinydashboardPlus::dashboardPage(
461
  - #### **0.1.3** — Added `Raw Data`
462
  - #### **0.1.4** — Improved and sped up `Payout Summary`
463
  - #### **0.1.5** — Replaced `corrV1` with `corrV2`
 
464
  "),
465
 
466
  br(),
@@ -479,7 +489,7 @@ ui <- shinydashboardPlus::dashboardPage(
479
 
480
  footer = shinydashboardPlus::dashboardFooter(
481
  left = "Powered by ❤️, ☕, Shiny, and 🤗 Spaces",
482
- right = paste0("Version 0.1.5"))
483
 
484
  )
485
 
@@ -567,13 +577,14 @@ server <- function(input, output) {
567
  dom = 'Bflrtip', # https://datatables.net/reference/option/dom
568
  buttons = list('csv', 'excel', 'copy', 'print'), # https://rstudio.github.io/DT/003-tabletools-buttons.html
569
  order = list(list(0, 'asc'), list(1, 'asc')),
570
- pageLength = 5,
571
- lengthMenu = c(5, 10, 20, 100, 500, 1000, 50000),
572
  columnDefs = list(list(className = 'dt-center', targets = "_all")))
573
  ) |>
574
 
575
  # Reformat individual columns
576
  formatRound(columns = c("corrV2", "tc", "fncV3", "corr_meta", "pay_ftr"), digits = 4) |>
 
577
  formatRound(columns = c("corrV2_pct", "tc_pct", "fncV3_pct"), digits = 1) |>
578
  formatRound(columns = c("stake", "payout"), digits = 2) |>
579
 
@@ -646,6 +657,32 @@ server <- function(input, output) {
646
  })
647
 
648
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
649
  # ============================================================================
650
  # Reactive: Payout Value Boxes
651
  # ============================================================================
@@ -689,7 +726,7 @@ server <- function(input, output) {
689
  subtitle = "Staked Rounds (All)",
690
  color = "light-blue")
691
  })
692
-
693
 
694
  # ============================================================================
695
  # Reactive valueBox outputs: Payouts
@@ -700,7 +737,7 @@ server <- function(input, output) {
700
  subtitle = "Total Payout (Resolved)",
701
  color = "olive")
702
  })
703
-
704
  output$payout_pending <- renderValueBox({
705
  valueBox(value = as.character(format(round(sum(react_d_filter()[resolved == F, ]$payout, na.rm = T), 2), nsmall = 2)),
706
  subtitle = "Total Payout (Pending)",
@@ -717,7 +754,7 @@ server <- function(input, output) {
717
  # ============================================================================
718
  # Reactive valueBox outputs: Average Round Payouts
719
  # ============================================================================
720
-
721
  output$payout_average_resolved <- renderValueBox({
722
  # Use rounds with stake > 0 only
723
  valueBox(value = as.character(format(round(mean(react_d_payout_summary()[resolved == T & total_stake > 0, ]$net_payout, na.rm = T), 2), nsmall = 2)),
@@ -763,7 +800,7 @@ server <- function(input, output) {
763
  subtitle = "Avg. Round ROR (All)",
764
  color = "light-blue")
765
  })
766
-
767
 
768
  # ============================================================================
769
  # Reactive: Payout Charts
@@ -782,7 +819,7 @@ server <- function(input, output) {
782
  # Divider (resolved vs pending)
783
  x_marker <- max(d_filter[resolved == TRUE]$round) + 0.5
784
  y_marker <- max(d_filter$net_payout)
785
-
786
  # ggplot
787
  p <- ggplot(d_filter,
788
  aes(x = round, y = net_payout, fill = net_payout,
@@ -811,7 +848,7 @@ server <- function(input, output) {
811
  geom_hline(aes(yintercept = 0), linewidth = 0.25, color = "grey") +
812
 
813
  annotate("text", x = x_marker, y = y_marker*1.2, label = "← Resolved vs. Pending →") +
814
-
815
  scale_fill_scico(palette = "vikO", direction = -1, midpoint = 0) +
816
  # scale_x_date(breaks = breaks_pretty(10),
817
  # labels = label_date_short(format = c("%Y", "%b", "%d"), sep = "\n")
@@ -951,6 +988,7 @@ server <- function(input, output) {
951
  # Reactive: Payout Summary Table
952
  # ============================================================================
953
 
 
954
  output$dt_payout_summary <- DT::renderDT({
955
 
956
  # Generate a new DT
@@ -999,6 +1037,55 @@ server <- function(input, output) {
999
  })
1000
 
1001
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1002
  # ============================================================================
1003
  # Reactive: Model Performance Charts
1004
  # ============================================================================
@@ -1050,7 +1137,7 @@ server <- function(input, output) {
1050
 
1051
  # Generate plotly
1052
  ggplotly(p, height = height)
1053
-
1054
  })
1055
 
1056
 
 
50
  col_keep <- c("model", "roundNumber",
51
  "roundOpenTime", "roundResolveTime",
52
  "roundResolved", "selectedStakeValue",
 
53
  "corr20V2", "corr20V2Percentile",
54
  "fncV3", "fncV3Percentile",
55
  "tc", "tcPercentile",
56
  "corrWMetamodel",
57
+ "apcwnm", "mcwnm",
58
  "roundPayoutFactor", "payout")
59
  d_munged <- d_raw[, col_keep, with = FALSE]
60
 
 
75
  "fncV3", "fncV3_pct",
76
  "tc", "tc_pct",
77
  "corr_meta",
78
+ "apcwnm", "mcwnm",
79
  "pay_ftr", "payout")
80
 
81
  # Return
 
303
  tabsetPanel(type = "tabs",
304
 
305
 
306
+ tabPanel("Overview (All)",
307
 
308
  br(),
309
 
 
339
  DTOutput("dt_payout_summary"),
340
 
341
  br()
342
+
343
+ ),
344
+
345
+
346
+ tabPanel("Overview (Individual)",
347
+
348
+ br(),
349
+
350
+ DTOutput("dt_model_payout_summary"),
351
+
352
+ br()
353
+
354
+ ),
355
 
356
 
357
  tabPanel("Chart (Stacked Payouts)",
 
365
  shinycssloaders::withSpinner(plotlyOutput("plot_payout_stacked")),
366
 
367
  br()
 
 
 
368
 
369
  ),
370
 
 
470
  - #### **0.1.3** — Added `Raw Data`
471
  - #### **0.1.4** — Improved and sped up `Payout Summary`
472
  - #### **0.1.5** — Replaced `corrV1` with `corrV2`
473
+ - #### **0.1.6** — Added `apcwnm` and `mcwnm`
474
  "),
475
 
476
  br(),
 
489
 
490
  footer = shinydashboardPlus::dashboardFooter(
491
  left = "Powered by ❤️, ☕, Shiny, and 🤗 Spaces",
492
+ right = paste0("Version 0.1.6"))
493
 
494
  )
495
 
 
577
  dom = 'Bflrtip', # https://datatables.net/reference/option/dom
578
  buttons = list('csv', 'excel', 'copy', 'print'), # https://rstudio.github.io/DT/003-tabletools-buttons.html
579
  order = list(list(0, 'asc'), list(1, 'asc')),
580
+ pageLength = 10,
581
+ lengthMenu = c(10, 20, 100, 500, 1000, 50000),
582
  columnDefs = list(list(className = 'dt-center', targets = "_all")))
583
  ) |>
584
 
585
  # Reformat individual columns
586
  formatRound(columns = c("corrV2", "tc", "fncV3", "corr_meta", "pay_ftr"), digits = 4) |>
587
+ formatRound(columns = c("apcwnm", "mcwnm"), digits = 4) |>
588
  formatRound(columns = c("corrV2_pct", "tc_pct", "fncV3_pct"), digits = 1) |>
589
  formatRound(columns = c("stake", "payout"), digits = 2) |>
590
 
 
657
  })
658
 
659
 
660
+ react_d_model_payout_summary <- eventReactive(
661
+ input$button_filter,
662
+ {
663
+
664
+ # Summarise payout
665
+ d_smry <-
666
+ react_d_filter() |>
667
+ lazy_dt() |>
668
+ filter(stake > 0) |>
669
+ group_by(model) |>
670
+ summarise(staked_rounds = n(),
671
+ net_payout = sum(payout, na.rm = T),
672
+ avg_payout = mean(payout, na.rm = T),
673
+ sharpe = mean(payout, na.rm = T) / sd(payout, na.rm = T)
674
+ ) |>
675
+ as.data.table()
676
+
677
+ # Return
678
+ d_smry
679
+
680
+ })
681
+
682
+
683
+
684
+
685
+
686
  # ============================================================================
687
  # Reactive: Payout Value Boxes
688
  # ============================================================================
 
726
  subtitle = "Staked Rounds (All)",
727
  color = "light-blue")
728
  })
729
+
730
 
731
  # ============================================================================
732
  # Reactive valueBox outputs: Payouts
 
737
  subtitle = "Total Payout (Resolved)",
738
  color = "olive")
739
  })
740
+
741
  output$payout_pending <- renderValueBox({
742
  valueBox(value = as.character(format(round(sum(react_d_filter()[resolved == F, ]$payout, na.rm = T), 2), nsmall = 2)),
743
  subtitle = "Total Payout (Pending)",
 
754
  # ============================================================================
755
  # Reactive valueBox outputs: Average Round Payouts
756
  # ============================================================================
757
+
758
  output$payout_average_resolved <- renderValueBox({
759
  # Use rounds with stake > 0 only
760
  valueBox(value = as.character(format(round(mean(react_d_payout_summary()[resolved == T & total_stake > 0, ]$net_payout, na.rm = T), 2), nsmall = 2)),
 
800
  subtitle = "Avg. Round ROR (All)",
801
  color = "light-blue")
802
  })
803
+
804
 
805
  # ============================================================================
806
  # Reactive: Payout Charts
 
819
  # Divider (resolved vs pending)
820
  x_marker <- max(d_filter[resolved == TRUE]$round) + 0.5
821
  y_marker <- max(d_filter$net_payout)
822
+
823
  # ggplot
824
  p <- ggplot(d_filter,
825
  aes(x = round, y = net_payout, fill = net_payout,
 
848
  geom_hline(aes(yintercept = 0), linewidth = 0.25, color = "grey") +
849
 
850
  annotate("text", x = x_marker, y = y_marker*1.2, label = "← Resolved vs. Pending →") +
851
+
852
  scale_fill_scico(palette = "vikO", direction = -1, midpoint = 0) +
853
  # scale_x_date(breaks = breaks_pretty(10),
854
  # labels = label_date_short(format = c("%Y", "%b", "%d"), sep = "\n")
 
988
  # Reactive: Payout Summary Table
989
  # ============================================================================
990
 
991
+ # Net Round Payout Summary
992
  output$dt_payout_summary <- DT::renderDT({
993
 
994
  # Generate a new DT
 
1037
  })
1038
 
1039
 
1040
+ # Individual Model Payout Summary
1041
+ output$dt_model_payout_summary <- DT::renderDT({
1042
+
1043
+ # Generate a new DT
1044
+ DT::datatable(
1045
+
1046
+ # Data
1047
+ react_d_model_payout_summary(),
1048
+
1049
+ # Other Options
1050
+ rownames = FALSE,
1051
+ extensions = "Buttons",
1052
+ options =
1053
+ list(
1054
+ dom = 'Bflrtip', # https://datatables.net/reference/option/dom
1055
+ buttons = list('csv', 'excel', 'copy', 'print'), # https://rstudio.github.io/DT/003-tabletools-buttons.html
1056
+ order = list(list(0, 'asc'), list(1, 'asc')),
1057
+ pageLength = 500,
1058
+ lengthMenu = c(10, 50, 100, 500, 1000),
1059
+ columnDefs = list(list(className = 'dt-center', targets = "_all")))
1060
+ ) |>
1061
+
1062
+ # Reformat individual columns
1063
+ formatRound(columns = c("net_payout", "avg_payout", "sharpe"), digits = 4) |>
1064
+
1065
+ # formatStyle(columns = c("model"), fontWeight = "bold") |>
1066
+
1067
+ formatStyle(columns = c("net_payout"),
1068
+ # fontWeight = "bold",
1069
+ color = styleInterval(cuts = c(-1e-15, 1e-15),
1070
+ values = c("#D24141", "#D1D1D1", "#00A800"))) |>
1071
+
1072
+ formatStyle(columns = c("avg_payout"),
1073
+ # fontWeight = "bold",
1074
+ color = styleInterval(cuts = c(-1e-15, 1e-15),
1075
+ values = c("#D24141", "#D1D1D1", "#00A800"))) |>
1076
+
1077
+ formatStyle(columns = c("sharpe"),
1078
+ # fontWeight = "bold",
1079
+ color = styleInterval(cuts = c(-1e-15, 1e-15),
1080
+ values = c("#D24141", "#D1D1D1", "#00A800")))
1081
+
1082
+
1083
+
1084
+
1085
+ })
1086
+
1087
+
1088
+
1089
  # ============================================================================
1090
  # Reactive: Model Performance Charts
1091
  # ============================================================================
 
1137
 
1138
  # Generate plotly
1139
  ggplotly(p, height = height)
1140
+
1141
  })
1142
 
1143