Latest Model - Final Report

I completed the testing of my latest trading model on paper after being spooked by a losing streak. However, after reviewing all the data today, as Commander Data would say, "Everything is operating within normal parameters."

In the first image you can see the optimisation of the training data I used for a genetic algorithm. (Click images to enlarge). I decided upon the very first set of entries and exits because this gave a large yield with a very good Sharpe Ratio. There is a better Sharpe Ratio in the data but for far fewer trades, which creates the risk of more variance.


Looking at the data more closely I can see where I can create some new fitness metrics. Maybe something that utilises both Sharpe and absolute yield.

The equity curve for the 30, -77, 16 entry/exit vector looks rather smooth with no large drawdowns. You would expect that with a Sharpe Ratio of 5.42


I setup a bot to trade this entry/exit vector with new code to handle the new metrics that I had created. Minimum £2 trades were used so as to minimise risk whilst testing the new code under live conditions.

The sudden drop in equity spooked me and so I continued trading on paper, using the bot to collect data only rather than place any trades.


My fears were unfounded and the trades performed largely as the model expected. As can be seen in the test figures below, Sharpe and average yield were slightly higher. As the test trades were about 10% the number of optimisation trades then we can look at the previous optimisation equity curve and see similar drops if we split the curve into 10% chunks but which make no impact on overall profitability. In other words, I was spooked by the difference in scale between the charts. (A beginner's mistake. I should sit in a corner for 10 minutes.)


Also, I was confused by the bot's trade log producing figures that do not tally with what actually happened so there appears to be a bug in the bot. In the meantime the bot is not running until I am 100% sure that everything is working. I also need to get on with my new book as I have not touched it for a few months. The weather is good for tennis so I want to get some exercise rather than sitting here all day otherwise everything will be for naught.

Admit Your Mistakes

The only way to progress as a trader is to admit your mistakes and correct them. I've noticed a few more blogs (courtesy of Green All Over's blog list) that have deleted pages they wished they'd never published. You know the type of page I refer to; "The One Month Challenge", "Double My £100 Bank in 10 days", "Make £100,000 in One Year", "This Time Next Year Rodney..." etc. Pages are removed when the bankroll blows up or the website is never updated again.

Bold claims are usually made by young traders starting out with no real idea of how to trade. Well, I am going to start the ball rolling by admitting that I was such a trader, many years ago. I was working in The City and if I wasn't spread betting futures contracts, I was in the casino (after work) playing poker. Internet poker and Betfair had just taken off. I was the quintessential action gambler. All money, bluster and no idea of what I was doing. Money comes easy in The City and goes just as quickly.

When the first third-party software applications came out for the Betfair exchange I was onto it. Of course, the ladder has you "scalping" like a pit trader in a futures exchange but without a structured strategy losses mounted. Any idea I heard of I tried. Even if it failed I just blamed others and continued in the hope that I could make the markets bend to my will.

Then the best thing in my life happened, I was offered a redundancy and so I left The City. I haven't played poker since. I stopped futures trading. Rather futures stopped me when I took a £10,000 hit on an oil contract. I reevaluated my entire life and became more realistic in what I could achieve. I realised that wealth is a pyramid structure with a long hard climb to the top and there is not much room at the top, even if you get there. Try hard but not so hard that you guarantee failure.

Today, I get rich... slowly. If at all. I make a living. I am comfortable. I do not have a wealthy lifestyle. I am a member of a tennis club with plenty of fast cars parked outside. That is the lifestyle choice of other members not me. I am happy to drive a twenty year-old secondhand jeep that I maintain myself.

And so I offer my list of mistakes and ask you to do likewise on your blog and/or Twitter account. Retweet and get others to do likewise. Only by being realistic and truthful to yourself and towards others can you progress. It's the first step to success.

My mistakes...

1) I thought only of winning and not a winning edge.

2) I jumped at ideas and traded them without back testing.

3) I had no money management strategy.

4) I got caught up in the action rather than trading the numbers impassionately.

5) I chased my losses instead of my winnings.

