jofaichow commited on
Commit
5bde136
1 Parent(s): 7fb33fd

0.1.9 - Added New Payout Simulation

Browse files
Files changed (1) hide show
  1. app/app.R +240 -2
app/app.R CHANGED
@@ -106,6 +106,16 @@ gen_custom_palette <- function(ls_model) {
106
  }
107
 
108
 
 
 
 
 
 
 
 
 
 
 
109
  # ==============================================================================
110
  # UI
111
  # ==============================================================================
@@ -373,6 +383,49 @@ ui <- shinydashboardPlus::dashboardPage(
373
  ),
374
 
375
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
  tabPanel("Chart (All Models)",
377
 
378
  br(),
@@ -399,7 +452,7 @@ ui <- shinydashboardPlus::dashboardPage(
399
  br(),
400
  shinycssloaders::withSpinner(plotlyOutput("plot_payout_individual"))
401
  )
402
-
403
  ) # end of tabsetPanel
404
 
405
  ) # end of fluidPage
@@ -497,6 +550,7 @@ ui <- shinydashboardPlus::dashboardPage(
497
  - #### **0.1.6** — Added `apcwnm` and `mcwnm`
498
  - #### **0.1.7** — Added CoE Meetup GitHub page to `Community`
499
  - #### **0.1.8** — Various improvements in `Payout Summary`
 
500
  "),
501
 
502
  br(),
@@ -515,7 +569,7 @@ ui <- shinydashboardPlus::dashboardPage(
515
 
516
  footer = shinydashboardPlus::dashboardFooter(
517
  left = "Powered by ❤️, ☕, Shiny, and 🤗 Spaces",
518
- right = paste0("Version 0.1.8"))
519
 
520
  )
521
 
@@ -712,6 +766,104 @@ server <- function(input, output) {
712
 
713
 
714
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
715
 
716
 
717
  # ============================================================================
@@ -738,6 +890,11 @@ server <- function(input, output) {
738
  if (nrow(react_d_filter()) >= 1) "Payout Summary Chart (Individual Models)" else " "
739
  })
740
 
 
 
 
 
 
741
 
742
  # ============================================================================
743
  # Reactive valueBox outputs: Rounds
@@ -1022,6 +1179,7 @@ server <- function(input, output) {
1022
 
1023
  })
1024
 
 
1025
 
1026
  # ============================================================================
1027
  # Reactive: Payout Summary Table
@@ -1115,6 +1273,86 @@ server <- function(input, output) {
1115
  })
1116
 
1117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1118
 
1119
  # ============================================================================
1120
  # Reactive: Model Performance Charts
 
106
  }
107
 
108
 
109
+ # max drawdown
110
+ # https://stackoverflow.com/questions/13733166/maxdrawdown-function
111
+ drawdown <- function(pnl) {
112
+ cum.pnl <- c(0, cumsum(pnl))
113
+ drawdown <- cum.pnl - cummax(cum.pnl)
114
+ return(tail(drawdown, -1))
115
+ }
116
+ maxdrawdown <- function(pnl)min(drawdown(pnl))
117
+
118
+
119
  # ==============================================================================
120
  # UI
121
  # ==============================================================================
 
383
  ),
384
 
385
 
