jofaichow commited on
Commit
4115d51
1 Parent(s): 7d44ee0

Added KPI chart

Browse files
Files changed (1) hide show
  1. app/app.R +125 -18
app/app.R CHANGED
@@ -320,7 +320,7 @@ ui <- shinydashboardPlus::dashboardPage(
320
  tabsetPanel(type = "tabs",
321
 
322
 
323
- tabPanel("KPI (CT)",
324
 
325
  br(),
326
 
@@ -409,19 +409,28 @@ ui <- shinydashboardPlus::dashboardPage(
409
  ),
410
 
411
 
412
- column(3,
413
- markdown("#### **Hide Pending Rounds?**"),
414
  switchInput(
415
  inputId = "kpi_hide_pending",
416
  onLabel = "Yes",
417
  offLabel = "No",
418
- value = FALSE)
 
 
 
 
 
 
 
 
 
419
  ),
420
 
421
  column(2,
422
- markdown("#### **Cumulative?**"),
423
  switchInput(
424
- inputId = "kpi_culmulative",
425
  onLabel = "Yes",
426
  offLabel = "No",
427
  value = FALSE)
@@ -429,20 +438,19 @@ ui <- shinydashboardPlus::dashboardPage(
429
 
430
 
431
  ),
 
 
432
 
433
  br(),
434
 
435
- h4(strong(textOutput(outputId = "text_performance_chart_title"))),
436
-
437
- markdown("![image](https://media.giphy.com/media/cftSzNoCTfSyAWctcl/giphy.gif)"),
438
 
439
  br(),
440
-
441
- h4(strong(textOutput(outputId = "text_performance_chart_data"))),
442
-
443
  br(),
444
 
445
- DTOutput("dt_kpi"),
 
 
446
 
447
  br()
448
 
@@ -516,7 +524,7 @@ ui <- shinydashboardPlus::dashboardPage(
516
  ),
517
 
518
 
519
- tabPanel("Payout (Simulation)",
520
 
521
  br(),
522
 
@@ -643,6 +651,11 @@ ui <- shinydashboardPlus::dashboardPage(
643
  markdown("- #### This hobby project was inspired by Rajiv's <b><a href='https://huggingface.co/spaces/rajistics/shiny-kmeans' target='_blank'>shiny-kmeans</a></b> on 🤗 Spaces."),
644
  markdown('- #### The <b><a href="https://linktr.ee/jofaichow" target="_blank">Rnumerai</a></b> package from Omni Analytics Group.'),
645
 
 
 
 
 
 
646
  br(),
647
  markdown("## **Changelog**"),
648
  markdown(
@@ -1070,7 +1083,7 @@ server <- function(input, output) {
1070
  d_pref <- d_pref[!is.na(KPI)]
1071
 
1072
  # Calculate Cumulative KPI (if needed)
1073
- if (input$kpi_culmulative) {
1074
 
1075
  # Sort before doing cumsum
1076
  setorderv(d_pref, c("model", "round"))
@@ -1137,7 +1150,7 @@ server <- function(input, output) {
1137
  })
1138
 
1139
  output$text_performance_chart_title <- renderText({
1140
- if (nrow(react_d_filter()) >= 1) "One Big Chart (Coming Soon!)" else " "
1141
  })
1142
 
1143
  output$text_performance_chart_data <- renderText({
@@ -1524,6 +1537,98 @@ server <- function(input, output) {
1524
  })
1525
 
1526
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1527
 
1528
  # ============================================================================
1529
  # Reactive: Payout Summary Table
@@ -1752,8 +1857,8 @@ server <- function(input, output) {
1752
  dom = 'Bflrtip', # https://datatables.net/reference/option/dom
1753
  buttons = list('csv', 'excel', 'copy', 'print'), # https://rstudio.github.io/DT/003-tabletools-buttons.html
1754
  order = list(list(0, 'asc'), list(1, 'asc')),
1755
- pageLength = 10,
1756
- lengthMenu = c(10, 50, 100, 500, 1000),
1757
  columnDefs = list(list(className = 'dt-center', targets = "_all")))
1758
  ) |>
1759
 
@@ -1766,6 +1871,8 @@ server <- function(input, output) {
1766
 
1767
  })
1768
 
 
 
1769
  # ============================================================================
1770
  # Reactive: Model Performance Charts
1771
  # ============================================================================
 
320
  tabsetPanel(type = "tabs",
321
 
322
 
323
+ tabPanel("KPI (C&T)",
324
 
325
  br(),
326
 
 
409
  ),
410
 
411
 
412
+ column(2,
413
+ markdown("#### **Hide Pending**"),
414
  switchInput(
415
  inputId = "kpi_hide_pending",
416
  onLabel = "Yes",
417
  offLabel = "No",
418
+ value = TRUE)
419
+ ),
420
+
421
+ column(2,
422
+ markdown("#### **Cumulative**"),
423
+ switchInput(
424
+ inputId = "kpi_cumulative",
425
+ onLabel = "Yes",
426
+ offLabel = "No",
427
+ value = TRUE)
428
  ),
429
 
430
  column(2,
431
+ markdown("#### **Facet**"),
432
  switchInput(
433
+ inputId = "kpi_facet",
434
  onLabel = "Yes",
435
  offLabel = "No",
436
  value = FALSE)
 
438
 
439
 
440
  ),
441
+
442
+ h4(strong(textOutput(outputId = "text_performance_chart_data"))),
443
 
444
  br(),
445
 
446
+ DTOutput("dt_kpi"),
 
 
447
 
448
  br(),
 
 
 
449
  br(),
450
 
451
+ h4(strong(textOutput(outputId = "text_performance_chart_title"))),
452
+
453
+ fluidRow(column(12, plotlyOutput("plot_kpi"))),
454
 
455
  br()
456
 
 
524
  ),
525
 
526
 
527
+ tabPanel("Payout (Sim)",
528
 
529
  br(),
530
 
 
651
  markdown("- #### This hobby project was inspired by Rajiv's <b><a href='https://huggingface.co/spaces/rajistics/shiny-kmeans' target='_blank'>shiny-kmeans</a></b> on 🤗 Spaces."),
652
  markdown('- #### The <b><a href="https://linktr.ee/jofaichow" target="_blank">Rnumerai</a></b> package from Omni Analytics Group.'),
653
 
654
+ br(),
655
+ markdown("## **Source Code**"),
656
+ markdown("- #### GitHub: https://github.com/woobe/shiny-numerati"),
657
+ markdown("- #### Hugging Face: https://huggingface.co/spaces/jofaichow/shiny-numerati/tree/main"),
658
+
659
  br(),
660
  markdown("## **Changelog**"),
661
  markdown(
 
1083
  d_pref <- d_pref[!is.na(KPI)]
1084
 
1085
  # Calculate Cumulative KPI (if needed)
1086
+ if (input$kpi_cumulative) {
1087
 
1088
  # Sort before doing cumsum
1089
  setorderv(d_pref, c("model", "round"))
 
1150
  })
1151
 
1152
  output$text_performance_chart_title <- renderText({
1153
+ if (nrow(react_d_filter()) >= 1) "KPI Chart" else " "
1154
  })
1155
 
1156
  output$text_performance_chart_data <- renderText({
 
1537
  })
1538
 
1539
 
1540
+ # KPI Chart: All KPIs
1541
+ output$plot_kpi <- renderPlotly({
1542
+
1543
+ # Data
1544
+ d_kpi <- react_d_kpi()
1545
+
1546
+ # Dynamic Labels
1547
+ if (input$kpi_choice == "CORRv2: CORRelation with target cyrus_v4_20") y_label <- "CORRv2"
1548
+ if (input$kpi_choice == "TC: True Contribtuion to the hedge fund's returns") y_label <- "TC"
1549
+ if (input$kpi_choice == "FNCv3: Feature Neutral Correlation with respect to the FNCv3 features") y_label <- "FNCv3"
1550
+ if (input$kpi_choice == "CWMM: Correlation With the Meta Model") y_label <- "CWMM"
1551
+ if (input$kpi_choice == "MCWNM: Maximum Correlation With Numerai Models staked at least 10 NMR") y_label <- "MCWNM"
1552
+ if (input$kpi_choice == "APCWNM: Average Pairwise Correlation With Numerai Models staked at least 10 NMR") y_label <- "APCWNM"
1553
+
1554
+ if (input$kpi_choice == "Score Multipliers: 0.5 x CORRv2") y_label <- "0.5 x CORRv2"
1555
+ if (input$kpi_choice == "Score Multipliers: 1.5 x CORRv2") y_label <- "1.5 x CORRv2"
1556
+ if (input$kpi_choice == "Score Multipliers: 2.0 x CORRv2") y_label <- "2.0 x CORRv2"
1557
+ if (input$kpi_choice == "Score Multipliers: 2.0 x CORRv2 + 0.5 x TC") y_label <- "2.0 x CORRv2 + 0.5 x TC"
1558
+ if (input$kpi_choice == "Score Multipliers: 2.0 x CORRv2 + 1.0 x TC") y_label <- "2.0 x CORRv2 + 1.0 x TC"
1559
+
1560
+ if (input$kpi_choice == "Percentile: CORRv2") y_label <- "CORRv2 Percentile"
1561
+ if (input$kpi_choice == "Percentile: TC") y_label <- "TC Percentile"
1562
+ if (input$kpi_choice == "Percentile: FNCv3") y_label <- "FNCv3 Percentile"
1563
+
1564
+ if (input$kpi_choice == "Payout") y_label <- "Payout (NMR)"
1565
+ if (input$kpi_choice == "Rate of Return (%): Payout / Stake x 100") y_label <- "Rate of Return (%)"
1566
+
1567
+ # If cumulative
1568
+ if (input$kpi_cumulative) y_label <- paste("Cumulative", y_label)
1569
+
1570
+ # Other settings
1571
+ y_min <- min(d_kpi$KPI) * 0.95
1572
+ if (y_min > 0) y_min <- 0
1573
+ y_max <- max(d_kpi$KPI) * 1.05
1574
+ height <- 500 # default minimum height
1575
+
1576
+ # Plot
1577
+ p <- ggplot(d_kpi, aes(x = round, y = KPI,
1578
+ ymin = y_min, ymax = y_max,
1579
+ color = model)) +
1580
+ geom_line() +
1581
+ theme(
1582
+ panel.border = element_rect(fill = 'transparent', color = "grey", linewidth = 0.25),
1583
+ panel.background = element_rect(fill = 'transparent'),
1584
+ plot.background = element_rect(fill = 'transparent', color = NA),
1585
+ panel.grid.major = element_blank(),
1586
+ panel.grid.minor = element_blank(),
1587
+ strip.background = element_rect(fill = 'transparent'),
1588
+ strip.text = element_text(),
1589
+ strip.clip = "on",
1590
+ legend.background = element_rect(fill = 'transparent'),
1591
+ legend.box.background = element_rect(fill = 'transparent'),
1592
+ axis.text.x = element_text(angle = 45, hjust = 1)
1593
+ ) +
1594
+ scale_x_continuous(breaks = breaks_pretty(5)) +
1595
+ scale_y_continuous(breaks = breaks_pretty(5)) +
1596
+ geom_hline(aes(yintercept = 0), linewidth = 0.25, color = "grey", linetype = "dashed") +
1597
+ ylab(y_label) +
1598
+ xlab("\nTournament Round")
1599
+
1600
+ # Facet wrap?
1601
+ if (input$kpi_facet) {
1602
+
1603
+ # Extract no. of models
1604
+ n_model <- length(unique(d_kpi$model))
1605
+
1606
+ # Add facet_wrap
1607
+ p <- p + facet_wrap(. ~ model, ncol = 5, scales = "fixed") # fixed
1608
+
1609
+ # Dynamic height adjustment
1610
+ if (n_model >= 10) height = 800
1611
+ if (n_model >= 15) height = 1000
1612
+ if (n_model >= 20) height = 1200
1613
+ if (n_model >= 25) height = 1400
1614
+ if (n_model >= 30) height = 1600
1615
+ if (n_model >= 35) height = 1800
1616
+ if (n_model >= 40) height = 2000
1617
+ if (n_model >= 45) height = 2200
1618
+ if (n_model >= 50) height = 2400
1619
+ if (n_model >= 55) height = 2600
1620
+ if (n_model >= 60) height = 2800
1621
+ if (n_model >= 65) height = 3000
1622
+
1623
+ }
1624
+
1625
+ # Convert to Plotly
1626
+ ggplotly(p, height = height)
1627
+
1628
+
1629
+ })
1630
+
1631
+
1632
 
1633
  # ============================================================================
1634
  # Reactive: Payout Summary Table
 
1857
  dom = 'Bflrtip', # https://datatables.net/reference/option/dom
1858
  buttons = list('csv', 'excel', 'copy', 'print'), # https://rstudio.github.io/DT/003-tabletools-buttons.html
1859
  order = list(list(0, 'asc'), list(1, 'asc')),
1860
+ pageLength = 5,
1861
+ lengthMenu = c(5, 10, 50, 100, 500, 1000),
1862
  columnDefs = list(list(className = 'dt-center', targets = "_all")))
1863
  ) |>
1864
 
 
1871
 
1872
  })
1873
 
1874
+
1875
+
1876
  # ============================================================================
1877
  # Reactive: Model Performance Charts
1878
  # ============================================================================