Wednesday 10 February 2010

Building Our First Bot - Part I, Theory

OK: we've done a lot of theory. Now, let's actually build something that can actually trade. What we're going to do is a very, very simple version of a market-making bot. Why so simple? Because we want to minimise risk during this learning experience, and also because it'll be easier to understand what we're doing. We'll build out this 'bot over the next couple of weeks and months, but this should get you started.


First things first: what's this bot going to do?


Well, it's going to act as a very simple market maker. It will offer liquidity, for a given selection, at a slightly better price than the best price currently offered. Every few minutes it will check whether it is still the best price, and will move it if price change around it. Should our meagre offer be taken, it will jump to the other side of the trade, offering up a price for someone else to take.


Simple? Well, let's explain it using some pictures. A typical Betfair selection looks like this:


Tottenham Hotspur vs Arsenal


Back

Lay

Tottenham

2.2

2.4

Arsenal

1.5

1.7


Now, for the purposes of our super-simple 'bot, let's simply look at one selection – Tottenham. So, we have an option to back them at 2.2, and to lay them at 2.4.


What out 'bot will do is this: it will offer to back Tottenham with a £2 (the minimum) bet at 2.38.


Tottenham Hotspur vs Arsenal


Back

Lay

Tottenham

2.2

2.38

Arsenal

1.5

1.7


Now, the market will look like this. (I've highlighted the bet that is ours.) Our 'bot will then monitor the market every 30 seconds or so. If our bet is taken (and nothing else happens), then the market will look like the first figure again. And we will have a profit of £2.76, should Tottenham win.


But we're not interested in whether Tottenham wins or not – our goal is to make money by supplying liquidity to the market. So, what we'll do now is offer to lay Tottenham at 2.22.


Tottenham Hotspur vs Arsenal


Back

Lay

Tottenham

2.22

2.4

Arsenal

1.5

1.7


Should someone take our bet, then we'll have a (£0.32) profit irrespective of whoever wins.


This will be the simplest Betfair 'bot in the world: it will monitor somewhere between 1 and 100 selections, and will attempt to grab a small chunk of the action by acting as a (very limited) market maker.


But what happens if no-one takes my offered back bet, or if the market moves away from me? Well, no great loss. You can just reset the level of your bet, so that it is inside the best lay price available. The 'bot needs to be smart enough to only put bets on when there is a reasonable (say 3%) gap between the back and lay prices.


And what happens if someone takes my offered back bet, but then no-one takes my offered lay, or the market moves away from me so I am making a guaranteed loss? Well, the 'bot has two possible choices: it can always stay inside the best back price, and so sometimes it will take small losses. Or it can leave the bet in place and hope the market returns. Because the amounts we're playing with are so small, the worst that happens is that we end up with a small uncovered back bet on Tottenham.


This 'bot will work best on markets where the odds move around a lot. And it will work least well on odds which will tend to trend for long-periods in certain directions. It will also work very poorly for in-play markets – not least because it will only be checking on prices every 30 seconds or so. The 'bot needs a reasonably, but not excessively, liquid markets: we need to have a gap between the back and the lay prices, otherwise we're not offering anything useful. (The aim with this 'bot is to get paid for the provision of liquidity.) We'll work on some algorithms that find appropriate markets and selections down the road.


In the second part of this post – which will hopefully be tomorrow, but may be Friday – we'll actually program this 'bot, and get it trading on some real markets.

11 comments:

  1. this is a brilliant blog, wish i could contibute more.

    Is it worth me learning Revolver or VBA from scratch??

    ReplyDelete
  2. Well: if you want to learn about computer programming (with the goal of making money out of Betfair trading), I would go for Python. Google for 'introduction to python'. If you know Python, Resolver will be a doddle.

    ReplyDelete
  3. Hello,

    I read it few times but not understanding betting at all (never placed a bet) I don't get why such a bets like Tottenham back 2.2 , lay 2.4 are possible at all? Surely if there is no draw then if I back and lay at the same time I cannot lose? Or did you omit the draw situation from the diagrams?

    ReplyDelete
  4. forcer: suppose this is a cup match so there has to be a winner.

    You could back and lay simultaneously and you would indeed make a guaranteed profit -- provided people take your bets up. If you place a backing bet, that will only be "matched" if someone offers to lay at the same odds. You can see this above: we backed Tottenham at 2.38; this then appeared in the "lay" box since someone wanting to lay Tottenham could do so at 2.38 and be matched to our price.

    The tactic here to encourage people to take your bets by offering slightly better odds than the market currently has to offer. We can back at slightly above the lay price, then once that's taken up, lay at slightly below the back price -- this, assuming there's a decent spread (difference between back and lay prices), will be below the price of our back.

    So we end up with a situation where we've backed Tottenham at odds of 2.38 and layed at 2.2. We're guaranteed a profit of (2.38 - 2.2) * £2 = £0.38 if Tottenham win (and no profit nor loss if Arsenal win), since:

    Tottenham win: back bet yields 2.38 * £2, lay bet loses 2.2 * £2 = profit of £0.38
    Tottenham lose (so Arsenal win): lay bet yields £2, back bet loses £2.

    ReplyDelete
  5. Forgot to add: real Betfair markets on football matches do indeed include a Draw option, but this is omitted in this post for what I assume is simplicity. Much more complicated markets with many more entrants ("runners" in Betfair parlance) exist, e.g. markets on who'll win the whole league.

    ReplyDelete
  6. Thanks David. It makes sense now. I was looking through Betfair and most of the matches have 3 options including draw. I have been looking now more towards "arbitrage betting" where you place bets on different servers, installed RebelBetting and it seems like a clever piece of software that could teach me how to start betting without big risks involved.

    ReplyDelete
  7. Beyond casino with most of the entertainment.
    Gclub SlotIs online casino site that offers all the fun for gamblers. New games are easy to gamble, and you can bet on the site directly. All kinds of online gambling games that are ready to entertain the user unlimited. The fun of online games to the player even more, and can generate money for all players. Gambling online casinos are packed with fun at any time. Regardless of the time, you can use the online games to win entertainment. Our online casino games that will make customers more merrily. Not only this, our online casino games site also supports gambling on smart phones with easy to play money with online gambling games with 24-hour customer service, betting on online games that will not disappoint you. Entertainment, and can also meet the needs of modern gamblers have been excellent. Online gambling is the gateway to wealth. If you bet today, you also have the privilege with a variety of profits that will make the player risk every game online. Holiday Palace

    ReplyDelete
  8. Nice topic to post ,I very much agree with this,especially we should take care of our health.This post will surely help me to take right decision,thanks for the great tips!
    เว็บย่อลิ้ง
    เว็บย่อลิ้งค์
    ย่อลิ้ง
    ย่อurl
    ย่อเว็บ

    ReplyDelete
  9. Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here. Minecraft Server List

    ReplyDelete
    Replies
    1. Online Casino Roulette. Roulette is all alone of the amazing famous 'wheel' casino online games. It is zest superb to lose true a round and there are various types of online casino roulette... Online Casino Roulette. Online Slot Machines. Slots are the easiest casino ... owner of google by Nadir

      Delete