1. #1
    Ganchrow
    Nolite te bastardes carborundorum.
    Ganchrow's Avatar Become A Pro!
    Join Date: 08-28-05
    Posts: 5,011
    Betpoints: 1088

    New VBA Sports Betting Functions Excel Demo

    A few people have have asked if and if I still planned to post an update to http://www.sportsbookreview.com/forum/handicappe...tml#post256487.

    The short answer is yes, but only after I put together some better documentation.

    In the meantime, however, interested parties can download the attached demo spreadsheet. I've recoded many of the functions in C++ , so if want to check it out you'll also need the matrix.dll library included in the .zip file. Copy the DLL to your \Windows\System32\ directory and you'll be ready to go.

    Feel free to copy the VBA functions and wrapper code into your own spreadsheets. You can also call the DLL functions directly from other programming languages. Not all the included functions are demoed and most won't be of use to 99%+ of posters. Many of the functions I personally use all the time, others I virtually never use.

    The main reason I rewrote much of the was to speed up large matrix operations. Inversions are much faster than with the Excel built-in function (and without any size limits) as are calculations involving nested matrix operations (as would be the case, for example, with generalized regressions). I also coded an Eigenvalue/vector solver for symmetric matrices which should useful to anyone delving into Principal Component Analysis.

    Anyway, this comes with absolutely no warranties, ... , etc. etc. If anyone finds any of this useful -- great.
    Attached Files
    Points Awarded:

    MadTiger gave Ganchrow 1 SBR Point(s) for this post.


  2. #2
    PRC
    PRC's Avatar Become A Pro!
    Join Date: 10-22-09
    Posts: 576
    Betpoints: 49

    Incredible! Thanks ganch! Do you need Windows to run the DLL and/or your old .xlt template? And what are the chances you could add a tab that factors in the Matchbook commissions?

  3. #3
    Ganchrow
    Nolite te bastardes carborundorum.
    Ganchrow's Avatar Become A Pro!
    Join Date: 08-28-05
    Posts: 5,011
    Betpoints: 1088

    Quote Originally Posted by PRC View Post
    Incredible! Thanks ganch! Do you need Windows to run the DLL and/or your old .xlt template? And what are the chances you could add a tab that factors in the Matchbook commissions?
    Well it's specifically compiled as a Win32 DLL.

    There are a few Matchbook conversion functions not demoed.

    The VBA wrapper functions (found in the modSBGanch_Exchanges module) are:

    Code:
    Public Declare Function MB2US Lib "matrix.dll" Alias "g_MBUS2US" ( _
        ByVal dUSOdds As Double, _
        ByVal dCommission As Double _
    ) As Double
    
    Public Declare Function MB2DEC Lib "matrix.dll" Alias "g_MBDEC2DEC" ( _
        ByVal dDecimalOdds As Double, _
        ByVal dCommission As Double _
    ) As Double
    
    Public Declare Function MBUS2US Lib "matrix.dll" Alias "g_MBUS2US" ( _
        ByVal dUSOdds As Double, _
        ByVal dCommission As Double _
    ) As Double
    
    Public Declare Function MBDEC2DEC Lib "matrix.dll" Alias "g_MBDEC2DEC" ( _
        ByVal dDecimalOdds As Double, _
        ByVal dCommission As Double _
    ) As Double
    
    Public Declare Function MBUS2DEC Lib "matrix.dll" Alias "g_MBUS2DEC" ( _
        ByVal dUSOdds As Double, _
        ByVal dCommission As Double _
    ) As Double
    
    Public Declare Function MBDEC2US Lib "matrix.dll" Alias "g_MBDEC2US" ( _
        ByVal dDecimalOdds As Double, _
        ByVal dCommission As Double _
    ) As Double


    These provide the following functions.
    • MB2US(US Odds, Commission) -- US Odds input, returns Effective US Odds After Commission (alias: MBUS2US)
    • MB2DEC(Decimal Odds, Commission) -- Decimal Odds input, returns Effective Decimal Odds After Commission (alias: MBDEC2DEC)
    • MBUS2DEC(US Odds, Commission) -- US Odds input, returns Effective Decimal Odds After Commission
    • MBDEC2USDecimal Odds, Commission) -- Decimal Odds input, returns Effective US Odds After Commission

  4. #4
    lasker
    lasker's Avatar Become A Pro!
    Join Date: 01-27-10
    Posts: 1,683
    Betpoints: 114

    ---------->

  5. #5
    durito
    escarabajo negro
    durito's Avatar Become A Pro!
    Join Date: 07-03-06
    Posts: 13,173
    Betpoints: 438

    Gracias.

  6. #6
    rise
    rise's Avatar Become A Pro!
    Join Date: 03-01-09
    Posts: 372
    Betpoints: 30

    great stuff thanks

  7. #7
    MadTiger
    Wait 'til next year!
    MadTiger's Avatar Become A Pro!
    Join Date: 04-19-09
    Posts: 2,724
    Betpoints: 47

    Pointed.

  8. #8
    benjy
    Untitled
    benjy's Avatar Become A Pro!
    Join Date: 02-19-09
    Posts: 2,158
    Betpoints: 2882

    Cool! Thanks!

  9. #9
    Premierr23
    Premierr23's Avatar Become A Pro!
    Join Date: 01-16-10
    Posts: 511
    Betpoints: 564

    wow nice

  10. #10
    JohnAnthony
    JohnAnthony's Avatar Become A Pro!
    Join Date: 04-30-09
    Posts: 5,110
    Betpoints: 12

    Wow, so Granchow's back?

  11. #11
    Ganchrow
    Nolite te bastardes carborundorum.
    Ganchrow's Avatar Become A Pro!
    Join Date: 08-28-05
    Posts: 5,011
    Betpoints: 1088

    I was wondering if you would share the source code for your kelly calculator at:

    http://www.sportsbookreview.com/betting+tool...alculator.aspx
    Better than that is the C++ source underlying the routine called by the VBA KellyVector() wrapper function in the above posted spreadsheet. Follows here:
    Code:
    double DLLPEXPORT KellyVector(
            double *dProbs,                // array of independent event probabilities (input not changed)
            double *dOdds,                // array of independent event odds (input not changed)
            double *dKellyOutVector,    // array of Kelly stakes (output)
            long lEvents,                // number of events (input not changed)
            double dKellyMult,            // Kelly multiplier > 0 (input not changed)
            long lOddsType                /* odds type (input not changed)
                                           0 ==> all odds > 0 are decimal, all odds < 0 US
                                           1 ==> all odds are US
                                           2 ==> all odds < 0 or >=100 are US
                                        */
    ){
        long i, j;
        long lParlaySize, lParlayNum, lThisAND, lOutcomes, lBetIdx, lResIdx;
    
        lOutcomes = 1<= 100)
                            dOdds[i] = g_US2DEC(dOdds[i]);
                }
            }
            if(dOdds[i] == NULL) goto END;
            dSingKellyV[i] = SBKelly(dProbs[i], dOdds[i], dKellyMult);
        }
    
        lMapV[lOutcomes-1] = 0;
        lBetsPerSize[lEvents] = 1;
        lCombins[lEvents] = lOutcomes-1;
        for(i=1; i 1 || dWinProb < 0 || dKellyMult <= 0)
            return NULL;
    
        dWinQuant = dDecOdds - 1;
        dKellyStake = (pow(dWinQuant * dWinProb, dKellyMult) - pow(1 - dWinProb, dKellyMult)) / (pow(dWinQuant * dWinProb, dKellyMult) + dWinQuant * pow(1 - dWinProb, dKellyMult));
        return dKellyStake>0 ? dKellyStake : 0;
    }
    
    inline double DLLEXPORT g_US2DEC(double dUSOdds){
        if(dUSOdds<0)
            return 1-100/dUSOdds;
        else if(dUSOdds>0)
            return 1+dUSOdds/100;
        else
            return 1;
    }
    
    inline long perm(long n, long r){
        long i;
        long lAns = 1;
    
        if (n < 0) n = 0; 
        if (r > n)
            r = n;
        else if (r < 1)
            r = 1;
    
        for(i = n; i > r; i--)
            lAns *= i;
    
        return lAns;
    }
    
    inline long DLLEXPORT combin(long n, long r){
        if (n > r+r)
            return perm(n,n-r)/perm(r,1);
        else
            return perm(n,r)/perm(n-r,1);
    }

  12. #12
    Blax0r
    Blax0r's Avatar Become A Pro!
    Join Date: 10-13-10
    Posts: 688
    Betpoints: 1512

    One nitpick:

    I only quickly skimmed through the code, but I think if r > n (for your perm function), you should indicate an error w/ the 0 return value (or something else). The function shouldn't automatically "fix" a user's mistake; excel works that way too (try something like =Combin(2,50)).

  13. #13
    Ganchrow
    Nolite te bastardes carborundorum.
    Ganchrow's Avatar Become A Pro!
    Join Date: 08-28-05
    Posts: 5,011
    Betpoints: 1088

    Quote Originally Posted by Blax0r View Post
    I think if r > n (for your perm function), you should indicate an error w/ the 0 return value (or something else). The function shouldn't automatically "fix" a user's mistake
    No argument here.

    Call it legacy code -- I swiped those two functions unmolested out of something I wrote as a clueless grad student way back in the 90s.

    I'm much better now.

  14. #14
    Blax0r
    Blax0r's Avatar Become A Pro!
    Join Date: 10-13-10
    Posts: 688
    Betpoints: 1512

    Ah gotcha; either way, I'm sure this .dll has paid/will pay dividends for its users. Also, I think a cool feature (that would save a step) would be an extra param for the bankroll, but may not be worth the effort since it's easy enough to just multiply the output.
    Last edited by Blax0r; 10-20-10 at 06:41 PM. Reason: fixed spelling

  15. #15
    byronbb
    byronbb's Avatar Become A Pro!
    Join Date: 11-13-08
    Posts: 3,067
    Betpoints: 2284

    Thanks these functions have been very useful and saved me a lot of time and swearing.

  16. #16
    punintended
    punintended's Avatar Become A Pro!
    Join Date: 11-29-11
    Posts: 90
    Betpoints: 3283

    Having some trouble with this ..
    When I open the file and enable macros I get the error:
    Error #53 in Kelly Functions. File not found: matrix.dll

    Help?

  17. #17
    RickySteve
    SBR is a criminal organization
    RickySteve's Avatar Become A Pro!
    Join Date: 01-31-06
    Posts: 3,415
    Betpoints: 187

    Not sure but possibly incompatible with your version of Excel.

  18. #18
    AlwaysDrawing
    AlwaysDrawing's Avatar Become A Pro!
    Join Date: 11-19-09
    Posts: 657
    Betpoints: 279

    I get the same error.

  19. #19
    Big Tebowski
    Big Tebowski's Avatar Become A Pro!
    Join Date: 12-13-11
    Posts: 269
    Betpoints: 1420

    I also get the same error

  20. #20
    matekus
    matekus's Avatar Become A Pro!
    Join Date: 07-26-07
    Posts: 39
    Betpoints: 4853

    Possibles Solution

    Possible solution:
    1. Copy FunctionDemo.xls and matrix.dll to same directory (NOT "C:\Windows\System32").
    2. Open FunctionDemo.xls and access VBA editor (Alt-F11).
    3. Use Ctrl-H to open Replace dialog box (see attached).
    4. Replace "matrix.dll" with ".\matrix.dll" (73 locations).
    5. Save FunctionDemo.xls.


    John

    MatrixDllReplace.jpg.

Top