Saturday, 20 March 2010

UI

The user interface will initially be a simple Swing window with a text box for each parameter and a window for log output.

This is made slightly more complex due to more than one race being traded in parallel.

I think I'll probably go with a log window for each race being traded - this could be configured in a number of different ways.

1) The log pane splits into as many windows as necessary for each race being traded.
2) Each race has a tab created for it.
3) Each race pops up a new log window separate to the parameters.

The UI can also show profit and loss in the main window.

Sunday, 7 February 2010

Went live last weekend

I started the bot running live on betfair with a £3 initial stake.

It seemed to work as planned, although due to a few bugs, I found that I had to log into betfair and manually close some of the positions. I did leave myself exposed for one of the first races and accidently won £14!!

I need to refine the algorithm now and introduce some new parameters.

Currently the parameters are:

Stake
Profit per trade - max profit per trade before position closed (quit while ahead!!)
MaxTick - Number of ticks the price changes by to place trade
spike - Ignore large price fluctuations
odd limit - maximum price used.
Amnt Available - amount on offer to back/lay
Min Matched - minmum matched amount on this horse - shows activity
StartTradeTime - how long before race to start trading
EndTradeTime - how long before race starts to stop trading
TimeBetweenTrades

Additional parameters to do:

weight of money - the percentage of total amount that is on the back or lay, this will give an indication of which way the market is going.

Sunday, 3 January 2010

TO DO

Place the bets with betfair.

Automate the calculation of the bet parameters to use - maybe able to use a pivot table in Excel.

Write the GUI front end in Eclipse RCP.

Java

I started with the WSDL from the Betfair developers program- created the interfaces from this etc.

I wrote a bot to perform the trading, this will place/cancel/re-place the bets given the market conditions. The bot will trade many races at once, each race creates an array of bots - one per horse used.

The trading begins 20 minutes before each race. More than one race can be traded at once as some races are 5 minutes apart.

Currently no bets are actually placed, but are simulated in real time.

A GUI will be written in Eclipse RCP, this will provide a means of altering parameters, analysing results and replaying results to simulate different parameters.

WATCH THIS SPACE.....

Theory

In theory trading on as many profitable horses as possible during the day will give best results. What determines a profitable horse is the problem I am solving. In order to find these values I am considering the following variables.

Stake - the amount to initiate the trade - I suspect that the market will only tolerate small amounts for a reliable profit. i.e. you are more likely to get £10 matched immediately than £100.
Odds Limit - the max price used - using large prices means you need a lot of cash in your account to support the Lays. (e.g. £10 lay at 40 requires £400)
Max Profit Per Trade
Max Spike - this is to cater for the large spikes in the movement.
Max Number of ticks a market can move before being closed
Max Profit that can be made before a market is closed.
Minimum Amount available for bet
Minimum amount matched on that runner.

With a profitable set of parameters, trading on 1-3 horses per race should give approx 0-£10 profit per race, using simulations this seems to give about £20 per day (about 12 races). Not a lot for the amount of activity required, but not bad for the push of a button!

To simulate I basically used a stake of £10 on every race for horses with a max price of 5. The bets were not actually placed, but the theoretical profit was calculated given the live prices on the market.

The prices were captured and fed into the bot with a set of values for each variable. The results were then analysed in an Excel spreadsheet to determine the set of values that gave the most reliable profit. I have been looking at 10^8 results - this required me to buy a new PC as my old single-core machine was creaking at the seams!

Introduction

About a 18 months ago I started looking at Betfair and fairly quickly realised that straight betting was a bit of a mugs game and quickly lost my initial £100 pot.

So I looked into the subject a bit and realised that hedging on horse racing was the way forward. Doing this locks in profits no matter the outcome of the race. Basically if you bet at a higher price than lay on the same runner then you'll achieve a profit no matter what the outcome. So on a rising market lay then back when the price has risen, conversely on a falling market, back then lay when the price has fallen. The amounts to place at these two prices are in the ratio of the prices.

e.g. Falling market: Back £10 @ 3.10, then Lay £10.33 @ 3.00 (10*3.1/3.0) will give you a guaranteed profit of £0.33 - not much, but a profit!

This is scalping and the idea is to get in and out quickly making a profit on every race. You don't concern yourself with the actual horse race and gain nothing from watching or listening to it.

This trading (scalping) can be done through the Betfair website, although to do it properly you need to be either extremely good at mental arithmetic or use a calculator very quickly.

Then I discovered Racing Traders (http://racingtraders.co.uk)- this is an excellent tool for trading on the horses and there are some excellent tutorials on their site, which explain the processes and techniques very well. They provide a tool to enable you to trade on the horses and hedge each bet correctly to achieve the same profit on a win or no-win situation. I urge you to give this a try if you want to understand the techniques.

The only problem is that the UK horse racing is on during the day mainly, whilst I am at work and being self employed taking time off to scalp is not sensible.

Anyway, this brings us onto the subject of automation. I am an IT consultant and work in Java, Oracle and other related things, one of my obsessions is automation and I have automated many of the testing processes in systems I work with using some COTS products like HTMLUnit and Rational Functional Tester and some I have written from scratch myself.

So I set myself a task to automate the scalping of horse racing using the Betfair API, which is freely available and well documented. This seems possible as the decisions that you make as to whether to place a back or lay bet are based on determinable factors and values - the type of thing a computer is good at!!