Mathematical and Programming Skills for Sports Trading

I received a question in the comments section of my previous article, Change Your Environment to Promote Success, about the level of mathematics knowledge required to be a sports trader. My answer was so long that I decided to write this article with it. The question was a difficult one to answer because sports trading has many entry points, some requiring a lot of mathematical skill and some requiring less mathematical skill but still a lot of common sense. I could talk in terms of academic qualifications but judging by the commenter's use of the term "math" rather than "maths", as we say in the UK, means that the questioner's education system is probably different to the one I went through and so I will answer the question in more general terms.

The commenter asked
But where to start and find reliable learning sources for improving math skills, should I first remind myself with high school basics and gradually go towards more complex math,what do you think how should I organize my learning,having in mind that I only know basic math(maybe little bit better but lets say just basics is with what I am completly proficient),but never had problems with understanding math concepts,or some kind of math fobia,so question is how and where to start in that way that my learning would be really fruitul,applicable?And one more question do you think it is wise first to get decent math knowledge as a foundation prior to learning programming? Thanks in advance.
There is the gambling quote, "I'd rather be lucky than good," which means so long as you are making money then why worry. If you are making money with little academic acheivement and you like what you are doing then it is quite all right to not want to put any extra baggage in your mind. After all, you are unlikely to use it.

Some people can start off in sports trading and make a profit without really knowing what they are doing. Either they have some latent talent that cannot be quanitified or they are extremely lucky and the law of large numbers is waiting around a dark corner with a cosh, to mug them of all their winnings.

If the idea of sitting in a chair all day long, looking at screens and making money appeals to you then I suppose sports trading is as good as any other job but for one difference. In any other office job (with the exception of proprietary financial trading) you are being paid by someone else to do the work. As a trader you are being paid by yourself and if you have no talent then you are going to lose money. That talent might be inate or it might be created through study, of which mathematics will play a part.

Recently, there was a short series of programmes on UK television about Corals, a bookmaker. One episode showed one of Corals' high street betting shops and the people that go there to bet. Betting shops in the UK are now permitted to have gaming machines in them. As if fleecing people with overround sports books wasn't enough these gaming machines offer video roulette and other such casino games with which to demonstrate negative edge games to the public. One visitor to the bookmaker wasted his unemployment benefit on a video roulette machine. His lack of simple mathematical skills probably kept him drawing benefit and heading to the the machine. Unfortunately, many people do not understand the concept of edge and lose heavily (what else are they supposed to do?) to these machines.

However, I am not sure that a basic understanding of maths will help those people who gravitate towards gaming machines. As discussed by myself and Casini in Perpetual Change, for some people the laws of probability do not matter to them. Luck will conquer all. It would appear that Steve Jobs is not the only one who enjoyed a reality distortion field. Seeing as these machines only take £1 bets you would have to have an enormous reality distortion field to give you a winning run long enough to make you seriously wealthy. Even in sports trading it is easy to create a spreadsheet showing you how your winnings are going to ramp up and dump you on a sun drenched island in the Pacific. Reality is never like that. All the blogs I come across (including this one) are written by people plugging away in their spare bedroom under dreary UK skies.

I guess the best kind of maths to learn is the kind that shows you what a bad bet looks like. I can't teach anyone how to become rich but I can stop them from losing money. After that it is up to you to decide what you want to learn, depending on the kind of betting/trading that you want to do. I wrote an article on edge, Edge, Expectation and Kelly Criterion, which should explain, in simple terms, how to determine a good bet from a bad one. You can ignore Kelly Criterion, for the time being, as that is more to do with money management. 

When building and evaluating systems, a useful book to have is Joseph Buchdahl's, How To Find a Black Cat in a Coal Cellar. Ostensibly, the book teaches you how to evaluate other people's systems but the mathematics within can help you to evaluate your systems too. The particular branch of mathematics used by Buchdahl is statistics and probability theory. If you want to read up on maths that is of use to a sports trader then that area of maths is the place to start your reading. 

Any books that take you up to what we would call in the UK an A-Level standard (pre-university level) in statistics and probability would suffice. I don't think that not having a mathematics qualification as a school leaver will stand in your way, if you are really interested in becoming a sports trader. We have all wondered, as school children, what the point was of learning maths that had nothing to do with the world around us. Eventually, though, some of us will want to fill our world with things that have mathematical properties and maths is the tool that helps us to understand those mathematical properties.

