bet 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +27 -10
- data/lib/bet/bet_calculations/combinatorial.rb +2 -2
- data/lib/bet/calc.rb +2 -9
- data/lib/bet/staking.rb +26 -0
- data/lib/bet/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb93dabb53df5ca72be4e860b158e4b4426f7a54
|
4
|
+
data.tar.gz: 8118c8c5c2aa862a042d733674cb09e7fcb8d84e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 744b5a87d467ddbdb846a94945deb33b73fa0f90c2fc8c14ac0f9ed5d9d71f5aedfea7464c299917ce9157ccc6c9c96c9f452699afd25f76906f828eb90701bc
|
7
|
+
data.tar.gz: acc75c8bd2230b9fdcf53ed9a43862be57b535acfad047d1c913db2b4f97f514917f16fab1de063c493fe7802a3d2cbd5a718eff56ef551fea95aecc8cd7215d
|
data/README.md
CHANGED
@@ -38,24 +38,24 @@ Bet::Calc.block_with_singles # 9 selections (511 bets)
|
|
38
38
|
Bet::Calc.full_cover(prices, min_size: 1) # 1 is default, option can be omitted
|
39
39
|
```
|
40
40
|
|
41
|
-
Some examples for
|
41
|
+
Some examples of bet calculations for you good folks:
|
42
42
|
|
43
43
|
```ruby
|
44
|
-
# you can provide an array of winning prices, or a results hash
|
45
|
-
#
|
44
|
+
# you can provide an array of winning prices, or a results hash of
|
45
|
+
# price and win/price/loss representation, here's array format:
|
46
46
|
Bet::Calc.single(1.2) # or .single([1.2])
|
47
47
|
# => {:returns=>1.2, :profit=>0.19999999999999996, :outlay=>1}
|
48
48
|
# you'll notice the float imprecision, if you want accurate floating
|
49
49
|
# point calculations use BigDecimal:
|
50
50
|
require 'bigdecimal'
|
51
|
-
Bet::Calc.single(BigDecimal.new('1.2'))[:
|
52
|
-
# =>
|
51
|
+
Bet::Calc.single(BigDecimal.new('1.2'))[:profit].to_f
|
52
|
+
# => 0.2
|
53
53
|
|
54
54
|
Bet::Calc.double([1.2, 5.3])
|
55
55
|
# => {:returns=>6.359999999999999, :profit=>5.359999999999999, :outlay=>1}
|
56
56
|
|
57
|
-
# etc! here's the results hash format. you can use numerical or
|
58
|
-
#
|
57
|
+
# etc! here's the results hash format. you can use numerical or the
|
58
|
+
# symbolic format for the win/place/loss result
|
59
59
|
{ -1 => :loss, 0 => :place, 1 => :win }
|
60
60
|
|
61
61
|
# format is price => result
|
@@ -68,12 +68,29 @@ Bet::Calc.yankee({ 2.3 => :win, 1.2 => :place, 4.5 => :loss, 11.0 => :win }, sta
|
|
68
68
|
# => {:returns=>11.385, :profit=>6.435, :outlay=>4.95}
|
69
69
|
```
|
70
70
|
|
71
|
+
We can also calculate the stakes for more advanced bets:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# dutching is pretty fun, if you don't know what it is go look it up
|
75
|
+
# but this is how you calculate your stakes:
|
76
|
+
Bet::Staking.dutch([4.8, 5.3, 12], 100)
|
77
|
+
# => {
|
78
|
+
# :stakes=>[43.37, 39.28, 17.35],
|
79
|
+
# :min_profit=>108.17599999999999,
|
80
|
+
# :total_stake=>100.0,
|
81
|
+
# :profitable=>true
|
82
|
+
# }
|
83
|
+
|
84
|
+
# The first argument is the prices of the runners, the second is the
|
85
|
+
# target total stake. The `stakes` in the resulting hash are the
|
86
|
+
# stakes for each of the inputted prices (respectively). The rest
|
87
|
+
# should be fairly self explanatory.
|
88
|
+
```
|
89
|
+
|
71
90
|
## Todo
|
72
91
|
|
73
92
|
1. Implement each way bets properly
|
74
|
-
2.
|
75
|
-
3. Maybe implement support for other price formats (fractional & 'murican)
|
76
|
-
4. Write tests
|
93
|
+
2. Write tests
|
77
94
|
|
78
95
|
## Contributing
|
79
96
|
|
@@ -43,8 +43,8 @@ module Bet
|
|
43
43
|
(1..prices.length).to_a.combination(n).to_a.length
|
44
44
|
end.reduce(:+)
|
45
45
|
|
46
|
-
winning_prices = if prices.is_a?(
|
47
|
-
prices.select{ |_,v| win_place_lose?(v) == :win }.
|
46
|
+
winning_prices = if prices.first.is_a?(Array)
|
47
|
+
prices.select{ |_,v| win_place_lose?(v) == :win }.map(&:first)
|
48
48
|
else
|
49
49
|
prices
|
50
50
|
end
|
data/lib/bet/calc.rb
CHANGED
@@ -28,15 +28,8 @@ module Bet
|
|
28
28
|
stake * price
|
29
29
|
end
|
30
30
|
|
31
|
-
def parse_prices(
|
32
|
-
|
33
|
-
when Hash
|
34
|
-
opts_or_prices[:prices] ? extract_prices(opts_or_prices[:prices]) : opts_or_prices
|
35
|
-
when Numeric
|
36
|
-
[opts_or_prices]
|
37
|
-
else
|
38
|
-
opts_or_prices
|
39
|
-
end
|
31
|
+
def parse_prices(prices)
|
32
|
+
Array(prices)
|
40
33
|
end
|
41
34
|
|
42
35
|
def parse_opts(opts_or_prices)
|
data/lib/bet/staking.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Bet
|
2
|
+
module Staking
|
3
|
+
class << self
|
4
|
+
def dutch(prices, risk = 1)
|
5
|
+
denom = prices.combination(2).map{ |c| c[0] * c[1] }.reduce(:+)
|
6
|
+
|
7
|
+
stakes = prices.map.with_index do |p, i|
|
8
|
+
(prices.dup.tap{ |a| a.delete_at(i) }.reduce(:*) * risk)
|
9
|
+
.fdiv(denom)
|
10
|
+
.round(2)
|
11
|
+
end
|
12
|
+
|
13
|
+
profits = prices.zip(stakes).map{ |c| c.reduce(:*) }
|
14
|
+
total_stake = stakes.reduce(:+)
|
15
|
+
min_profit = profits.min - total_stake
|
16
|
+
|
17
|
+
{
|
18
|
+
stakes: stakes,
|
19
|
+
min_profit: min_profit,
|
20
|
+
total_stake: total_stake,
|
21
|
+
profitable: min_profit > 0
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/bet/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Campbell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/bet/bet_calculations/convenience.rb
|
57
57
|
- lib/bet/bet_calculations/core.rb
|
58
58
|
- lib/bet/calc.rb
|
59
|
+
- lib/bet/staking.rb
|
59
60
|
- lib/bet/version.rb
|
60
61
|
homepage: https://github.com/mikecmpbll/bet
|
61
62
|
licenses:
|