1

我创建了这个函数来确定在特定篮球比赛中投注命题的任何一方是否会产生多少三分球是否有利可图。我在代码前面预测了总共有多少个三指针pjTotal3s和标准差pjGame3STD。threes_over是投注网站给我的数字,我试图找出三分球的总数是大于还是小于该数字在这种情况下,它是 14.5。

threes_over = 14.5

def overunder(n):
over_count = 0
under_count = 0
push_count = 0
overodds = 0
underodds = 0
for i in range(n):
    if round(np.random.normal(pjTotal3s,pjGame3STD)) > threes_over:
        over_count = over_count + 1
    if round(np.random.normal(pjTotal3s,pjGame3STD)) < threes_over:
        under_count = under_count +1
    if round(np.random.normal(pjTotal3s,pjGame3STD)) == threes_over:
        push_count = push_count + 1
return over_count, under_count, push_count   

然后我模拟它 100,000 overunder(100000)次,它告诉我三个指针的数量将超过、低于或等于给定数字的次数。这很好用,但我仍然需要做更多的工作才能确定这是否是一个有利可图的赌注。

假设这是输出 (57550, 42646, 0),我必须像这样手动输入它,并做更多的事情来确定下注的任何一方是否值得。

over_count = 57550
under_count = 42646
over = 1/(over_count / (over_count + under_count))
under = 1/ (under_count / (over_count + under_count))
over_odds_given = 1.77
under_odds_given = 2.05
overedge = 1/over * over_odds_given - 1
underedge = 1/under * under_odds_given - 1
print overedge, underedge

如何将第二组计算组合到与第一组相同的函数中。我想避免手动输入第一个函数的结果,以节省时间并避免输入错误的数字。

4

1 回答 1

0

如果您真的希望在与第一个函数相同的函数中使用第二位代码,则可以将除设置 over_count 和 under_count 的部分之外的所有代码都粘贴到函数中...

def overunder(n):
  over_count = 0
  under_count = 0
  push_count = 0
  overodds = 0
  underodds = 0
  for i in range(n):
    if round(np.random.normal(pjTotal3s,pjGame3STD)) > threes_over:
      over_count = over_count + 1
    if round(np.random.normal(pjTotal3s,pjGame3STD)) < threes_over:
      under_count = under_count +1
    if round(np.random.normal(pjTotal3s,pjGame3STD)) == threes_over:
      push_count = push_count + 1

  over = 1/(over_count / float(over_count + under_count))
  under = 1/ (under_count / float(over_count + under_count))
  over_odds_given = 1.77
  under_odds_given = 2.05
  overedge = 1/over * over_odds_given - 1
  underedge = 1/under * under_odds_given - 1

  print overedge, underedge

  return over_count, under_count, push_count   

或者,可能更好,您可以将第二段代码(overedge,underedge)放入一个单独的函数中,并将 overunder 的结果传递给它:

def edges(over_count, under_count, push_count):
  over = 1/(over_count / float(over_count + under_count))
  under = 1/ (under_count / float(over_count + under_count))
  over_odds_given = 1.77
  under_odds_given = 2.05
  overedge = 1/over * over_odds_given - 1
  underedge = 1/under * under_odds_given - 1
  print overedge, underedge

然后用 overunder 的结果调用它:

c = overunder(100000)
edges(c[0],c[1],c[2])
于 2013-05-02T02:38:02.763 回答