5) I boasted about winnings and kept quiet about losses.

Today, I never trade with trading models that have not been thoroughly tested. I write ideas down on scraps of paper and when the day's trading is over I test those ideas to destruction. Most fail. You just have to accept that fact and move on. I never trade a losing model in the hope that it might work.

Money management is very important to me as I am self-employed. My sports trading is just a part of my income and I have to look after every penny I make. I am far closer to retirement than I am to my days at university. There can be no big mistakes from now on, just little ones to learn from.

I never tell people I know of what I do. If they ask then I just say, "I write and I work with computers." If they ask about my website, book or Twitter account then I just say, "If you are interested in that sort of thing then you will already be reading it." I used to make fun of a Chinese girlfriend who always told me to be "humble and modest" (it was the pronunciation that amused me - humbull and moh-dest) but she was right. Nobody likes a big head and P&L blogs are the worst kind of big-headedness if not written with a large dash of modesty. There are some good P&L blogs and they know who they are because I frequent them but most are egotistical "look at my latest win (whilst we brush the losses under the carpet)".

Action I find on a tennis court. If I have an off-day or just don't feel happy about life then I take it out on a tennis ball and not on the markets. As children we were all told to pick on someone our own size. We are all pygmies in the markets.

Update

Apparently, I am the only person in the world to have made trading mistakes. I never knew I had so much money to pay off all you winners!

Approaching Half Way In New Model Test

I am currently testing a new model to add to my trading portfolio. The test consists of 100 trades at a minimal trade size of £2 to see how it matches the model optimised by a genetic algorithm

You may ask why I am not testing this on paper. The reason being that I am running new code that needs to be tested live and the kind of trading I do is very precise and paper trading does not replicate the same live trading conditions.

Already I have made a few changes. The optimisation suggested a profit take whenever a trade makes 25% yield but I have toned this down to 20%. The stop loss is fine as is. I changed some of the code to keep me better informed but essentially it is similar to the code in Programming for Betfair

This is a hybrid trading model whereby the program analyses all the days races at the same time and flags runners that fit the entry criteria for a trade. A human trader then trades the runner with his discretion in play. At no time is the trader permitted to trade below the limits set by the algorithm. There are some things that computers can't do and there are things that humans can't do either. This method utilises the skills of both.

A few figures from the test...

Average win per £1 traded = 0.15
Average loss per £1 traded = 0.10

Strike Rate = 0.68

Longest Losing Streak = 3 trades (model says 5 over a larger period)

Edge per £1 traded = (0.68 * 0.15) - ((1-0.68) * 0.10) = 0.13 (i.e. 13p per £1 bet)

Total % Yield = 6.25%

Average Daily % Yield = 6.55%

Daily Sharpe Ratio = 1.78 (In other words my reward is greater than the risk taken on.)

I have begun to increase the trade size slightly so that I can experiment with gradually entering money into the market or taking it out. The minimum £2 trade is to reduce risk whilst testing a new model and new code that can accommodate the new model but it constrains trading style.

Trading with this model has given me an idea for another so I will reprogram the genetic algorithm trading rule optimiser to see if there is any edge in the new idea. I shall file a final report when the 100 trade test is over.

Compounding Yield in Sports Trading

Compounding, the magic ingredient that will give us untold wealth. We've all done it when we started out trading. We opened up a spreadsheet and took our first day's yield and compounded it over the next few years. "I'm going to be a millionaire!" we foolishly say to ourselves.

I still run a compounding spreadsheet but not for sports trading. My bank accounts and other regular forms of income are noted each week and a compounded value for the next five years is calculated. This makes sense because a bank account (no matter how little they pay these days), peer2peer and other investments can be more relied upon than sports trading income.

I expect to make 10% per year on my portfolio of investments and other incomes and so I expect to double the value of my portfolio in 8 years time. Why can I not do the same for sports trading? The answer is market capacity.

Just because you are making 10% yield on your trades now does not mean to say that you will continue to yield 10% as your bankroll increases thus allowing you to make bigger trades. There is only a finite amount of money on offer in the exchange.