The things you need to learn are :-

 - How do markets work? The battle between backers and layers. Each side wanting to make money, tugging prices one way and the other. 

- Price oscillation as the market determines the price through the Wisdom of the Crowd. Trends created when prices relax as the book becomes less overround or as momentum is created through new information entering the market.

- The effect of late breaking and inside information on prices.

- The roundness of the book. Odds can be converted to probabilities - 100% is a round book. >100% is overround and erodes betting profitability.

- Determing when you have an edge. When betting, is the price right? When trading, is the price going to move in the direction you think it will move?

 - Mathematics for system building. Charting, simple statisitcs for building your own metrics. A few select charting techniques used in financial trading - e.g. the moving average and volume analysis.

- Money management. Making the most of an edge. Losing as little as possible when that edge turns negative.

Your interests will determine what you want to learn. Gathering data, spreadsheeting and charting it will make you ask questions. Those questions might require you to research on the web for a mathematical skill or tool to help you answer the questions. Research plays a large part in sports trading. An enquiring mind and a search engine can go a long way.

As far as programming is concerned, it always annoys me when someone asks, "Which language do you like/usually program in?" It's a silly question. If you can program then you shoud be able to program in any language, after suitable conversion. All pogramming languages are based on logic and so I would recommend a basic understanding of predicate calculus. That's rather old school and probably today's programmers learn Python, have no idea what predicate calculus is and refuse to program in any other language. 

Still, thinking logically is the only way to write a computer program and not a course on a specific language. Programming is an art, more than a science and whatever programming your teacher teaches you then you will find another way. If you have never programmed before then you can't go wrong with Visual Basic and any beginner's book. However, like carpentry, you don't go to college to learn hammers or chisels. You learn how to be a carpenter, develop skills and use the appropriate tools.

i 8 sum pi and it was delicious

Further Reading

Change Your Environment to Promote Success

I ran into an interesting article about the environment affecting behaviour. From the moment we are born our environment acts like a mould, shaping our future self. I remember seeing an episode of Horizon discussing criminality, genetics and the environment. An example from the programme showed that a person may be genetically pre-disposed with psychopathic tendencies that could lead to a life of crime, but if that person was born into a loving and caring family then the worst they might ever be is a bit of an annoying control freak and nothing more.

In recent articles I have detailed my hardware set-up and the difficulty I have been having with my eyesight. Undoubtedly, sitting in front of a monitor all day and night is not a healthy activity. My eyesight has suffered and my general health too. I was a member of a tennis club until I decided to concentrate on completing my book earlier in the year. I haven't played tennis since the autumn of 2014 and so I need to think about joining a club again. As things are I get no exercise other than an occasional walk to the supermarket.

After getting my glasses prescription I realised that the glasses alone would not help my eye strain. The glasses are only good for reading and these days most of my reading is done from a screen with only a little book, tablet or Kindle reading. I decided therefore to change my working environment by setting the monitor further back, altering the monitor's brightness and contrast, changing the font size and trying to spend less time sitting in front of the monitor. It is too early to say if it has made any difference. I have thought about bifocal lenses but for now I won't get them.

The article I read on behaviour and environment, entitled The Most Effective Way to Change Your Behaviour and Improve Your Life goes further. Your environment affects the way you think, which I can vouch for after making bad trading decisions when hungry, angry or pre-occupied with thoughts not relavent to my trading activity and so on. This is what makes us human and why machines struggle to replicate human behaviour. A machine intelligence makes optimal decisions and then acts upon them. Humans are often "satisficing" (sufficing with decisions that satisfy a need) or thinking on the fly. That is why I use bots to trade with now. A bot doesn't get hungry or angry or worry about anything other than what you programmed it do. Just make sure you program the bot when your attention is fully focused on the task.

A quote I liked from the article was

We are often lazy creatures of habit, strongly influenced by the world around us. We don’t even use our leisure time to do what we really enjoy, we do what’s easiest. And without a prod we don’t do the ethical thing, we do what’s convenient.

I know that I can get stuck in a rut very easily. My rut can be very comfortable but if I don't get out of it then I know greater success will elude me. How about you? Do you keep promising yourself to learn to program but end up sticking to some simple half-working manual trading idea that only earns peanuts? Are you fearful of improving your mathematical knowledge because of a fear of failure?