386
+ tabPanel("Payout Sim (Experimental)",
387
+
388
+ br(),
389
+
390
+ h3(strong(textOutput(outputId = "text_payout_sim"))),
391
+
392
+ br(),
393
+
394
+
395
+ markdown("![new_tc_change](https://i.ibb.co/XjKwtzr/screenshot-2023-10-05-at-10.png)"),
396
+
397
+ br(),
398
+
399
+ markdown("#### **Notes**:
400
+
401
+ - **sum_pay**: Sum of Payouts
402
+ - **shp_pay**: Sharpe Ratio of Payouts
403
+ - **1C0T**: 1xCORRv2 + 0xTC
404
+ - **2C0T**: 2xCORRv2 + 0xTC (New Payout Mode)
405
+ - **2C1T**: 2xCORRv2 + 1xTC (New Payout Mode)
406
+ - **1C3T**: 1xCORRv2 + 3xTC (Original Degen Mode)
407
+
408
+ "),
409
+
410
+ br(),
411
+
412
+ markdown("### **Payout Simulation (Overall)**"),
413
+
414
+ DTOutput("dt_payout_sim_overall"),
415
+
416
+ br(),
417
+ br(),
418
+
419
+ markdown("### **Payout Simulation (Individual Models)**"),
420
+
421
+ br(),
422
+
423
+ DTOutput("dt_payout_sim_model"),
424
+
425
+ br()
426
+
427
+ ),
428
+
429
  tabPanel("Chart (All Models)",
430
 
431
  br(),
 
452
  br(),
453
  shinycssloaders::withSpinner(plotlyOutput("plot_payout_individual"))
454
  )
455
+
456
  ) # end of tabsetPanel
457
 
458
  ) # end of fluidPage
 
550
  - #### **0.1.6** — Added `apcwnm` and `mcwnm`
551
  - #### **0.1.7** — Added CoE Meetup GitHub page to `Community`
552
  - #### **0.1.8** — Various improvements in `Payout Summary`
553
+ - #### **0.1.9** — Added `Payout Sim` based on new Corr and TC multipier settings
554
  "),
555
 
556
  br(),
 
569
 
570
  footer = shinydashboardPlus::dashboardFooter(
571
  left = "Powered by ❤️, ☕, Shiny, and 🤗 Spaces",
572
+ right = paste0("Version 0.1.9"))
573
 
574
  )
575
 
 
766
 
767
 
768
 
769
+ react_d_payout_sim_model <- eventReactive(
770
+ input$button_filter,
771
+ {
772
+
773
+ # Get filtered data
774
+ d_payout <- as.data.table(react_d_filter())
775
+
776
+ # Apply clip to corrV2
777
+ d_payout[, corrV2_final := corrV2]
778
+ d_payout[corrV2 > 0.25, corrV2_final := 0.25]
779
+ d_payout[corrV2 < -0.25, corrV2_final := -0.25]
780
+
781
+ # Apply clip to tc
782
+ d_payout[, tc_final := tc]
783
+ d_payout[tc > 0.25, tc_final := 0.25]
784
+ d_payout[tc < -0.25, tc_final := -0.25]
785
+
786
+ # Calculate different payout
787
+ d_payout[, payout_1C0T := (corrV2_final) * stake * pay_ftr]
788
+ d_payout[, payout_2C0T := (2*corrV2_final) * stake * pay_ftr]
789
+ d_payout[, payout_2C1T := (2*corrV2_final + tc_final) * stake * pay_ftr]
790
+ d_payout[, payout_1C3T := (corrV2_final + 3*tc_final) * stake * pay_ftr]
791
+
792
+ # Summarise
793
+ d_payout_smry <-
794
+ d_payout |>
795
+ lazy_dt() |>
796
+ group_by(model) |>
797
+ summarise(
798
+ rounds = n(),
799
+
800
+ sum_pay_1C0T = sum(payout_1C0T, na.rm = T),
801
+ sum_pay_2C0T = sum(payout_2C0T, na.rm = T),
802
+ sum_pay_2C1T = sum(payout_2C1T, na.rm = T),
803
+ sum_pay_1C3T = sum(payout_1C3T, na.rm = T),
804
+
805
+ shp_pay_1C0T = mean(payout_1C0T, na.rm = T) / sd(payout_1C0T, na.rm = T),
806
+ shp_pay_2C0T = mean(payout_2C0T, na.rm = T) / sd(payout_2C0T, na.rm = T),
807
+ shp_pay_2C1T = mean(payout_2C1T, na.rm = T) / sd(payout_2C1T, na.rm = T),
808
+ shp_pay_1C3T = mean(payout_1C3T, na.rm = T) / sd(payout_1C3T, na.rm = T)
809
+
810
+ ) |>
811
+ as.data.table()
812
+
813
+ # Return
814
+ d_payout_smry
815
+
816
+ })
817
+
818
+
819
+ react_d_payout_sim_overall <- eventReactive(
820
+ input$button_filter,
821
+ {
822
+
823
+ # Get filtered data
824
+ d_payout <- as.data.table(react_d_filter())
825
+
826
+ # Apply clip to corrV2
827
+ d_payout[, corrV2_final := corrV2]
828
+ d_payout[corrV2 > 0.25, corrV2_final := 0.25]
829
+ d_payout[corrV2 < -0.25, corrV2_final := -0.25]
830
+
831
+ # Apply clip to tc
832
+ d_payout[, tc_final := tc]
833
+ d_payout[tc > 0.25, tc_final := 0.25]
834
+ d_payout[tc < -0.25, tc_final := -0.25]
835
+
836
+ # Calculate different payout
837
+ d_payout[, payout_1C0T := (corrV2_final) * stake * pay_ftr]
838
+ d_payout[, payout_2C0T := (2*corrV2_final) * stake * pay_ftr]
839
+ d_payout[, payout_2C1T := (2*corrV2_final + tc_final) * stake * pay_ftr]
840
+ d_payout[, payout_1C3T := (corrV2_final + 3*tc_final) * stake * pay_ftr]
841
+
842
+ # Summarise
843
+ d_payout_smry <-
844
+ d_payout |>
845
+ lazy_dt() |>
846
+ summarise(
847
+
848
+ sum_pay_1C0T = sum(payout_1C0T, na.rm = T),
849
+ sum_pay_2C0T = sum(payout_2C0T, na.rm = T),
850
+ sum_pay_2C1T = sum(payout_2C1T, na.rm = T),
851
+ sum_pay_1C3T = sum(payout_1C3T, na.rm = T),
852
+
853
+ shp_pay_1C0T = mean(payout_1C0T, na.rm = T) / sd(payout_1C0T, na.rm = T),
854
+ shp_pay_2C0T = mean(payout_2C0T, na.rm = T) / sd(payout_2C0T, na.rm = T),
855
+ shp_pay_2C1T = mean(payout_2C1T, na.rm = T) / sd(payout_2C1T, na.rm = T),
856
+ shp_pay_1C3T = mean(payout_1C3T, na.rm = T) / sd(payout_1C3T, na.rm = T)
857
+
858
+ ) |>
859
+ as.data.table()
860
+
861
+ # Return
862
+ d_payout_smry
863
+
864
+ })
865
+
866
+
867
 
868
 
869
  # ============================================================================
 
890
  if (nrow(react_d_filter()) >= 1) "Payout Summary Chart (Individual Models)" else " "
891
  })
892
 
893
+ output$text_payout_sim <- renderText({
894
+ if (nrow(react_d_filter()) >= 1) "New Payout Simulation (NOTE: Experimental!)" else " "
895
+ })
896
+
897
+
898
 
899
  # ============================================================================
900
  # Reactive valueBox outputs: Rounds
 
1179
 
1180
  })
1181
 
1182
+
1183
 
1184
  # ============================================================================
1185
  # Reactive: Payout Summary Table
 
1273
  })
1274
 
1275
 
