Testing horse racing strategy on betfair to be placed market
Posted in Video Tutorials by StefanBelo Tags: BOT | Video
Yesterday I read Paul R. blog and his article Planning the Development of a Bot. It is good to see other software developers writing about betfair bot development.
A bot is simply an automated way to do something you would do manually. It has several advantages we wish to exploit, and if anything we do negates one of these advantages we must reconsider whether it's suitable for a bot to be doing it.
- Speed is of the essence. A bot can obviously act and react much faster than a human. Because of how the APIs work a bot can monitor many markets simultaneously and strike/cancel bets much faster than any human. This has obvious advantages as the earliest mover in a market to make the right decision typically will make the most money.
- It will behave consistently according to design. We have all found systems, techniques and tricks that appear to be profitable. Those with strong discipline might even be able to stick to them. For the rest of us though, there is always a desire to have a quick punt or to break our system based on a hunch. It makes the statistical analysis of what we're doing borderline ridiculous. That's when losses occur. Bots will do what they're programmed to do, and only what they're programmed to do.
- They free you up to do other things. Back in 2002 when I was first trading I was spending 10-12 hours/day at screen. It was demoralising and boring work grinding out a meagre existence. I would have rather spent my days enjoying watching the sport without needing to keep an exchange screen open constantly, or doing something entirely different instead. A bot can - and probably should - work completely unaccompanied and perhaps running on a server in a data centre so I don't even need my computer to be turned on if necessary. It should be able to work on markets whilst I am enjoying the fruits of its labour.
- The nature of building a bot forces you to be more systematic and analytical. Rather than going with "it's a hunch" style of betting/trading, you must justify every line of code. Even better, following industry standard programming methods, a bot can be "iteratively" developed, that is to say tweaked and enhanced bit by bit based on data and results. This requires us to go back and revisit our assumptions regularly, and make new ones. It's a healthier way to think about what we're doing here.
So we want speed, consistency, complete automation and iterative development based on systematic and analytical thought processes. What could be easier?
The first idea for a bot I am going to test is one I expect to fail at the analysis stage (which is good! If it's going to fail, that's the point in time I want for it to fail, not after the bot is built and running out onto the exchanges with hard cash), but will be relatively simple to implement and therefore a good "starting project" for this blog. It is very simple to state:
Find non-handicap UK/IRE horse races which will go in-play, and back the favourite for 5% of my betting bank in the place market 5-10 minutes before the official off. Then lay it at a price giving a 10% RoI greened up with the "keep in play" option on the bet selected.
It's a very naive system based on the assumption that favourites in non-handicaps are priced fairly, and I currently have no evidence of it being profitable. Each component needs to be tested and verified before I build any code. I'm happy to modify my thoughts based on the results I get back, and I have plenty of other ideas for bots if this one doesn't stand up to analysis: the purpose of this idea is primarily to go through the analysis stages.
Having my own "bot" I decided to extend the bot: TriggerBotByMarketNameLookUpBot that can be found in BfexplorerCommunity Bots group under the name: Trigger a bot by name
I created this bot couple weeks ago and its main use was to execute a bot strategy on horse racing markets where you can exclude or include markets by race type and/or distance. I added a new parameter (AssociatedMarket) so a bot execution is made on associated market, in this case on the To Be Placed market.
To execute Paul's strategy I created a bot setting for trading bot Place bet and close position setting parameters: BetType Back, PlaceBetInAllowedOddsRange True, AllowPlacingBetInPlay True, AtInPlayKeepBet True, ExecuteOnSelection 1, Stake 5, StakeIsPercentageOfMybank True, ClosePositionImmediatly True, HedgingEnabled True, Loss 0, Profit 10, ProfitLossType Percentage.
Because the bot must be executed on the firts favourite I set the market criteria parameter Sort selections by Probability to win, and ExecuteOnSelection 1.
This is the universal bot setting for trading on favourite, with no stop loss target and opening stake as a percentage of available bank. You can execute this bot on any betfair in-play market. I named this trading bot:
- Trade backing on favourite, 5% bank, 10% profit
To execute this trading bot on non handicap to be placed market I created second bot setting using the bot Trigger a bot by market setting parameters: BotToExecute Trade backing on favourite, 5% bank, 10% profit, AssociatedMarket To Be Placed, Exclude Hcap. I named this bot setting:
- To be placed, non-hcap, Trade backing on favourite, 5% bank, 10% profit
This bot must be executed on win market because only this horse racing market has information whether the race is handicap or not. There is no such information in betfair api data for To Be Placed market therefore I need this bot with parameter AssociatedMarket.
In my video I tested the bot on handicap and non handicap race, and you can see that all works fine, the trading bot was executed on non handicap to be placed market only, and the trading bot was executed on the first favourite at the moment.
Later in my vide I showed how to use the tool: Trade opportunity lookup, to execute Paul's trading strategy on all today's UK horse racing markets, setting the time for bot execution to 2 minutes before race off, the parameter Start monitoring -120 (seconds).