Compounding your winnings is a similar fallacy to using the Martingale to recoup losses. In Martingale betting, a naive gambler playing roulette thinks they can just double their bet after a loss to get their money back. However, the casino has a maximum bet limit and if you have a run of bad luck then your bet doubling will exceed the table maximum and you'll never get your money back.

To control risk a casino sets a limit as to how much money is in play at roulette. The same applies to market capacity only natural forces determine how much money is in play at any one time. Keep on winning and eventually you will hit the market limit as your bet size increases.

In the case of a naive sports trader, they might imagine there will always be enough money to cover their trades. However, the amount of money available at a given price is always finite. If you want a larger trade then either you have to accept a worse price or you will have to put your own offers into the market to get people to take the opposing view. The danger with that is that you have now become the market and if you are wrong about the price then you will lose edge.

And that's the problem you will have with compounding in sports trading. You are in a money market of finite size with agents who are also trying to maximise their wealth creation opportunities. In early market trading there is not much money in the market. Put too much in and you are the market. Make a mistake and someone with better knowledge (an insider) will destroy your edge. Nearer the start of a horse race or during an in-play sport there will be more money available but time is now at a premium where bad decision making can ruin your wealth.

Even though I recommend proportional and Kelly based money management strategies they usually have to be toned down to allow for noise and combining that with market capacity means that the hoped for geometric growth sometimes turns out to be little better than linear growth. I have created Kelly simulations on a spreadsheet and the rate of increase is astonishing but never realistic. There just isn't enough money in the exchange after a few wins.

You can be almost sure of returns from bank accounts, less risky investments and employment income. That is not the case with higher risk investments and sports trading. Compounding of sports trading income in a market of limited cash and limited opportunity is a fallacy. The successful trader will increase their wealth rapidly at first, if they are any good, but after that growth becomes more linear.

Testing Latest Trading Model

The trading model I referred to a few weeks ago is now in test. The model will be making £2 trades for a maximum of 100 trades to see how the model matches against the optimisation results and the out-of-sample test. Also, it will test out some new code that I have written so I don't want to risk too much in case of program failure. Yesterday saw a glitch where a stop-loss failed to fire and the trade was left to go to expiry whereupon it became a bet... and won. I won't be skewing my analysis spreadsheet with that 1200% return.

A poker playing friend who has gone on to great success at the game once said, after he bad beat me for the umpteenth time, "I'd rather be lucky than good." That's not a mantra I wish to copy in sports trading. Yesterday's good luck could easily have been bad luck so I have rectified the glitch and will take all stop-losses on the chin. Besides, my friend may have his fair share of luck but he is also very good.

I have been discussing the testing of this model over at Trader247. The model is a purely technical pre-start horse race trading model. Nothing is known of the runners, riders, trainers or phase of the moon, just market dynamics, wisdom of crowds and market efficiency. The model is highly selective, placing just a few bets per day rather than firing in many hundreds like some sports trading algorithms.

My aim is to slowly ramp up the trade size, making sure not to reach market capacity, which is very easy at any time prior to the last 15 minutes or so of the pre-start market. A single trade opens the position and then it is closed when a profit-take, stop-loss or start-time is hit. There is no doubling down, Martingales or any desperation to claw back a losing position.

Caveat Emptor

I have recently discovered that Betfair now charges anyone attempting to create a live AppKey for the first time as of 10th May 2016. Anyone creating the live and delayed AppKey from now on will see a disabled live key for which there is a £299 charge to enable it. If you do not pay the fee then your data will be delayed for upto 60 seconds but betting operations are live. At least you only have to pay the fee once unlike third-party software where the recurring monthly fee will eventually be greater than £299.

Supposedly the fee is to to stop unlicensed commercial use. However, the AppKey you are buying is used to indentify users so rogue users can simply have their access blocked when they try to login with their AppKey.

To summarise...

a) As of 10th May 2016 you will have to pay a £299 fee to access live data through API-NG.

b) Betting operations can be accessed live with a delayed key.