This morning I realised that 20 years have passed since I graduated. There has been some hardship along the way, many bad decisions but also a number of successes. I decided to write down all the good and bad things over the past two decades. I won't share them with you as some of the things are rather personal but amongst them were things that I can be proud of. I need to create an environment that will promote more success and avoid  failure as best as I can. It is better to try and fail than not to have tried at all.

Trading Hardware

Following the publication of my book, Programming for Betfair, I have had a few emails asking about my hardware set-up. My set-up is quite simple due to the fact that I am not an in-play trader. I have just two monitor screens. There is no live feed on a monitor or television screen as I am out of the markets before they go-in-play. The second monitor is only used when the first screen is full and I need the extra space on which to spread my work out. The second screen also permits me to monitor bots trading on one screen and do research and development on the other

An algorithmic trader using bots could easily make do with a single screen. The item hiding under the plastic bag on the right of the picture is a laser printer. The bag keeps the dust off.

The rest of my hardware is kept in a rackmount system. I like rackmount as I can hide everything in a cabinet and keep it reasonably dust free. I am rather prone to dust; pollen in the summer and dust in the winter has me reaching for the antihistamines. The cabinet is a short style 19-inch rackmount cabinet, the type used for telecomms equipment rather than servers, which tend to be in much deeper cabinets that take up too much floor space. The shorter telecomms cabinets are ideal for installing short ITX cases. The particular rack case that I use is a 1.5U case. I did have a 1U case but that required a blower to keep the CPU cool rather than a fan. Blowers are very noisy and I don't recommend them for home offices. They are better suited to data centres. The 1.5U case will only take one 3.5 inch or two 2.5 inch hard drives so I use external drives on a shelf above for additional storage.

I will probably put another machine in the rack in the near future. I am not keen on upgrading to Windows 10 although it looks as though Microsoft will soon change Windows 10 from an optional upgrade to a required upgrade. If I don't like what I see then I will probably go back to Linux. Now that Betfair uses JSON rather than SOAP through which to provide data I shouldn't have any problems with coding a price server and bot platform for Linux. When I last used Betfair's old API-6 on Linux the task was not a pleasant one. I like things that work out of the box. With Linux there is so much gluing to do.

The processor on my ITX motherboard is an Intel i7-3770K with four cores running at 3.5 Ghz and is still quite high up on the CPU benchmark website. There are some six core Intels now on the market, which are only a little more expensive than the price I paid for my processor two years ago that are a little more capable than my machine. Still, I am happy with my system as it can grab data for all the day's races and process it in under a second, which is good enough for the trading algorithms that I use.

As mentioned, I have used the Linux operating system in the past but I ended up dumping it. I don't like bolting things on and then tweaking them to get them running perfectly, which was what I always seem to be doing on Linux. For all its faults Windows is very much plug and play. That goes forMicrosoft's Visual Studio programming environment too where I can create applications without having to worry about incompatibilities. And so I am caught in a quandry, preferring Microsoft for programming but not wanting to get caught up in whatever Microsoft has planned for the future.

I use the the 64-bit version of Windows 7. The Windows 10 upgrade icon sits on my taskbar but I have not been tempted to click it. It would appear that Microsoft is following other operating system vendors in monetising all aspects of an operating system with micro-payments here and there for everything. I regard micro-payments as another tax on stupidity, along with the lottery and mobile phone contracts. I am not a youngster who has been brainwashed into accepting micro-payments for everything. I believe in applying money management principles to all aspects of my daily life. I have a pay as you go phone but never call out with it. Email and free VoIP (voice over IP) are my preferred methods of communication. I have no television, no satellite receiver and no license fee compelling me to be brainwashed with BBC propaganda.

Currently, I program with Visual Studio Community Edition 2015, which allows me to code applications in BASIC, C++, C#, Python and F#. If I move over to Linux again then I will port my code to the Mono environment. As I have already said, that shouldn't be too problematic with API-NG's JSON based system. I will probably build another machine to run alongside the Windows 7 (assuming it has not been shutdown by Microsoft) machine rather than dual booting. There is plenty of room in the rack for more cases. I use PlusNet as my ISP and then only the slowest broadband option. This is fine for my needs as there is no other activity during trading. No downloads or media consumption to slow things down or risk being throttled by my ISP.

On my desk you can see lots of scrap paper, pens and pencils. This is for writing down ideas, which I can then research, test and implement. Whilst monitoring markets I watch for anomalies to exploit, novice bots being tested and more professional concerns to see what they are up to. The markets are constantly in flux and you have to be alert to new openings as once profitable areas dry up in liquidity.

