Class: Oddsmaker::Odd::ImpliedProbability

Inherits:
Base
  • Object
show all
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

#id, #value

Instance Method Summary collapse

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.

Parameters:

Returns:

  • (-1, 0, 1)


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.

Parameters:

Returns:

  • (Boolean)


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

#americanAmerican

Convert to American odds, returning a new object.

Returns:



72
73
74
# File 'lib/oddsmaker/odd/implied_probability.rb', line 72

def american
  @american ||= American.new(calculate_american, id)
end

#decimalDecimal

Convert to decimal odds, returning a new object.

Returns:



79
80
81
# File 'lib/oddsmaker/odd/implied_probability.rb', line 79

def decimal
  @decimal ||= Decimal.new(calculate_decimal, id)
end

#fractionalFractional

Convert to fractional odds, returning a new object.

Returns:



86
87
88
# File 'lib/oddsmaker/odd/implied_probability.rb', line 86

def fractional
  @fractional ||= Fractional.new(calculate_fractional, id)
end

#implied_probabilityself

Returns self. This creates a consistent API for all odds.

Returns:

  • (self)


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.

Parameters:

  • v (Integer)

    Overround percentage (as whole number)

Returns:



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.

Parameters:

  • n (Integer) (defaults to: 2)

    Number of decimal places for rounding.



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.

Parameters:

  • n (Integer) (defaults to: nil)

    Number of decimal places for rounding.



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.

Returns:



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