c) Althought the lastpricematched returned by the delayed key might be upto 60 seconds old it will have a timestamp.

For those of us who had created AppKeys before the introduction of the fee or who have paid the activation fee we have have access to two keys; a live one and a delayed one. The live AppKey allows us to use API-NG as normal. The delayed AppKey is for testing purposes; you can place bets in realtime but the data you are receiving can be up to 60 seconds old. New accounts will only get access to the delayed AppKey and will have to pay for the live AppKey.

Here is the official reason for the charge

We have recently introduced an application process for new customers who'd like to use the Betfair API for betting. This is to prevent unlicensed commercial use of the API.

The application process does not affect active customers who are currently using the API (personal customers or Vendors), nor will there be any retrospective charge applied to active customers.

New customers who create a new Application Key are able to use the API with a Delayed Key (which by default now allows betting operations for new API customers) but need to apply and be approved for Live App Key API access before paying the £299 one off fee.

The Delayed App Key has always been intended for use by customers for development purpose and functional testing.

No Full Algo-Trading Yet

My algorithms still have a degree of discretionary trading about them. By that I mean the algorithm expects a trade at a certain point but the trade is still executed manually, which permits me to get a better price. It matters not if I miss the boat this way as there is always another trade.

A particular algorithm I have recently developed was done so using genetic algorithm to discover interesting facets and then brute force search to complete the optimisation of the areas of interest. I know that the algorithm provides edge at a certain entry point. However, programming the bot to always trade at that entry means that I miss out on the chance of a little extra profit because sometimes the market overshoots where it is expected to go. Because of this overshoot I still enter my trades manually. 

The algorithm is constantly monitoring every race and tells me when any entry has been met. I then look at the spread and decide if I should hold out for a better price. In effect, the entry tells me the absolute maximum or minimum price to trade at so there is no risk of a bad trade. Some trades will go against me, which is to be expected but I cannot blame bad entries as they have been optimised.

I can see a way of creating another algorithm for automating the process of getting a better price than the entry price so there is a possibility that I can update this particular bot to be fully automated. However, I still like to use my discretion. Even financial trading bots in commercial banks have human circuit breakers to act when they sense something is wrong. After all, an optimisation process can only do what is asked of it and no more.

The Best Strategy is Not Always a Good One

I received some interesting comments after publishing a recent article on evolutionary computation. One commenter asked if evolutionary computation always finds the best solution and when is it best to use a brute force approach instead.

Answering the second question first is easiest so I will do so. If you can do a brute force search then do so. If the creators of the Deep Blue chess computer that beat Garry Kasparov and the AlphaGo program that beat Lee Sedol at go could have used brute force techniques then they would have. They had to use artificial intelligence (AI) techniques to optimise the best move because the search space for chess and go moves is so large.

Today's desktop PCs are very powerful with their multi-core CPUs, parallel processing GPUs and programming languages that can make use of parallel processing techniques. It is better to perform an exhaustive search first and then to make sense of your findings rather than immediately turning to AI. There is no magic in AI. Both brute force and AI search will find the same solutions to a problem. It is only when time is a constraint or nothing is known about a search space does AI come into its own.

To answer the first question, 'Does evolutionary computation (or any AI technique) always find the best solution?' the answer is no. The only way to be sure that you have found the ideal solution is to search the entire problem space. If that is not possible then you are reliant on 'satisficing' (being satisfied with a sufficient solution).

Your AI technique might find a local maximum i.e. the technique gets trapped in a certain part of the search space and provides the best solution for that part of the search space even though a better solution lies elsewhere. Finding the best answer in a search space is not always the best solution to a problem.

You might find a trading rule that has a 50% yield but only finds a trade three times a month. The trading rule will probably be over-fitted to the training data with no predictive value with unseen future data. It would be better to choose a less optimal trading rule that trades 100 times a month with a yield of 10% and an out-of-sample yield of 5%. At least then you know the rule has a degree of robustness.

