尝试计算观察的期望值

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

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

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

The following is the calculation

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

The values in the calculation above correspond with the following variables

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

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

-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

structure(list(id = c("073c154f3c8586868a3ba21522161a70", 
"073c154f3c8586868a3ba21522161a70", 
"073c154f3c8586868a3ba21522161a70", "073c154f3c8586868a3ba21522161a70", 
"073c154f3c8586868a3ba21522161a70", "073c154f3c8586868a3ba21522161a70"
), book = c("Bovada", "Pinnacle", "MyBookie.ag", "MyBookie.ag", 
"Pinnacle", "Bovada"), home = c("Western Michigan Broncos", "Western 
Michigan Broncos", 
"Western Michigan Broncos", "Western Michigan Broncos", "Western 
Michigan Broncos", 
"Western Michigan Broncos"), away = c("Ball State Cardinals", 
"Ball State Cardinals", "Ball State Cardinals", "Ball State Cardinals", 
"Ball State Cardinals", "Ball State Cardinals"), team = c("Western 
Michigan Broncos", 
"Ball State Cardinals", "Western Michigan Broncos", "Ball State 
Cardinals", 
"Western Michigan Broncos", "Ball State Cardinals"), price = c(-185, 
-143, -142, 100, 108, 140), bep = c(0.64912, 0.58848, 0.58678, 
0.5, 0.48077, 0.41667), no_vig = c(-155.78947, -122.40329, -117.35537, 
117.35537, 122.40329, 155.78947), no_vig_bep = c(0.60905, 0.55037, 
0.53992, 0.46008, 0.44963, 0.39095), win = c(54.05, 69.93, 70.42, 
100, 108, 140), EV_1 = c(-15.2155015, -6.47562589999999, 
-6.20594459999999, 
-10.074, -6.47696000000001, 7.91119999999999)), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -6L), groups = 
structure(list(
book = c("Bovada", "MyBookie.ag", "Pinnacle"), .rows = structure(list(
    c(1L, 6L), 3:4, c(2L, 5L)), ptype = integer(0), class = 
c("vctrs_list_of", 
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -3L), .drop = TRUE))

答案1

得分: 1

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

library(purrr)
no_vig_pin_list <- df | 
  ungroup() | 
  split(df$id) |  
  map(~.x | filter(book == "Pinnacle") | pull(no_vig_bep))

df | 
  ungroup() | 
  group_split(id) | 
  purrr::map2_dfr(no_vig_pin_list, ~  .x | 
               group_by(book) | 
  mutate(EV_1 = ifelse(row_number() == 1, 
                       (.y[1] * win)- ((1-.y[1])*100),
                       (.y[2] * win)- ((1-.y[2])*100)))) | 
  select(EV_1)

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

library(dplyr)

no_vig_pin <- df | 
  filter(book == "Pinnacle") | 
  pull(no_vig_bep)

df | 
  group_by(book) | 
  mutate(EV_1 = ifelse(row_number() == 1, 
                       (no_vig_pin[1] * win)- ((1-no_vig_pin[1])*100),
                       (no_vig_pin[2] * win)- ((1-no_vig_pin[2])*100))) | 
  select(EV_1)

输出

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

Edit1: Maybe purrr can help you here:

library(purrr)
no_vig_pin_list &lt;- df |&gt; 
  ungroup() |&gt; 
  split(df$id) |&gt;  
  map(~.x |&gt; filter(book == &quot;Pinnacle&quot;) |&gt; pull(no_vig_bep))

df |&gt; 
  ungroup() |&gt; 
  group_split(id) |&gt; 
  purrr::map2_dfr(no_vig_pin_list, ~  .x |&gt; 
               group_by(book) |&gt; 
  mutate(EV_1 = ifelse(row_number() == 1, 
                       (.y[1] * win)- ((1-.y[1])*100),
                       (.y[2] * win)- ((1-.y[2])*100)))) |&gt; 
  select(EV_1)

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

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

library(dplyr)

no_vig_pin &lt;- df |&gt; 
  filter(book == &quot;Pinnacle&quot;) |&gt; 
  pull(no_vig_bep)

df |&gt; 
  group_by(book) |&gt; 
  mutate(EV_1 = ifelse(row_number() == 1, 
                       (no_vig_pin[1] * win)- ((1-no_vig_pin[1])*100),
                       (no_vig_pin[2] * win)- ((1-no_vig_pin[2])*100))) |&gt; 
  select(EV_1)

Output:

# A tibble: 6 &#215; 2
# Groups:   book [3]
  book      EV_1
  &lt;chr&gt;    &lt;dbl&gt;
1 BetUS    -4.48
2 BetUS    -2.58
3 Bovada   -4.48
4 Bovada   -2.58
5 Pinnacle -3.91
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:

确定