尝试计算观察的期望值

huangapple go评论85阅读模式
英文:

Trying to calculate the Expected Value of an observation

问题

这是计算的部分:

-4.482633 = (.55718 * 71.43) - (.44282 * 100)

上述计算中的数值对应以下变量:

-4.482633 = 我试图得出的预期值
.55718 = "Pinnacle" 的 "no_vig_bep"
71.43 = 观察1的 "win"
.44282 = 1 - "Pinnacle" 的 "no_vig_bep" 或最后一行
100 = 一固定金额

然后,我想计算赔率的另一侧,如下所示:

-2.5796 = (.44282 * 120.00) - (.55718 * 100)

最终目标是使用 "Pinnacle" 书中的值执行上述计算,并将EV写入新列。

英文:

I have a tibble and am trying to use values from two specific rows (Pinnacle book) to perform a calculation. The values of the calculation will be written to a new column. Here is the output of dput

  1. structure(list(id = c("5d8f6b2536fbdc4ab6a3e9759ebc6c51", "5d8f6b2536fbdc4ab6a3e9759ebc6c51",
  2. "5d8f6b2536fbdc4ab6a3e9759ebc6c51", "5d8f6b2536fbdc4ab6a3e9759ebc6c51",
  3. "5d8f6b2536fbdc4ab6a3e9759ebc6c51", "5d8f6b2536fbdc4ab6a3e9759ebc6c51"
  4. ), start = structure(c(1676691000, 1676691000, 1676691000, 1676691000,
  5. 1676691000, 1676691000), tzone = "UTC", class = c("POSIXct",
  6. "POSIXt")), book = c("BetUS", "BetUS", "Bovada", "Bovada", "Pinnacle",
  7. "Pinnacle"), home = c("San José St Spartans", "San José St Spartans",
  8. "San José St Spartans", "San José St Spartans", "San José St Spartans",
  9. "San José St Spartans"), away = c("New Mexico Lobos", "New Mexico Lobos",
  10. "New Mexico Lobos", "New Mexico Lobos", "New Mexico Lobos", "New Mexico Lobos"
  11. ), team = c("San José St Spartans", "New Mexico Lobos", "San José St Spartans",
  12. "New Mexico Lobos", "San José St Spartans", "New Mexico Lobos"
  13. ), price = c(-140, 120, -140, 120, -138, 117), update = c("2023-02-18T00:24:43Z",
  14. "2023-02-18T00:24:43Z", "2023-02-18T00:25:10Z", "2023-02-18T00:25:10Z",
  15. "2023-02-18T00:25:04Z", "2023-02-18T00:25:04Z"), bep = c(0.58333,
  16. 0.45455, 0.58333, 0.45455, 0.57983, 0.46083), no_vig = c(-128.33333,
  17. 128.33333, -128.33333, 128.33333, -125.82353, 125.82353), no_vig_bep = c(0.56204,
  18. 0.43796, 0.56204, 0.43796, 0.55718, 0.44282), win = c(71.43,
  19. 120, 71.43, 120, 72.46, 117)), class = c("grouped_df", "tbl_df",
  20. "tbl", "data.frame"), row.names = c(NA, -6L), groups = structure(list(
  21. id = c("5d8f6b2536fbdc4ab6a3e9759ebc6c51", "5d8f6b2536fbdc4ab6a3e9759ebc6c51",
  22. "5d8f6b2536fbdc4ab6a3e9759ebc6c51", "5d8f6b2536fbdc4ab6a3e9759ebc6c51",
  23. "5d8f6b2536fbdc4ab6a3e9759ebc6c51", "5d8f6b2536fbdc4ab6a3e9759ebc6c51"
  24. ), book = c("BetUS", "BetUS", "Bovada", "Bovada", "Pinnacle",
  25. "Pinnacle"), team = c("New Mexico Lobos", "San José St Spartans",
  26. "New Mexico Lobos", "San José St Spartans", "New Mexico Lobos",
  27. "San José St Spartans"), .rows = structure(list(2L, 1L,
  28. 4L, 3L, 6L, 5L), ptype = integer(0), class = c("vctrs_list_of",
  29. "vctrs_vctr", "list"))), row.names = c(NA, -6L), class = c("tbl_df",
  30. "tbl", "data.frame"), .drop = TRUE))

The following is the calculation

  1. -4.482633 = (.55718 * 71.43) - (.44282 * 100)

The values in the calculation above correspond with the following variables

  1. -4.482633 = Expected Value I am trying to derive
  2. .55718 = "no_vig_bep" of Pinnacle
  3. 71.43 = "win" of observation 1
  4. .44282 = 1 - "no_vig_bep" of Pinnacle or the last row
  5. 100 = a set amount

I Would then like to calculate the other side of the odds as follow

  1. -2.5796 = (.44282 * 120.00) - (.55718 * 100)

The ultimate goal is to use the values of the Pinnacle book to perform the above calculation against all other books. The EV will be written to a new column.

