bet 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 253843bce1b84ca7f1dd411f69604bb009a044ff
4
- data.tar.gz: f1c14ea51af572cd7d2ecc17ebed818dba27c0c0
3
+ metadata.gz: fb93dabb53df5ca72be4e860b158e4b4426f7a54
4
+ data.tar.gz: 8118c8c5c2aa862a042d733674cb09e7fcb8d84e
5
5
  SHA512:
6
- metadata.gz: 0e1decc9d39a829bb2c5be349c133985e6c117ee52ba846118666f90be2ea431c35574973c3a5c4c6993be842d284f32a5dfb834b680d8e87a396516cdc20b18
7
- data.tar.gz: f3fec497e66ba3612ea3206da252dda005ac1333cd5af5b18798487fe9d3cfe21f31de0656fd1f0c38d367d9d1e3d7d5a28570469dcdc5c7480beee1619cb64e
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 the good folks of github and beyond:
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
- # of price and win/price/loss representation, here's array format:
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'))[:returns].to_f
52
- # => 1.2
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
- # the symbolic format for the win/place/loss result
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. Add dutching and shit like that
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?(Hash)
47
- prices.select{ |_,v| win_place_lose?(v) == :win }.keys
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
@@ -28,15 +28,8 @@ module Bet
28
28
  stake * price
29
29
  end
30
30
 
31
- def parse_prices(opts_or_prices)
32
- case opts_or_prices
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)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Bet
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
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.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-21 00:00:00.000000000 Z
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: