Lefora Free Forum
376 views

pip calculator

Page 1
posts 1–14 of 14
novice - member
37 posts

here's one for the community library. If you need to place a bet one tick away, or "n" ticks away from the current price, this will let you do it, dealing with all the boundary conditions. See the test cases for example use.

regular - member
184 posts
denp - this looks brilliant, I'll let you know how I go with it when I have it integrated with my new trading app.

Thanks heaps!

Alan
__________________
Slashdot. It's like Digg on slow, but sensible.
regular - member
123 posts

Do betfair and betdaq (and other exchanges) share the same tick structure? Or is this betfair specific?

novice - member
20 posts

no, the batdaq one is different

novice - member
20 posts

/* betdaq
* Odds range:
* 1.01 - 3
* 3.05 - 4
* 4.1 - 6
* 6.2 - 10
* 10.5 - 20
* 21 - 30
* 32 - 50
* 55 - 100
* 110 - 1000
* Total: 400 ticks
*/

/* betfair
* Odds range:
* 1.01 - 2
* 2.02 - 3
* 3.05 - 4
* 4.1 - 6
* 6.2 - 10
* 10.5 - 20
* 21 - 50
* 32 - 50
* 55 - 100
* 110 - 1000
* Total: 350
*/

regular - member
74 posts
And there's also some variation between different types of market e.g. on Betfair the Total Goals markets (and other Asian Handicaps?) have a 0.01 tick size regardless of odds
regular - member
184 posts

denp, I finally got round to having a good look at this PipCalculator of yours - I understand most of what you have done, but the asInverse function has me a little lost. This is what I'm doing to test it - it isn't very sophisticated, but it works for me.

The code:

                    PipCalculator pip = new PipCalculator();
                    double cp = rp.getBestPricesToBack().getPrice().get(0).getPrice();
                    System.out.println("Current price = " + rp.getBestPricesToBack().getPrice().get(0).getPrice());
                    System.out.println("pip addPips + 1 = " + pip.addPips(cp, 1));
                    System.out.println("pip addPips + 2 = " + pip.addPips(cp, 2));
                    System.out.println("pip addPips + 5 = " + pip.addPips(cp, 5));
                    System.out.println("pip addPips + -1 = " + pip.addPips(cp, -1));
                    System.out.println("pip addPips + -2 = " + pip.addPips(cp, -2));
                    System.out.println("pip addPips + -5 = " + pip.addPips(cp, -5));
                    System.out.println("pip asInverse = " + pip.round(pip.asInverse(cp)));

The results:

Current price = 2.22
pip addPips + 1 = 2.24
pip addPips + 2 = 2.26
pip addPips + 5 = 2.32
pip addPips + -1 = 2.2
pip addPips + -2 = 2.18
pip addPips + -5 = 2.12
pip asInverse = 0.45

As you can see, the results for adPips are pretty much what I am expecting (and just as a by the by, exactly what I needed, thanks very much!) but I'm not completely understanding what the asInverse function is returning.

This is the function as you have written it:

    public double asInverse(double p) {
        return p > 0 ? 1 / p : 0.0;
    }

Which I have to confess I didn't understand at all. So after another look at the java operators, this is the function as I would have written it - yours is much more elegant than mine:

    public double asInverse(double p) {
        double result = 0.0;
        if (p > 0)
        {
            result = 1 / p;
        }
        return result;
    }

So I understand the operation of the method, but what is the point of the result?

Just as a by the way, even if you never answer this, I'll be grateful for that code, I can't count how many times I have wished for a shorter way for if, then, else statements. Next time I'm working on picking up a new language, I won't brush past the operators like I did with Java.

Cheers,

Alan

__________________
Slashdot. It's like Digg on slow, but sensible.
regular - member
184 posts

I've done a little more experimenting with it and I'm even more confused than before. Probably is me being thick. I had a look at inverse functions and what they are used for (wikipedia) and I think I have a handle on them. I'm still not seeing how to use this function in this class.

