Class: Oddsmaker::Odd::ImpliedProbability
- Defined in:
- lib/oddsmaker/odd/implied_probability.rb
Overview
Implied probability is the probability of an event, based on the odds for that event. Implied probability is what translates between various types of odds.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Compare two odds against each other.
-
#==(other) ⇒ Boolean
Check two odds for equality.
-
#american ⇒ American
Convert to American odds, returning a new object.
-
#decimal ⇒ Decimal
Convert to decimal odds, returning a new object.
-
#fractional ⇒ Fractional
Convert to fractional odds, returning a new object.
-
#implied_probability ⇒ self
Returns self.
-
#initialize(value, id = nil) ⇒ ImpliedProbability
constructor
A new instance of ImpliedProbability.
-
#overround!(v) ⇒ ImpliedProbability
Calculates a new odd, with the given overround percentage.
-
#round(n = 2) ⇒ Object
Round decimal value.
-
#to_percent(n = nil) ⇒ Object
Convert probability to percent.
-
#without_vig(total_probability) ⇒ ImpliedProbability
Calculates a new odd, removing the vig.
Methods inherited from Base
#multiplier, #profit, #to_h, #to_json, #to_s, #wager
Constructor Details
#initialize(value, id = nil) ⇒ ImpliedProbability
Returns a new instance of ImpliedProbability.
7 8 9 10 |
# File 'lib/oddsmaker/odd/implied_probability.rb', line 7 def initialize(value, id = nil) @id = id || value @value = value >= 1 ? value.fdiv(100) : value end |
Instance Method Details
#<=>(other) ⇒ -1, ...
Compare two odds against each other.
58 59 60 |
# File 'lib/oddsmaker/odd/implied_probability.rb', line 58 def <=>(other) value <=> other.value end |
#==(other) ⇒ Boolean
Check two odds for equality.
46 47 48 49 50 51 52 |
# File 'lib/oddsmaker/odd/implied_probability.rb', line 46 def ==(other) if other.is_a?(self.class) @value == other.value else @value == other.implied_probability.value end end |
#american ⇒ American
Convert to American odds, returning a new object.
72 73 74 |
# File 'lib/oddsmaker/odd/implied_probability.rb', line 72 def american @american ||= American.new(calculate_american, id) end |
#decimal ⇒ Decimal
Convert to decimal odds, returning a new object.
79 80 81 |
# File 'lib/oddsmaker/odd/implied_probability.rb', line 79 def decimal @decimal ||= Decimal.new(calculate_decimal, id) end |
#fractional ⇒ Fractional
Convert to fractional odds, returning a new object.
86 87 88 |
# File 'lib/oddsmaker/odd/implied_probability.rb', line 86 def fractional @fractional ||= Fractional.new(calculate_fractional, id) end |
#implied_probability ⇒ self
Returns self. This creates a consistent API for all odds.
65 66 67 |
# File 'lib/oddsmaker/odd/implied_probability.rb', line 65 def implied_probability self end |
#overround!(v) ⇒ ImpliedProbability
Calculates a new odd, with the given overround percentage.
23 24 25 |
# File 'lib/oddsmaker/odd/implied_probability.rb', line 23 def overround!(v) self.class.new(@value * ((100 + v)/100.rationalize), id) end |
#round(n = 2) ⇒ Object
Round decimal value.
38 39 40 |
# File 'lib/oddsmaker/odd/implied_probability.rb', line 38 def round(n = 2) @value.round(n) end |
#to_percent(n = nil) ⇒ Object
Convert probability to percent. Optionally round the resulting decimal.
31 32 33 |
# File 'lib/oddsmaker/odd/implied_probability.rb', line 31 def to_percent(n = nil) n ? (@value * 100).round(n) : @value * 100 end |
#without_vig(total_probability) ⇒ ImpliedProbability
Calculates a new odd, removing the vig.
15 16 17 |
# File 'lib/oddsmaker/odd/implied_probability.rb', line 15 def without_vig(total_probability) self.class.new(@value / total_probability, id) end |