1276
+ # Payout Sim (Model)
1277
+ output$dt_payout_sim_model <- DT::renderDT({
1278
+
1279
+ # Generate a new DT
1280
+ DT::datatable(
1281
+
1282
+ # Data
1283
+ react_d_payout_sim_model(),
1284
+
1285
+ # Other Options
1286
+ rownames = FALSE,
1287
+ extensions = "Buttons",
1288
+ options =
1289
+ list(
1290
+ dom = 'Bflrtip', # https://datatables.net/reference/option/dom
1291
+ buttons = list('csv', 'excel', 'copy', 'print'), # https://rstudio.github.io/DT/003-tabletools-buttons.html
1292
+ order = list(list(0, 'asc'), list(1, 'asc')),
1293
+ pageLength = 100,
1294
+ lengthMenu = c(10, 50, 100, 500, 1000),
1295
+ columnDefs = list(list(className = 'dt-center', targets = "_all")))
1296
+ ) |>
1297
+
1298
+ # Reformat individual columns
1299
+ formatRound(columns = c("sum_pay_1C0T", "sum_pay_2C0T", "sum_pay_2C1T", "sum_pay_1C3T",
1300
+ "shp_pay_1C0T", "shp_pay_2C0T", "shp_pay_2C1T", "shp_pay_1C3T"),
1301
+ digits = 2) |>
1302
+
1303
+ formatStyle(columns = c("sum_pay_1C0T", "sum_pay_2C0T", "sum_pay_2C1T", "sum_pay_1C3T",
1304
+ "shp_pay_1C0T", "shp_pay_2C0T", "shp_pay_2C1T", "shp_pay_1C3T"),
1305
+ color = styleInterval(cuts = c(-1e-15, 1e-15),
1306
+ values = c("#D24141", "#D1D1D1", "#00A800"))) |>
1307
+
1308
+ formatStyle(columns = c("model",
1309
+ "sum_pay_2C1T", "sum_pay_1C3T",
1310
+ "shp_pay_2C1T", "shp_pay_1C3T"
1311
+ ), fontWeight = "bold")
1312
+
1313
+ })
1314
+
1315
+
1316
+ # Payout Sim (Overall)
1317
+ output$dt_payout_sim_overall <- DT::renderDT({
1318
+
1319
+ # Generate a new DT
1320
+ DT::datatable(
1321
+
1322
+ # Data
1323
+ react_d_payout_sim_overall(),
1324
+
1325
+ # Other Options
1326
+ rownames = FALSE,
1327
+ # extensions = "Buttons",
1328
+ options =
1329
+ list(
1330
+ dom = 't', # https://datatables.net/reference/option/dom
1331
+ # buttons = list('csv', 'excel', 'copy', 'print'), # https://rstudio.github.io/DT/003-tabletools-buttons.html
1332
+ # order = list(list(0, 'asc'), list(1, 'asc')),
1333
+ # pageLength = 10,
1334
+ # lengthMenu = c(10, 50, 100, 500, 1000),
1335
+ columnDefs = list(list(className = 'dt-center', targets = "_all")))
1336
+ ) |>
1337
+
1338
+ # Reformat individual columns
1339
+ formatRound(columns = c("sum_pay_1C0T", "sum_pay_2C0T", "sum_pay_2C1T", "sum_pay_1C3T",
1340
+ "shp_pay_1C0T", "shp_pay_2C0T", "shp_pay_2C1T", "shp_pay_1C3T"),
1341
+ digits = 2) |>
1342
+
1343
+ formatStyle(columns = c("sum_pay_1C0T", "sum_pay_2C0T", "sum_pay_2C1T", "sum_pay_1C3T",
1344
+ "shp_pay_1C0T", "shp_pay_2C0T", "shp_pay_2C1T", "shp_pay_1C3T"),
1345
+ color = styleInterval(cuts = c(-1e-15, 1e-15),
1346
+ values = c("#D24141", "#D1D1D1", "#00A800"))) |>
1347
+
1348
+ formatStyle(columns = c("sum_pay_2C1T", "sum_pay_1C3T",
1349
+ "shp_pay_2C1T", "shp_pay_1C3T"
1350
+ ), fontWeight = "bold")
1351
+
1352
+ })
1353
+
1354
+
1355
+
1356
 
1357
  # ============================================================================
1358
  # Reactive: Model Performance Charts