My glasses are useless

The glasses are fine for reading so the prescription is correct. It's just that they are useless for computer work, of which excessive amounts of time in front of a monitor caused my layoff. I was recommended to sit closer to the monitor but at the range at which the glasses begin to work I am too close to the screen and cannot see all of it at once. If I continue in that manner then I could well end up like the actor in the picture, left (Ben Turpin for those of you under 100 years of age.)

I have resorted to moving the screen further away so that my eyes don't get tired from working too hard at focussing. The glasses I just use for reading things in my hands; books, fiddling with electronics and so on. I am having to take rest breaks, which I never like to do once I get into the flow of things. There is the 20-20-20 rule; every 20 minutes take a 20 second break to look at something 20 feet away. By the time I notice the time, an hour or more might have passed. I am just too used to pushing myself past the pain and continuing to look through squinted eyes.

My work output has decreased a lot in the past month but I will gradually increase it again. However, I am not sure that I can work at the level I once did before the eyestrain. It's a case of quality over quantity, concentrating on the next book more than anything else. Some coding and research when I am up to it. Thanks to all those who wished me well.

The Punter's Love-In

I don't know what it is about me and Cassini these days but we appear drawn to each others' writings on a daily basis. Obviously some sort of mid-life crisis. Tongues will begin to start wagging and a wife will start to get worried. Thankfully, I unloaded my wife a number of years ago so it is Mrs Cassini who will have to be placated.

Anyway, the Cassini/de Fermat Butler love-in continues with Cassini's latest post, which mentions The Punter's Revenge, a seminal work for people who were dabbling during the early days of computer aided sports betting during the 1980s. The book mentions BEAGLE (Biological Evolutionary Algorithm Generating Logical Expressions), my first encounter with artificial intelligence and evolutionary computing in particular. 

At the time I first read of BEAGLE I was a student at the then Lancashire Polytechnic (now Central Lancashire University), studying for a combined studies degree in astronomy and computing. I believed myself to be a better computer scientist than astrophysicist so I left the course after passing the first year and worked for a few years before enrolling in an artificial intellgence degree at Essex University.