We can think of optimisation as a hill-climbing exercise. The idea is to find the peak of a hill representing a high rate of return from an investment. In the first picture we see a chart that is quite fat in comparison to the hill in the second picture. Each bar in the chart can be regarded as a slightly different entry for a trading rule and the height of each bar in the chart can be regarded as the return for the rule.


In the second picture the hill is not so fat. The optimal solution is superior to the optimal solution in the first picture but the neighbourhood consists of many more sub-optimal solutions than the neighbourhood in the first picture.


Due to slippage we may not get the exact prices we want for entries and exits and so we will be trading with either side of the optimal entry point. If you have been monitoring your slippage then you will have an idea how far either side of the optimal price you have been getting matched. You will want to make sure that even with slippage you are hitting profitable trades.

Now imagine if these hills in the above pictures were next to each other in a search space. The peak on the hill to the right has a very attractive return compared to the hill on the left. However, if you look at the solution just three bars to the left and right of peak on the right hand hill you will see that the return is less than the return for the solution three bars to the left of the peak solution in the leftmost hill. Not only that but you soon get a zero return if you go further. Whereas you are guaranteed a little return by missing the ideal entry on the leftmost hill.


Another problem you will run into is over-fitting a trading rule to its training data. Leave a genetic algorithm (GA) to run long enough and you will get a rule that gives an astounding return on investment but will only trade a few times given many hundreds of training examples. You can be sure in this case that the GA is over-fitted and may not work on test data or actual trading.

You might want to select one of your earlier solutions that gives a much lower rate of return but has enough leeway to soak up slippage and other trading errors. This will give you more trades and more certainty that the GA has learnt something.

In conclusion I would suggest using AI sparingly and be fully understanding of the underlying maths. As I have said there is no magic. You will find the same solutions to a problem with a brute force approach, given enough time. The most important thing is determining what problem you are trying to solve and understanding the results of your work. That requires mathematical skills that cannot be avoided.

When Reality Becomes Fantasy

There are many websites created by sports and financial traders. Many, unlike mine, like to report (boast?) their winnings but rarely their losses. Why might that be? I never discuss the details of my trades because winning strategies are hard to come by. Share a winner and it becomes a loser because the market will arbitrage the edge out of it.

Nobody is 100% successful when it comes to trading. Nobody likes to lose but there will be inevitable losses. Trading is not about finding winners, it is about finding edge. That is a subtle difference that many beginners do not appreciate. As stated, nobody is 100% correct in their decision making. You need to make sure that your winnings over-compensate for your losses and that is where edge is all important.

I see many websites come and go and even come back again (some people never learn). Boasts about conquering sports and financials (usually the forex markets, for some reason) abound when most traders specialise in just one or two sports or financial markets and rarely both sports and financials. After all, if you are that good at financial trading why waste your time with sports trading?

Bankrolls are repeatedly lost without a reason given or they are modified to hide losses. That is assuming that the figures you are reading are truthful. Once you have started to broadcast to the general public your initial success it is difficult to admit that you are wrong in the future when your luck runs out and the law of large numbers drags your bankroll down.

These action gamblers jump from one strategy to the next, none of them back-tested. All are hunches with no edge. The "trader" will announce that in so many months they will be independently wealthy (presumably an old aunt is about to die and cough up her estate) or they will set themselves the task of winning X amount in so many weeks. The sure sign of someone who hasn't the slightest idea of what they are doing.

Don't be an action gambler. Learn how to trade properly. Learn how markets work and how to build strategies with positive edge. Most strategies for sale are losing ones (see Buchdahl) and the only profit in them is the money the creator gets from selling these strategies to mugs. You will have to create strategies yourself; either by becoming a fundamental trader (learning how to understand past performance and creating your own odds) or as a technical trader (trading the prices) or a combination of the two.

There are no short-cuts to becoming a trader and reading a dodgy website is not going to make things any easier. Reading those websites will see you entering the same fantasy land as the creator of the dodgy website. Remember, 90% of traders are losing traders. Many amongst the other 10% barely break-even. It takes a lot of hard work just not to be a losing trader and the task gets harder each year. The reality of many trading websites is purely fantasy.