-
Notifications
You must be signed in to change notification settings - Fork 0
/
BetSizingFormulas.R
55 lines (45 loc) · 1.55 KB
/
BetSizingFormulas.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
result = function(predictions, x, y) {
res = list()
Npred = length(predictions)
bets = list()
bets$result = rep(0, Npred)
bets$br = rep(1, Npred + 1)
bets$bet = rep(0, Npred)
results = list()
results$Nrbets = 0
minEdge = 0.03
maxBrWage = 0.8
for(i in 1 : Npred) {
winexpectation = predictions[i]
lossexpectation = 1 - predictions[i]
if(!is.na(x$PSL[i]) & !is.na(x$PSW[i])){
if(winexpectation * x$PSW[i] - 1 > minEdge) {
results$Nrbets = results$Nrbets + 1
bets$bet[i] = maxBrWage * bets$br[i] * (winexpectation * x$PSW[i] - 1) / (x$PSW[i] - 1)
#constant BR bet
#bets$bet[i] = (winexpectation * x$PSW[i] - 1) / (x$PSW[i] - 1)
bets$bet[i] = 1
if(y[i] == 1 ) {
bets$result[i] = bets$bet[i] * (x$PSW[i] - 1)
} else {
bets$result[i] = -bets$bet[i]
}
} else if(lossexpectation * x$PSL[i] - 1 > minEdge) {
results$Nrbets = results$Nrbets + 1
bets$bet[i] = maxBrWage * bets$br[i] * (lossexpectation * x$PSL[i] - 1) / (x$PSL[i] - 1)
#constant BR bet
#bets$bet[i] = (lossexpectation * x$PSL[i] - 1) / (x$PSL[i] - 1)
bets$bet[i] = 1
if(y[i] == 0){
bets$result[i] = bets$bet[i] * (x$PSL[i] - 1)
} else {
bets$result[i] = -bets$bet[i]
}
}
}
bets$br[i + 1] = bets$br[i] + bets$result[i]
}
results$Br = bets$br[Npred + 1]
results$ROI = sum(bets$result) / sum(bets$bet)
combined = list("results" = results, "bets" = bets)
}