Included additional id for further clarification

  1. structure(list(id = c("073c154f3c8586868a3ba21522161a70",
  2. "073c154f3c8586868a3ba21522161a70",
  3. "073c154f3c8586868a3ba21522161a70", "073c154f3c8586868a3ba21522161a70",
  4. "073c154f3c8586868a3ba21522161a70", "073c154f3c8586868a3ba21522161a70"
  5. ), book = c("Bovada", "Pinnacle", "MyBookie.ag", "MyBookie.ag",
  6. "Pinnacle", "Bovada"), home = c("Western Michigan Broncos", "Western
  7. Michigan Broncos",
  8. "Western Michigan Broncos", "Western Michigan Broncos", "Western
  9. Michigan Broncos",
  10. "Western Michigan Broncos"), away = c("Ball State Cardinals",
  11. "Ball State Cardinals", "Ball State Cardinals", "Ball State Cardinals",
  12. "Ball State Cardinals", "Ball State Cardinals"), team = c("Western
  13. Michigan Broncos",
  14. "Ball State Cardinals", "Western Michigan Broncos", "Ball State
  15. Cardinals",
  16. "Western Michigan Broncos", "Ball State Cardinals"), price = c(-185,
  17. -143, -142, 100, 108, 140), bep = c(0.64912, 0.58848, 0.58678,
  18. 0.5, 0.48077, 0.41667), no_vig = c(-155.78947, -122.40329, -117.35537,
  19. 117.35537, 122.40329, 155.78947), no_vig_bep = c(0.60905, 0.55037,
  20. 0.53992, 0.46008, 0.44963, 0.39095), win = c(54.05, 69.93, 70.42,
  21. 100, 108, 140), EV_1 = c(-15.2155015, -6.47562589999999,
  22. -6.20594459999999,
  23. -10.074, -6.47696000000001, 7.91119999999999)), class = c("grouped_df",
  24. "tbl_df", "tbl", "data.frame"), row.names = c(NA, -6L), groups =
  25. structure(list(
  26. book = c("Bovada", "MyBookie.ag", "Pinnacle"), .rows = structure(list(
  27. c(1L, 6L), 3:4, c(2L, 5L)), ptype = integer(0), class =
  28. c("vctrs_list_of",
  29. "vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
  30. ), row.names = c(NA, -3L), .drop = TRUE))

答案1

得分: 1

编辑1:也许 purrr 可以在这里帮助你:

  1. library(purrr)
  2. no_vig_pin_list <- df |
  3. ungroup() |
  4. split(df$id) |
  5. map(~.x | filter(book == "Pinnacle") | pull(no_vig_bep))
  6. df |
  7. ungroup() |
  8. group_split(id) |
  9. purrr::map2_dfr(no_vig_pin_list, ~ .x |
  10. group_by(book) |
  11. mutate(EV_1 = ifelse(row_number() == 1,
  12. (.y[1] * win)- ((1-.y[1])*100),
  13. (.y[2] * win)- ((1-.y[2])*100)))) |
  14. select(EV_1)

或许这可以帮到你,我不太确定你想要实现什么。

  1. library(dplyr)
  2. no_vig_pin <- df |
  3. filter(book == "Pinnacle") |
  4. pull(no_vig_bep)
  5. df |
  6. group_by(book) |
  7. mutate(EV_1 = ifelse(row_number() == 1,
  8. (no_vig_pin[1] * win)- ((1-no_vig_pin[1])*100),
  9. (no_vig_pin[2] * win)- ((1-no_vig_pin[2])*100))) |
  10. select(EV_1)

输出

  1. # A tibble: 6 × 2
  2. # Groups: book [3]
  3. book EV_1
  4. <chr> <dbl>
  5. 1 BetUS -4.48
  6. 2 BetUS -2.58
  7. 3 Bovada -4.48
  8. 4 Bovada -2.58
  9. 5 Pinnacle -3.91
  10. 6 Pinnacle -3.91
英文:

Edit1: Maybe purrr can help you here:

  1. library(purrr)
  2. no_vig_pin_list &lt;- df |&gt;
  3. ungroup() |&gt;
  4. split(df$id) |&gt;
  5. map(~.x |&gt; filter(book == &quot;Pinnacle&quot;) |&gt; pull(no_vig_bep))
  6. df |&gt;
  7. ungroup() |&gt;
  8. group_split(id) |&gt;
  9. purrr::map2_dfr(no_vig_pin_list, ~ .x |&gt;
  10. group_by(book) |&gt;
  11. mutate(EV_1 = ifelse(row_number() == 1,
  12. (.y[1] * win)- ((1-.y[1])*100),
  13. (.y[2] * win)- ((1-.y[2])*100)))) |&gt;
  14. select(EV_1)
  15. A tibble: 8 &#215; 2
  16. # Groups: book [2]
  17. book EV_1
  18. &lt;chr&gt; &lt;dbl&gt;
  19. 1 BetUS -5.03
  20. 2 BetUS -1.10
  21. 3 Pinnacle -4.07
  22. 4 Pinnacle -4.07
  23. 5 BetUS -4.48
  24. 6 BetUS -2.58
  25. 7 Pinnacle -3.91
  26. 8 Pinnacle -3.91

Maybe this helps, I am not quite sure that I understood what you are trying to achieve.

  1. library(dplyr)
  2. no_vig_pin &lt;- df |&gt;
  3. filter(book == &quot;Pinnacle&quot;) |&gt;
  4. pull(no_vig_bep)
  5. df |&gt;
  6. group_by(book) |&gt;
  7. mutate(EV_1 = ifelse(row_number() == 1,
  8. (no_vig_pin[1] * win)- ((1-no_vig_pin[1])*100),
  9. (no_vig_pin[2] * win)- ((1-no_vig_pin[2])*100))) |&gt;
  10. select(EV_1)

Output:

  1. # A tibble: 6 &#215; 2
  2. # Groups: book [3]
  3. book EV_1
  4. &lt;chr&gt; &lt;dbl&gt;
  5. 1 BetUS -4.48
  6. 2 BetUS -2.58
  7. 3 Bovada -4.48
  8. 4 Bovada -2.58
  9. 5 Pinnacle -3.91
  10. 6 Pinnacle -3.91

huangapple
  • 本文由 发表于 2023年2月18日 10:38:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75490846.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定