Nearest allowed odds function

Discuss anything related to using the program (eg. triggered betting tactics)

Moderator: 2020vision

Nearest allowed odds function

Postby andak fedal » Thu Oct 17, 2013 3:10 pm

I'm far from the world's greatest coder and don't know VBA but was quite proud of myself for working out how to convert a number to the nearest allowed betfair odds. e.g. pass in 3.73 and it will return 3.75.

Here's the code in case anyone finds this useful in future:



Code: Select all
Function convertToOdds(ByVal odds As Currency) As Currency
by = 1
Select Case odds
Case 0 To 1#
odds = 1.01
Case 1.01 To 1.99
by = 1
Case 2# To 2.99
by = 2
Case 3# To 3.99
by = 5
Case 4 To 5.99
by = 10
Case 5.99 To 9.99
by = 20
Case 10# To 19.99
by = 50
Case 20# To 29.99
by = 100
Case 30# To 49.99
by = 200
Case 50# To 99.99
by = 500
Case 100# To 999.99
by = 1000
Case 1000# To 99999999
odds = 1000
End Select

odds = (((Round((100 * odds), 0)) - (((Round((100 * odds), 0)) Mod by))) / 100)

convertToOdds = odds

End Function
andak fedal
 
Posts: 105
Joined: Wed Apr 22, 2009 7:39 pm

Postby negapo » Thu Oct 17, 2013 5:45 pm

Very nice,
It has some issues though, try for instance 3.991

Don't know if this does it:

Code: Select all
Public Function ConvertToOdds(ByVal Odds As Double) As Double
Dim By As Double
    Select Case Odds
        Case Is <= 1: ConvertToOdds = 1.01: Exit Function
        Case Is < 2: By = 0.01
        Case Is < 3: By = 0.02
        Case Is < 4: By = 0.05
        Case Is < 6: By = 0.1
        Case Is < 10: By = 0.2
        Case Is < 20: By = 0.5
        Case Is < 30: By = 1
        Case Is < 50: By = 2
        Case Is < 100: By = 5
        Case Is < 1000: By = 10
        Case Else: ConvertToOdds = 1000: Exit Function
    End Select
    ConvertToOdds = (Int(Odds / By) + 1) * By
End Function


Thanks for sharing,
negapo
 
Posts: 179
Joined: Thu Mar 19, 2009 1:17 pm
Location: Porto, Portugal

Postby negapo » Thu Oct 17, 2013 5:49 pm

Just to add some details

Int returns the integer part of the number so it's equivalent to Round(Number, 0).
The problem with your function was that the intervals you have set didn't catch all the values so i used the < and > signs.
The Select case formula has short circuit meaning that when a condition it's true it stops and exits, it doesn't evaluate the other cases, this way we include all the values up to that interval point.

Hope it helps
negapo
 
Posts: 179
Joined: Thu Mar 19, 2009 1:17 pm
Location: Porto, Portugal

Postby andak fedal » Thu Oct 17, 2013 5:59 pm

Thanks negapo. Yeh I had been rounding to 2 d.p. before calling it but many thanks for improving it, fixing the issue and making it a much tidier solution.

:)
andak fedal
 
Posts: 105
Joined: Wed Apr 22, 2009 7:39 pm

Postby austingrd » Sun Oct 20, 2013 7:09 pm

Nice work Andak. The code looks good. I might have to try it out too.
Mistakes are learning tools. Image
austingrd
 
Posts: 56
Joined: Sun Sep 15, 2013 7:22 pm

Postby alrodopial » Sun Oct 20, 2013 8:40 pm

Get closest valid odds, if odds are the half between two valid odds it rounds down to closest valid odds

Code: Select all
Public Function getClosestOdds(ByVal Odds As Currency) As Currency
    Dim oddsInc As Currency
    Select Case Odds
        Case Is <= 1: getClosestOdds = 1.01: Exit Function
        Case Is < 2: oddsInc= 0.01
        Case Is < 3: oddsInc= 0.02
        Case Is < 4: oddsInc= 0.05
        Case Is < 6: oddsInc= 0.1
        Case Is < 10: oddsInc= 0.2
        Case Is < 20: oddsInc= 0.5
        Case Is < 30: oddsInc= 1
        Case Is < 50: oddsInc= 2
        Case Is < 100: oddsInc= 5
        Case Is < 1000: oddsInc= 10
        Case Else: getClosestOdds = 1000: Exit Function
    End Select
    If odds - Int(odds / oddsInc) * oddsInc > oddsInc / 2 Then
        getClosestOdds = Int(odds / oddsInc) * oddsInc + oddsInc
    Else
        getClosestOdds = Int(odds / oddsInc) * oddsInc
    End If
End Function
alrodopial
 
Posts: 1384
Joined: Wed Dec 06, 2006 9:59 pm

Postby JodyaMelendez » Tue Feb 04, 2014 8:36 am

Thanks alrodopial
JodyaMelendez
 
Posts: 1
Joined: Mon Feb 03, 2014 11:44 pm


Return to Discussion

Who is online

Users browsing this forum: No registered users and 57 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.