In all probability I am a better computer scientist than astrophysicist even though I still watch The Sky at Night (it's not quite the same without Sir Patrick) and any cosmology based episode of Horizon. I am woeful at pure mathematics, which seems to trip off the tongue of cosmologists such as Max Tegmark, whose career and mind seem perpetually in outer space (man!). My computing work did help in the creation of the CCFEA (see banner to the right of this article) so I suppose I was good for something. Getting back to The Punter's Revenge, the book is still a good read, even today. I gave the book a partial review during the early days of this website. My copy of the book is coming apart at the seams, as probably myself and Cassini are too but at least we have each other. Sorry Mrs C.

We all have an edge but not always where we imagine it to be

I am reminded by Cassini of a financial trading blog that I have read in the past. TraderFeed is written by Dr. Bret Steenbarger, author of The Psychology of Trading to name but one of many books he has written. I like to read about the psychological aspects of trading because in the past that was my main failing.

Steenbarger's recent post entitled Learning from our Genius -- And Our Idiocy informs us that we are all good at something and pretty rotten at everything else. We need to concentrate on what we are good at and not try to fit ourselves into something for which we are not suited. For example, I have no skills in dancing and consequently, I don't listen to pop music. What would be the point if I did? However, I do see the world as a series of algorithms, which for me is a strength as I am good at analysing data and looking for patterns. Any psychologists amongst you have probably made a snap diagnosis. I won't argue with it.

Another thing I am rotten at is thinking off the top of my head. I have an unerring ability to  make  wrong decisions (with no edge in the negation of my decisions, in case you are wondering). Push me into a corner and force me to make a simple decision and my mind clouds over. Question - "James, would you like tea or coffee?" Answer- "Errr. Penguin!

As a trader, the use of subjective trading rules and realtime manual trading (e.g. scalping and other such manual trading techniques) are to be avoided by me. My mind is unable to think on the hoof. I would rather take the time to develop a trading strategy in my own time, convert it into an algorithm and get a bot to trade the rule impassionately. Of course, that removes a whole subset of manual trades from my portfolio but for me those trades would be losing trades anyway.

If you are just starting out as a sports trader then I would suggest you try a little of everything to find your niche. Find the sport that suits you, be it in-play or pre-event trading. Try manual trading and algorithmic trading. If you have no mathematical or statistical skills but have some God-given skill at looking at the flow of funds entering and leaving a market then maybe scalping is for you and algorithmic trading isn't. Those who have good mathematical skills but no ability to create trading algorithms (they do exist) evaluate other people's trading rules (known as advisories) and build a portfolio of them into which they invest their money.

When I first started out as a sports trader, I did as everyone else did. I looked at the scalping videos, got the third-party trading software and made a hole in my bankroll. For me, every situation looked tradable. Thankfully, my analytic side noticed the dwindling bankroll and decided that whatever I was doing had a negative edge. I left the trading to analysis and algorithms and reversed the loss.

We are all good at something, as Steenbarger says. Don't try and force yourself to be do something you are no good at. Even if it means giving up sports trading altogether. At least you will gain an edge with regard to determining which asset class you shouldn't be investing in.

Some blogs I read

To be precise, the only two sports betting blogs I read. Whilst recovering from eyestrain, waiting for a glasses prescription to be completed and for an appointment with an opthalmologist, I have tried to stay away from monitor screens. I can't even do my hobby, which is microelectronics, as the damned components are too small. I am building a modular anaolgue synthesizer but I keep jabbing the soldering iron into my free hand because I can't see what I'm doing.

To alleviate some boredom I have read a little but only in short bursts. Thankfully, I don't get as much email regarding my book Programming for Betfair as I used to now that Betfair has stopped changing things on the server side and the book's addenda is complete. I have done a little catch-up reading of the two sports betting blogs that I read. I don't read the majority of sports betting blogs as they are quite dull, especially thre profit and loss type. They all remind me of Jimmy Cagney standing on top of a gas storage tank in the 1949 gangster movie White Heat, shouting, "Made it, Ma! Top of the world!" just before the tank blows up taking Jimmy with it.

"Ma! I just hit a losing streak!"

Many profit and loss blogs are here today and gone tomorrow, rather like Mr Cagney in White Heat. They have nothing to offer but boasts and not much else. Certainly they don't help aspiring bettors and traders. I don't like them because they make sports betting look easy when it is anything but that. I worry that people with little finances and less intellect will gamble all their money away if they imagine that sports trading offers untold wealth. Yes, I understand that adults have every right to blow their money on anything they want. I just don't think I could stomach someone reading something I wrote, betting their livelihood on it and losing everything.

The sports betting blogs that I do read are not of the profit and loss type. Those blogs are Green All Over and Sports Trader. Neither of them have anything to sell, be it tips, courses or merchandise. I have had a few mentions from Cassini, the nom de plume of Green All Over and here I return the compliment. I can't say that I am all that interested in association football or baseball but I do like the analysis of a sport and the modelling of a trading strategy, which Cassini so eloquently does with his wig and pen. Also, Green All Over contains a lot of philosophy of sports trading that I enjoy reading, mixed in with off-topic and more general investment content. 

I notice in Cassini's reading list that like myself he reads Zero Hedge, a news website for people who don't trust anyone in the establishment, be they politicians, bankers or the well-healed. There are some interesting articles on Zero Hedge that give a different slant to our own propaganda media outlets on poltics, finance and economics. However, you have to read Zero Hedge with a barrow load of salt as most of it is just contrarianism. The comments section of each post seems to be populated by red-necks and people of low intellect so that part of Zero Hedge is best ignored.

Sports Trader, written by Matekus, another nom de plume, only writes half a dozen times a year but each post is a gem with the two most recent posts entitled Volatility Drag As Time Averaging and Doubling Rate Entropy and Kullback-Leibler Divergence. The posts of Matekus are impenetrable to those without sufficient maths and finance knowledge but thought provoking if you do understand the posts.

Matekus is a bit of an enigma in that he has a lot of interest in US horse racing (he has written about horse racing with a US perspective on US horse racing forums) and yet I have tracked Matekus down to the Bet Angel forum and his blog has a ending so I am guessing that he is English. He would also appear to be from a finance background. The articles on Sports Trader tend to cover the fundamental side of sports trading  (not something that I do) but the articles do make me think about new avenues of research. Again there is no mention of winnings or losses. I can only imagine that such attention to detail has been rewarded with some profit.

So there you have it. I read just two sports betting blogs that make me think rather than make me wonder why I am not making obscene amounts of money like the P&L blogs, which is probably just as well as I doubt that most of the P&L blogs are telling the whole truth.