Friday, 27 August 2010

Horse racing market simulation

At this point of time, the Betting AI provides both market data collector and market simulator tools. Market data collector provides history of a market on a betting exchange in a form of market events, where as market simulator allows for testing trading strategies based on a historical market data. After simulation is finished the following report is generated (simulation for one day on UK horse racing markets, 21 markets):

***********************************************************************************

*Market Simulator Copyright 2010 Daniel Korzekwa(http://danmachine.com)           *
*Project homepage: http://code.google.com/p/betting-ai/                           *
*Licenced under Apache License 2.0(http://www.apache.org/licenses/LICENSE-2.0)    *
***********************************************************************************

Simulation is started. Simulation progress: 0% 4% 9% 14% 19% 23% 28% 33% 38% 42% 47% 52% 57% 61% 66% 71% 76% 80% 85% 90% 95% 100%
Simulation is finished in 65907 milliseconds.

Expected profit report for trader dk.trader.Trader:
7f Mdn Stks: /GB/Folk 22nd Aug minProfit/prob=-92.58/0.63 maxProfit/prob=345.0/0.01 expProfit=9.05 expAggrProfit=9.05 mBets=128 uBets=7
2m6f Hcap Hrd: /GB/Newt 22nd Aug minProfit/prob=-173.4/0.14 maxProfit/prob=80.4/0.14 expProfit=1.84 expAggrProfit=10.89 mBets=23 uBets=4
1m6f Hcap: /GB/Muss 22nd Aug minProfit/prob=-1182.9/0.19 maxProfit/prob=522.0/0.06 expProfit=24.83 expAggrProfit=35.73 mBets=226 uBets=17
1m Hcap: /GB/Muss 22nd Aug minProfit/prob=-1036.8/0.27 maxProfit/prob=615.0/0.01 expProfit=-11.99 expAggrProfit=23.74 mBets=222 uBets=9
3m2f Hcap Chs: /GB/Newt 22nd Aug minProfit/prob=-968.55/0.21 maxProfit/prob=1153.65/0.18 expProfit=-25.4 expAggrProfit=-1.66 mBets=184 uBets=12
2m5f Nov Chs: /GB/Newt 22nd Aug minProfit/prob=-1812.6/0.24 maxProfit/prob=1659.15/0.33 expProfit=-105.13 expAggrProfit=-106.8 mBets=468 uBets=14
2m3f Nov Hrd: /GB/Newt 22nd Aug minProfit/prob=-729.3/0.16 maxProfit/prob=738.36/0.31 expProfit=-3.33 expAggrProfit=-110.13 mBets=178 uBets=10
5f Mdn: /GB/Folk 22nd Aug minProfit/prob=-932.6/0.29 maxProfit/prob=591.4/0.11 expProfit=-8.61 expAggrProfit=-118.74 mBets=233 uBets=12
1m Hcap: /GB/Muss 22nd Aug minProfit/prob=-1687.7/0.16 maxProfit/prob=1637.55/0.34 expProfit=46.21 expAggrProfit=-72.53 mBets=421 uBets=24
7f Sell Stks: /GB/Folk 22nd Aug minProfit/prob=-3.0/0.09 maxProfit/prob=7.65/0.28 expProfit=0.07 expAggrProfit=-72.46 mBets=3 uBets=5
5f Sell Stks: /GB/Muss 22nd Aug minProfit/prob=-1699.8/0.28 maxProfit/prob=1462.06/0.3 expProfit=-112.54 expAggrProfit=-185.0 mBets=384 uBets=11
2m6f Hcap Hrd: /GB/Newt 22nd Aug minProfit/prob=-1088.4/0.2 maxProfit/prob=454.8/0.08 expProfit=-8.51 expAggrProfit=-193.51 mBets=156 uBets=8
2m1f NHF: /GB/Newt 22nd Aug minProfit/prob=-1068.0/0.2 maxProfit/prob=1105.8/0.29 expProfit=38.09 expAggrProfit=-155.42 mBets=230 uBets=16
7f Mdn Stks: /GB/Muss 22nd Aug minProfit/prob=-822.6/0.45 maxProfit/prob=1197.9/0.1 expProfit=-26.43 expAggrProfit=-181.85 mBets=333 uBets=12
1m4f Hcap: /GB/Muss 22nd Aug minProfit/prob=-750.72/0.4 maxProfit/prob=561.0/0.03 expProfit=-13.69 expAggrProfit=-195.55 mBets=207 uBets=7
7f Hcap: /GB/Folk 22nd Aug minProfit/prob=-849.45/0.25 maxProfit/prob=471.0/0.07 expProfit=-20.03 expAggrProfit=-215.57 mBets=167 uBets=5
5f Hcap: /GB/Muss 22nd Aug minProfit/prob=-564.3/0.18 maxProfit/prob=219.0/0.04 expProfit=7.55 expAggrProfit=-208.02 mBets=102 uBets=5
6f Hcap: /GB/Folk 22nd Aug minProfit/prob=-1268.7/0.2 maxProfit/prob=1548.0/0.16 expProfit=35.25 expAggrProfit=-172.78 mBets=361 uBets=22
2m1f Mdn Hrd: /GB/Newt 22nd Aug minProfit/prob=-922.5/0.18 maxProfit/prob=684.15/0.23 expProfit=53.31 expAggrProfit=-119.47 mBets=280 uBets=18
1m1f Hcap: /GB/Folk 22nd Aug minProfit/prob=-875.91/0.32 maxProfit/prob=2577.9/0.16 expProfit=-19.39 expAggrProfit=-138.86 mBets=489 uBets=20
1m4f Hcap: /GB/Folk 22nd Aug minProfit/prob=-589.23/0.35 maxProfit/prob=1018.5/0.22 expProfit=-10.18 expAggrProfit=-149.05 mBets=249 uBets=11
------------------------------------------------------------------------------------
TotalExpectedProfit=-149.05 TotalMatchedBets=5044 TotalUnmachedBets=249


The list below presents a few market events for a horse racing market:

{"time":1282481934744,"eventType":"CREATE_MARKET","marketId":101655582,"marketName":"7f Mdn Stks","eventName":"/GB/Folk 22nd Aug","numOfWinners":1,"marketTime":"2010-08-22 14:10:00","runners": [{"runnerId":4848193,"runnerName":"Dubawi Gulf"},{"runnerId":4818333,"runnerName":"Apace"},{"runnerId":4932434,"runnerName":"Menha"},{"runnerId":4932435,"runnerName":"Flying Arch"},{"runnerId":4883524,"runnerName":"Hello Tomorrow"},{"runnerId":4932436,"runnerName":"Mazagee"}]}
{"time":1282481934744,"eventType":"PLACE_BET","betSize":38.0,"betPrice":5.9,"betType":"LAY","marketId":101655582,"runnerId":4818333}
...
{"time":1282482515736,"eventType":"PLACE_BET","betSize":314.0,"betPrice":1.61,"betType":"BACK","marketId":101655582,"runnerId":4848193}
{"time":1282482515736,"eventType":"CANCEL_BETS","betsSize":5.0,"betPrice":18.0,"betType":"LAY","marketId":101655582,"runnerId":4932435}
{"time":1282482515736,"eventType":"PLACE_BET","betSize":17.0,"betPrice":20.0,"betType":"LAY","marketId":101655582,"runnerId":4932435}

Example of trader implementation:

/**Executes trader implementation so it can analyse market on a betting exchange and take appropriate bet placement decisions.
*
* @param ctx Provides market data and market operations that can be used by trader to place bets on a betting exchange market
*/
def execute(ctx: ITraderContext) = {

for(runner <- ctx.runners) {
val bestPrices = ctx.getBestPrices(runner.runnerId)

if(bestPrices._1>2) {
ctx.placeBet(2,bestPrices._1,BACK,runner.runnerId)
ctx.placeBet(2,bestPrices._1 - 0.02,LAY,runner.runnerId)
}
if(bestPrices._2<2.2) {
ctx.placeBet(2,bestPrices._2,LAY,runner.runnerId)
ctx.placeBet(2,bestPrices._2 + 0.02,BACK,runner.runnerId)
}
}
}

Project home page
http://code.google.com/p/betting-ai/