betting

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package betting provides functions to compute bet types and sizes in order to achieve a free bet or greenbook.

Example (A)

This example computes the bet type and size to be placed on the market in order to perform a "Green Book" operation.

package main

import (
	"fmt"

	"github.com/gustavooferreira/bfutils/betting"
)

func main() {
	selection := betting.Selection{
		Bets: []betting.Bet{
			{Type: betting.BetType_Back, Odd: 4, Amount: 5},
			{Type: betting.BetType_Lay, Odd: 3, Amount: 5},
			{Type: betting.BetType_Back, Odd: 3.5, Amount: 10},
			{Type: betting.BetType_Lay, Odd: 3.2, Amount: 10},
		},
		CurrentBackOdd: 2.4,
		CurrentLayOdd:  2.42,
	}

	bet, err := betting.GreenBookSelection(selection)
	if err != nil {
		panic(err)
	}

	fmt.Printf("In order to green book this selection, put a {%s} bet at {%.2f} for £%.2f.\n",
		bet.Type, bet.Odd, bet.Amount)

	fmt.Printf("P&L\n")
	fmt.Printf("---\n")
	fmt.Printf("If this selection wins:  £%.2f\n", bet.WinPL)
	fmt.Printf("If this selection loses: £%.2f\n", bet.LosePL)

}
Output:

In order to green book this selection, put a {Lay} bet at {2.42} for £3.31.
P&L
---
If this selection wins:  £3.31
If this selection loses: £3.31

Index

Examples

Constants

View Source
const (
	// BetType_Back represents a back bet.
	BetType_Back = iota + 1
	// BetType_Lay represents a lay bet.
	BetType_Lay
)

Variables

This section is empty.

Functions

func FreeBetDecimal

func FreeBetDecimal(oddBack float64, oddLay float64) float64

FreeBetDecimal returns the P&L multiplier factor. Example: back:4 lay:2 the multiplier factor is 2, which means if you back at odd 4 with £10 and lay at odd 2 with £10 you secure a free bet of 2 * £10 = £20

func FreeBetPL

func FreeBetPL(oddBack float64, oddLay float64, stake float64) float64

FreeBetPL returns the profit in case selection wins. Note that 'stake' is the backer's stake not the layer's liability

func GreenBookOpenBackAmount

func GreenBookOpenBackAmount(oddBack float64, stakeBack float64, oddLay float64) (float64, error)

GreenBookOpenBackAmount returns lay stake to greenbook.

func GreenBookOpenBackAmountByPerc

func GreenBookOpenBackAmountByPerc(oddBack float64, perc float64) (float64, error)

GreenBookOpenBackAmountByPerc returns oddLay for a given perc P&L. Note that when Backing, you cannot lose more than 100% of your stake therefore feeding perc with a number less or equal to -1 is an error! perc is a representation in decimal, meaning if you want to know at what LAY odd you should place a bet at in order to get 100% profit, then perc is == 1

func GreenBookOpenBackDecimal

func GreenBookOpenBackDecimal(oddBack float64, oddLay float64) (float64, error)

GreenBookOpenBackDecimal returns percentage of P&L.

func GreenBookOpenLayAmount

func GreenBookOpenLayAmount(oddLay float64, stakeLay float64, oddBack float64) (float64, error)

GreenBookOpenLayAmount returns back stake to greenbook.

func GreenBookOpenLayAmountByPerc

func GreenBookOpenLayAmountByPerc(oddLay float64, perc float64) (float64, error)

GreenBookOpenLayAmountByPerc returns oddBack for a given perc P&L. Note that when Laying, you cannot win more than 100% of your stake therefore feeding perc with a number greater or equal to 1 is an error!

func GreenBookOpenLayDecimal

func GreenBookOpenLayDecimal(oddLay float64, oddBack float64) (float64, error)

GreenBookOpenLayDecimal returns percentage of P&L.

func SelectionIsEdged

func SelectionIsEdged(bets []Bet) (bool, error)

SelectionIsEdged returns true if selection is already been edged or if there are no bets in this selection. This might not give an accurate result in the sense that the selection might not be edged perfectly, because it might not be possible to edge it "even" across all outcomes at the current odds.

Types

type AlreadyEdgedError

type AlreadyEdgedError struct {
}

AlreadyEdgedError is the error used in case a selection is already edged.

func (*AlreadyEdgedError) Error

func (e *AlreadyEdgedError) Error() string

type Bet

type Bet struct {
	// Bet type: Back or Lay.
	Type BetType
	// Odd in the market.
	Odd float64
	// Amount represents how much to bet or how much has been matched (backer's stake, or layer's payout)
	Amount float64
	// WinPL represents how much is the profit or loss in case this selection wins.
	// This value is meant to be treated as read-only.
	WinPL float64
	// LosePL represents how much is the profit or loss in case this selection loses.
	// This value is meant to be treated as read-only.
	LosePL float64
}

Bet represents a bet in the market.

func GreenBookSelection

func GreenBookSelection(selection Selection) (bet Bet, err error)

GreenBookSelection computes what bet to make in order to greenbook a selection.

type BetType

type BetType uint

BetType represents the type of bet to make in the market.

func (BetType) String

func (bt BetType) String() string

String returns the string representation of BetType.

type LadderStep

type LadderStep struct {
	// Odd in the market.
	Odd float64
	// Potential profit or loss in this selection in case of a greenbook operation.
	GreenBookPL float64
	// Volume matched by bets placed.
	VolMatched float64
}

LadderStep represents a trading ladder.

func GreenBookAtAllOdds

func GreenBookAtAllOdds(bets []Bet) ([]LadderStep, error)

GreenBookAtAllOdds returns the ladder with P&L and volumed matched by bets.

type Selection

type Selection struct {
	// Bets matched in this specific selection.
	Bets []Bet
	// Current back odd being offered.
	CurrentBackOdd float64
	// Current lay odd being offered.
	CurrentLayOdd float64
}

Selection represents a selection in a market.

Jump to

Keyboard shortcuts

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