This is what I've done:
    PipCalculator pip = new PipCalculator();
    double cp = rp.getBestPricesToBack().getPrice().get(0).getPrice();
    System.out.println("Current price = " + rp.getBestPricesToBack().getPrice().get(0).getPrice());
    System.out.println("pip addPips + 1 = " + pip.addPips(cp, 1));
    System.out.println("pip addPips + 2 = " + pip.addPips(cp, 2));
    System.out.println("pip addPips + 5 = " + pip.addPips(cp, 5));
    System.out.println("pip addPips + -1 = " + pip.addPips(cp, -1));
    System.out.println("pip addPips + -2 = " + pip.addPips(cp, -2));
    System.out.println("pip addPips + -5 = " + pip.addPips(cp, -5));
    System.out.println("pip asInverse = " + pip.round(pip.asInverse(cp)));
    System.out.println("pip asInverse + 1 = " + pip.round(pip.asInverse(pip.addPips(cp, 1))));
    System.out.println("pip asInverse + 2 = " + pip.round(pip.asInverse(pip.addPips(cp, 2))));
    System.out.println("pip asInverse + 5 = " + pip.round(pip.asInverse(pip.addPips(cp, 5))));
    System.out.println("pip asInverse + -1 = " + pip.round(pip.asInverse(pip.addPips(cp, -1))));
    System.out.println("pip asInverse + -2 = " + pip.round(pip.asInverse(pip.addPips(cp, -2))));
    System.out.println("pip asInverse + -5 = " + pip.round(pip.asInverse(pip.addPips(cp, -5))));

this is the result I get:

    Current price = 1.48
    pip addPips + 1 = 1.49
    pip addPips + 2 = 1.5
    pip addPips + 5 = 1.53
    pip addPips + -1 = 1.47
    pip addPips + -2 = 1.46
    pip addPips + -5 = 1.43
    pip asInverse = 0.68
    pip asInverse + 1 = 0.67
    pip asInverse + 2 = 0.67
    pip asInverse + 5 = 0.65
    pip asInverse + -1 = 0.68
    pip asInverse + -2 = 0.68
    pip asInverse + -5 = 0.7

Just for this example, I can see that the difference between the current price and the asInverse return is 0.2 Just looking at the returns from a couple of  different price calls now:

    Current price = 1.04
    pip asInverse = 0.96

    Current price = 1.12
    pip asInverse = 0.89

I don't understand. I think it may be giving the number of ticks left until the next jump, but that makes no sense at all if you look at the very first lot of output there. I'm horribly confused here and I think I might be overthinking the problem.

Alan



__________________
Slashdot. It's like Digg on slow, but sensible.
regular - member
134 posts

lol, you'll kick yourself!

A runner at a price of 1.04 will win 0.96 (96%) of the time.
A runner at 2 (ie evens) will win 0.5 (50%) of the time

All the inverse function does is convert either way between implied probability and betfair prices

1 / 2 = 0.5 and back again 1 / 0.5 = 2

regular - member
184 posts

Oh for christs sake.

Consider my arse thoroughly self kicked.

Thats actually a really useful function though - I have a real use for that at the moment.

Thanks Fred,

Alan

__________________
Slashdot. It's like Digg on slow, but sensible.
novice - member
37 posts

Sorry Alan - I should have thought about it more and used a name such as Fred suggests.

p > 0 ? 1 / p : 0.0;

is an example of the "ternary operator".  All it is doing in this case is avoiding a divide by zero error.  The ternary operator is available in many languages.  Oddly it only got added to Python in version 2.5 a year or so ago.

regular - member
184 posts

no biggy denp, if nothing else it showed me how capable I am of overthinking something. I think I sometimes need to back off and reduce things to basics. As you saw, I have a shocking tendency to make things more complicated than they are.

As for the ternary operator, I love it, I think I will be using that structure a lot. Lesson learned though, I'm going to document it when I do though - I find reading my own code an adventure in unintelligibility most of the time, reading someone elses code often throws me for a spin.

On the subject of python though, I just bought myself a Nokia e61i off ebay and I was gratified to find that not only is python supported on it, there is an interactive shell for it as well. All I need now is a decent free text editor for it and I'll start playing with it on the boring days at work when I can't get my laptop out.

Thanks again,

Alan

__________________
Slashdot. It's like Digg on slow, but sensible.
rookie - member
2 posts

Very useful class. It saves my time. Thank you.

__________________
"When I hear the "culture" word I reach for my gun"
rookie - member
2 posts

I made some modifications of code for using with the Swing JSpinner component.

All that you need - add code below to your component initialization.

JSpinner mySpinner = new javax.swing.JSpinner();
mySpinner.setModel(new PipModel(1.01));
mySpinner.setEditor(new PipEditor(mySpinner));

Attachment: PipEditor.java (0.0KB)

Attachment: PipModel.java (3.0KB)

__________________
"When I hear the "culture" word I reach for my gun"
Page 1
posts 1–14 of 14

This Topic Is Locked To Guest Posts

It's been a while since this topic was active, if you'd like to get it going again, please post as a registered member

join now