class Oddsmaker::Odd::ImpliedProbability
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.
Public Class Methods
# 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
Public Instance Methods
Compare two odds against each other.
@param other [ImpliedProbability] @return [-1,0,1]
# File lib/oddsmaker/odd/implied_probability.rb, line 58 def <=>(other) value <=> other.value end
Check two odds for equality.
@param other [ImpliedProbability] @return [Boolean]
# 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
Convert to American
odds, returning a new object.
@return [American]
# File lib/oddsmaker/odd/implied_probability.rb, line 72 def american @american ||= American.new(calculate_american, id) end
Convert to decimal odds, returning a new object.
@return [Decimal]
# File lib/oddsmaker/odd/implied_probability.rb, line 79 def decimal @decimal ||= Decimal.new(calculate_decimal, id) end
Convert to fractional odds, returning a new object.
@return [Fractional]
# File lib/oddsmaker/odd/implied_probability.rb, line 86 def fractional @fractional ||= Fractional.new(calculate_fractional, id) end
Returns self. This creates a consistent API for all odds.
@return [self]
# File lib/oddsmaker/odd/implied_probability.rb, line 65 def implied_probability self end
Calculates a new odd, with the given overround percentage.
@param v [Integer] Overround percentage (as whole number) @return [ImpliedProbability]
# File lib/oddsmaker/odd/implied_probability.rb, line 23 def overround!(v) self.class.new(@value * ((100 + v)/100.rationalize), id) end
Round decimal value.
@param n [Integer] Number of decimal places for rounding.
# File lib/oddsmaker/odd/implied_probability.rb, line 38 def round(n = 2) @value.round(n) end
Convert probability to percent. Optionally round the resulting decimal.
@param n [Integer] Number of decimal places for rounding.
# File lib/oddsmaker/odd/implied_probability.rb, line 31 def to_percent(n = nil) n ? (@value * 100).round(n) : @value * 100 end
Calculates a new odd, removing the vig.
@return [ImpliedProbability]
# File lib/oddsmaker/odd/implied_probability.rb, line 15 def without_vig(total_probability) self.class.new(@value / total_probability, id) end
Private Instance Methods
Calculate American
odds value.
@return [Integer, Float]
# File lib/oddsmaker/odd/implied_probability.rb, line 100 def calculate_american value = @value.rationalize if value >= 0.5 - ( value / (1 - value)) * 100 else ((1 - value) / value ) * 100 end end
Calculate decimal odds value.
@return [Float]
# File lib/oddsmaker/odd/implied_probability.rb, line 112 def calculate_decimal 1.0 / @value end
Calculate fractional odds value.
@return [Rational]
# File lib/oddsmaker/odd/implied_probability.rb, line 119 def calculate_fractional (1.0 / @value - 1).rationalize end
Allows for implied probability to create a vigged/unvigged odd and convert it back to source format.
# File lib/oddsmaker/odd/implied_probability.rb, line 93 def type :implied_probability end