Spaces:
Running
Running
0.2.0 - Added KPI charts
Browse files
app/app.R
CHANGED
@@ -328,13 +328,24 @@ ui <- shinydashboardPlus::dashboardPage(
|
|
328 |
|
329 |
h3(strong(textOutput(outputId = "text_performance_models"))),
|
330 |
|
|
|
|
|
331 |
br(),
|
332 |
|
333 |
-
|
|
|
|
|
|
|
334 |
|
|
|
|
|
335 |
br(),
|
336 |
|
337 |
-
|
|
|
|
|
|
|
|
|
338 |
|
339 |
- **avg_corrV2**: Average `CORRv2`
|
340 |
- **sharpe_corrV2**: Sharpe Ratio of `CORRv2`
|
@@ -346,9 +357,13 @@ ui <- shinydashboardPlus::dashboardPage(
|
|
346 |
- **sharpe_2C1T**: Sharpe Ratio of `2xCORRv2 + 1xTC`
|
347 |
|
348 |
"),
|
|
|
|
|
|
|
349 |
|
|
|
350 |
br()
|
351 |
-
|
352 |
),
|
353 |
|
354 |
|
@@ -781,8 +796,7 @@ server <- function(input, output) {
|
|
781 |
d_smry
|
782 |
|
783 |
})
|
784 |
-
|
785 |
-
|
786 |
|
787 |
react_d_payout_sim_model <- eventReactive(
|
788 |
input$button_filter,
|
@@ -931,45 +945,6 @@ server <- function(input, output) {
|
|
931 |
})
|
932 |
|
933 |
|
934 |
-
react_d_performance_summary_example <- eventReactive(
|
935 |
-
input$button_filter,
|
936 |
-
{
|
937 |
-
|
938 |
-
# Get filtered data
|
939 |
-
d_pref <- as.data.table(react_d_filter_example())
|
940 |
-
|
941 |
-
# Add 2xCORRv2 + 1xTC
|
942 |
-
d_pref[, twoC_oneT := 2*corrV2 + tc]
|
943 |
-
|
944 |
-
# Calculate some high level stats
|
945 |
-
d_pref <-
|
946 |
-
d_pref |>
|
947 |
-
lazy_dt() |>
|
948 |
-
group_by(model) |>
|
949 |
-
summarise(total_rounds = n(),
|
950 |
-
|
951 |
-
avg_corrV2 = mean(corrV2, na.rm = T),
|
952 |
-
sharpe_corrV2 = mean(corrV2, na.rm = T) / sd(corrV2, na.rm = T),
|
953 |
-
# mdd_corrV2 = maxdrawdown(corrV2),
|
954 |
-
|
955 |
-
avg_tc = mean(tc, na.rm = T),
|
956 |
-
sharpe_tc = mean(tc, na.rm = T) / sd(tc, na.rm = T),
|
957 |
-
# mdd_tc = maxdrawdown(tc),
|
958 |
-
|
959 |
-
avg_2C1T = mean(twoC_oneT, na.rm = T),
|
960 |
-
sharpe_2C1T = mean(twoC_oneT, na.rm = T) / sd(tc, na.rm = T)
|
961 |
-
# mdd_2C1T = maxdrawdown(twoC_oneT)
|
962 |
-
|
963 |
-
) |> as.data.table()
|
964 |
-
|
965 |
-
# Return
|
966 |
-
d_pref
|
967 |
-
|
968 |
-
})
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
# ============================================================================
|
974 |
# Reactive: Payout Value Boxes
|
975 |
# ============================================================================
|
@@ -1001,8 +976,10 @@ server <- function(input, output) {
|
|
1001 |
output$text_performance_models <- renderText({
|
1002 |
if (nrow(react_d_filter()) >= 1) "KPIs Summary (Individual Models)" else " "
|
1003 |
})
|
1004 |
-
|
1005 |
-
|
|
|
|
|
1006 |
|
1007 |
|
1008 |
# ============================================================================
|
@@ -1289,6 +1266,82 @@ server <- function(input, output) {
|
|
1289 |
})
|
1290 |
|
1291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1292 |
|
1293 |
# ============================================================================
|
1294 |
# Reactive: Payout Summary Table
|
@@ -1478,7 +1531,7 @@ server <- function(input, output) {
|
|
1478 |
dom = 'Bflrtip', # https://datatables.net/reference/option/dom
|
1479 |
buttons = list('csv', 'excel', 'copy', 'print'), # https://rstudio.github.io/DT/003-tabletools-buttons.html
|
1480 |
order = list(list(0, 'asc'), list(1, 'asc')),
|
1481 |
-
pageLength =
|
1482 |
lengthMenu = c(10, 50, 100, 500, 1000),
|
1483 |
columnDefs = list(list(className = 'dt-center', targets = "_all")))
|
1484 |
) |>
|
|
|
328 |
|
329 |
h3(strong(textOutput(outputId = "text_performance_models"))),
|
330 |
|
331 |
+
h4(textOutput(outputId = "text_performance_models_note")),
|
332 |
+
|
333 |
br(),
|
334 |
|
335 |
+
fluidRow(
|
336 |
+
column(width = 6, plotlyOutput("plot_performance_avg")),
|
337 |
+
column(width = 6, plotlyOutput("plot_performance_sharpe"))
|
338 |
+
),
|
339 |
|
340 |
+
br(),
|
341 |
+
br(),
|
342 |
br(),
|
343 |
|
344 |
+
fluidRow(DTOutput("dt_performance_summary"),
|
345 |
+
|
346 |
+
br(),
|
347 |
+
|
348 |
+
markdown("#### **Notes**:
|
349 |
|
350 |
- **avg_corrV2**: Average `CORRv2`
|
351 |
- **sharpe_corrV2**: Sharpe Ratio of `CORRv2`
|
|
|
357 |
- **sharpe_2C1T**: Sharpe Ratio of `2xCORRv2 + 1xTC`
|
358 |
|
359 |
"),
|
360 |
+
|
361 |
+
br()
|
362 |
+
),
|
363 |
|
364 |
+
|
365 |
br()
|
366 |
+
|
367 |
),
|
368 |
|
369 |
|
|
|
796 |
d_smry
|
797 |
|
798 |
})
|
799 |
+
|
|
|
800 |
|
801 |
react_d_payout_sim_model <- eventReactive(
|
802 |
input$button_filter,
|
|
|
945 |
})
|
946 |
|
947 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
948 |
# ============================================================================
|
949 |
# Reactive: Payout Value Boxes
|
950 |
# ============================================================================
|
|
|
976 |
output$text_performance_models <- renderText({
|
977 |
if (nrow(react_d_filter()) >= 1) "KPIs Summary (Individual Models)" else " "
|
978 |
})
|
979 |
+
|
980 |
+
output$text_performance_models_note <- renderText({
|
981 |
+
if (nrow(react_d_filter()) >= 1) "NOTE: You may want to find out which models have high CORRv2 Sharpe and high TC Sharpe." else " "
|
982 |
+
})
|
983 |
|
984 |
|
985 |
# ============================================================================
|
|
|
1266 |
})
|
1267 |
|
1268 |
|
1269 |
+
# KPI Chart: Avg Corr vs. Avg TC
|
1270 |
+
output$plot_performance_avg <- renderPlotly({
|
1271 |
+
|
1272 |
+
# Data
|
1273 |
+
d_pref <- react_d_performance_summary()
|
1274 |
+
|
1275 |
+
# Plot
|
1276 |
+
p_avg <- ggplot(d_pref,
|
1277 |
+
aes(x = avg_tc, y = avg_corrV2,
|
1278 |
+
text = paste("Model:", model,
|
1279 |
+
"\nAverage CORRv2:", round(avg_corrV2, 4),
|
1280 |
+
"\nAverage TC:", round(avg_tc, 4))
|
1281 |
+
)) +
|
1282 |
+
geom_point() +
|
1283 |
+
theme(
|
1284 |
+
panel.border = element_rect(fill = 'transparent', color = "grey", linewidth = 0.25),
|
1285 |
+
panel.background = element_rect(fill = 'transparent'),
|
1286 |
+
plot.background = element_rect(fill = 'transparent', color = NA),
|
1287 |
+
panel.grid.major = element_blank(),
|
1288 |
+
panel.grid.minor = element_blank(),
|
1289 |
+
strip.background = element_rect(fill = 'transparent'),
|
1290 |
+
strip.text = element_text(),
|
1291 |
+
strip.clip = "on",
|
1292 |
+
legend.background = element_rect(fill = 'transparent'),
|
1293 |
+
legend.box.background = element_rect(fill = 'transparent'),
|
1294 |
+
axis.text.x = element_text(angle = 45, hjust = 1)
|
1295 |
+
) +
|
1296 |
+
scale_x_continuous(breaks = breaks_pretty(5)) +
|
1297 |
+
scale_y_continuous(breaks = breaks_pretty(5)) +
|
1298 |
+
xlab("\nAverage TC") +
|
1299 |
+
ylab("\nAverage CORRv2")
|
1300 |
+
|
1301 |
+
# Convert to Plotly
|
1302 |
+
ggplotly(p_avg, tooltip = "text")
|
1303 |
+
|
1304 |
+
})
|
1305 |
+
|
1306 |
+
|
1307 |
+
# KPI Chart: Corr Sharpe vs. TC Sharpe
|
1308 |
+
output$plot_performance_sharpe <- renderPlotly({
|
1309 |
+
|
1310 |
+
# Data
|
1311 |
+
d_pref <- react_d_performance_summary()
|
1312 |
+
|
1313 |
+
# Plot
|
1314 |
+
p_sharpe <- ggplot(d_pref,
|
1315 |
+
aes(x = sharpe_tc, y = sharpe_corrV2,
|
1316 |
+
text = paste("Model:", model,
|
1317 |
+
"\nSharpe Ratio of CORRv2:", round(sharpe_corrV2, 4),
|
1318 |
+
"\nSharpe Ratio of TC:", round(sharpe_tc, 4))
|
1319 |
+
)) +
|
1320 |
+
geom_point() +
|
1321 |
+
theme(
|
1322 |
+
panel.border = element_rect(fill = 'transparent', color = "grey", linewidth = 0.25),
|
1323 |
+
panel.background = element_rect(fill = 'transparent'),
|
1324 |
+
plot.background = element_rect(fill = 'transparent', color = NA),
|
1325 |
+
panel.grid.major = element_blank(),
|
1326 |
+
panel.grid.minor = element_blank(),
|
1327 |
+
strip.background = element_rect(fill = 'transparent'),
|
1328 |
+
strip.text = element_text(),
|
1329 |
+
strip.clip = "on",
|
1330 |
+
legend.background = element_rect(fill = 'transparent'),
|
1331 |
+
legend.box.background = element_rect(fill = 'transparent'),
|
1332 |
+
axis.text.x = element_text(angle = 45, hjust = 1)
|
1333 |
+
) +
|
1334 |
+
scale_x_continuous(breaks = breaks_pretty(5)) +
|
1335 |
+
scale_y_continuous(breaks = breaks_pretty(5)) +
|
1336 |
+
xlab("\nSharpe Ratio of TC") +
|
1337 |
+
ylab("\nSharpe Ratio of CORRv2")
|
1338 |
+
|
1339 |
+
# Convert to Plotly
|
1340 |
+
ggplotly(p_sharpe, tooltip = "text")
|
1341 |
+
|
1342 |
+
})
|
1343 |
+
|
1344 |
+
|
1345 |
|
1346 |
# ============================================================================
|
1347 |
# Reactive: Payout Summary Table
|
|
|
1531 |
dom = 'Bflrtip', # https://datatables.net/reference/option/dom
|
1532 |
buttons = list('csv', 'excel', 'copy', 'print'), # https://rstudio.github.io/DT/003-tabletools-buttons.html
|
1533 |
order = list(list(0, 'asc'), list(1, 'asc')),
|
1534 |
+
pageLength = 10,
|
1535 |
lengthMenu = c(10, 50, 100, 500, 1000),
|
1536 |
columnDefs = list(list(className = 'dt-center', targets = "_all")))
|
1537 |
) |>
|