odds

package module
v0.0.0-...-16d28b0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 2 Imported by: 0

README

go-odds

go-odds

Go Reference Go Report Card

go-odds is a simple and fast utility library for making betting odds conversions between formats and calculating probabilities in Go.

Go gopher illustration created by Egon Elbre, originally created by Renee French.

Installation

Download the library using go get:

go get github.com/jsgm/go-odds

Import in your current repository:

import (
    odds "github.com/jsgm/go-odds"
)

Converting odds between formats

Data types

Each odd type will return a different data type, depending on your needs.

Odd format Function Type
Moneyline .Moneyline() int16
Indonesian .Indonesian() float64
Malay .Malay() float64
Decimal .Decimal() float64
HongKong .HongKong() float64
Implied Probability .Probability() float64
Odds conversions
o := odds.NewOdd(odds.Decimal, 1.64)

// Convert to implied probability
float := o.Probability()

Overround and Payouts

home, _ := odds.NewOdd(odds.Implied, 65.00) // Home odds from Implied Probability
draw, _ := odds.NewOdd(odds.Decimal, 4.00)
away, _ := odds.NewOdd(odds.Decimal, 7.00)

fmt.Println("Overround ", odds.GetOverround([]odds.Odd{home, draw, away})) // 4.285714285714278
fmt.Println("Payout ", odds.GetPayout([]odds.Odd{home, draw, away})) // 95.71428571428572

Arbitrage Calculation

todo

Kelly Criterion

Kelly Criterion is simply strategy that helps calculating the proper stake that you should wager on a particular event. This doesn't just applies to betting but also for investing and calculating risks.

Kelly Criterion Formula
  • b is the multiple of the stake.
  • p is the probability of winning. 70% chances of winning should be 0.7.
  • q is the probability of lossing. i.e. 100% - p = 30. The value would be 0.3.
  • K% is the suggested percentage of the bankroll for the event.

Simple Parlay Bets

o1, _ := odds.NewOdd(odds.Decimal, 1.25)
o2, _ := odds.NewOdd(odds.Implied, 50.7)
o3, _ := odds.NewOdd(odds.Decimal, 4.5)

multi := []odds.Odd{o1, o2, o3} 
stake := 10.0

p := odds.NewParlay(multi, stake)

p.Profit() // 67.22386587771203
p.Payout() // 77.22386587771203
p.SellectionCount() // 3
p.Probability() // 12.949364663814572 (%)

Round Robin

todo

Teaser

todo

Documentation

Index

Constants

View Source
const (
	Unknown    = -1
	Decimal    = 0 // check
	Fractional = 1
	Moneyline  = 2 // check
	Implied    = 3 // check
	Malay      = 4
	Indonesian = 5
	HongKong   = 6 // check

	// Rounding float types
	Round = 0
	Floor = 1
	Ceil  = 2
)

Variables

This section is empty.

Functions

func GetOverround

func GetOverround(odds []Odd) float64

Get the overround as float64 from an array of odds.

func GetPayout

func GetPayout(odds []Odd) float64

Get the payout as float64 from an array of odds.

Types

type Odd

type Odd struct {
	Type         int
	DecimalValue float64

	FloatPrecision uint8
	Value          interface{}
}

func NewOdd

func NewOdd(oType int, oVal interface{}) (Odd, error)

func (*Odd) Decimal

func (odd *Odd) Decimal() float64

Returns the decimal value as float64 from Odd{}.

func (*Odd) HongKong

func (odd *Odd) HongKong() float64

Returns HongKong odds as float64 from Odd{}.

func (*Odd) Indonesian

func (odd *Odd) Indonesian() float64

Returns Indonesian odds as float64 from Odd{}.

func (*Odd) KellyCriterion

func (o *Odd) KellyCriterion() (float64, error)

func (*Odd) Malay

func (odd *Odd) Malay() float64

Returns Malay odds as float64 from Odd{}.

func (*Odd) Moneyline

func (odd *Odd) Moneyline() int16

Returns the Moneyline value as int16 from Odd{}.

func (*Odd) Precision

func (odd *Odd) Precision(newPrecision uint8) Odd

func (*Odd) Probability

func (odd *Odd) Probability() float64

Returns the Implied Probability as float64 from Odd{}.

func (*Odd) Valid

func (odd *Odd) Valid() bool

type Parlay

type Parlay struct {
	Odds  []Odd
	Stake float64
}

func NewParlay

func NewParlay(odds []Odd, stake float64) Parlay

Creates a new parlay bet.

func (*Parlay) Payout

func (p *Parlay) Payout() float64

Total amount of money received for the parlay bet.

func (*Parlay) Probability

func (p *Parlay) Probability() float64

Combined probability of the parlay bet.

func (*Parlay) Profit

func (p *Parlay) Profit() float64

Will return a positive float64 that equals the benefits.

func (*Parlay) SellectionCount

func (p *Parlay) SellectionCount() int

Return the number of bets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL