<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7538904595934077017</id><updated>2012-02-11T02:36:09.618-08:00</updated><category term='Eclipse BIRT'/><category term='CXF'/><category term='stochastic optimisation'/><category term='Genetic algorithm'/><category term='Real-time'/><category term='virtual money'/><category term='heat map'/><category term='research'/><category term='simulator'/><category term='Price'/><category term='Javascript'/><category term='trading'/><category term='Apache SCXML'/><category term='SCALA'/><category term='Probability'/><category term='Reinforcement learning'/><category term='Java'/><category term='game'/><category term='BetFair'/><category term='android'/><category term='Maven'/><category term='Evolutionary algorithm'/><category term='Betfair API'/><category term='Betting exchange'/><category term='Spring'/><category term='Neural Networks'/><title type='text'>Betting Exchange Research Blog</title><subtitle type='html'>A mixture of information technology, betting exchange and artificial intelligence</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.danmachine.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>20</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-6879714003146028938</id><published>2012-02-04T01:29:00.000-08:00</published><updated>2012-02-06T09:56:49.781-08:00</updated><title type='text'>On probability of winning a tennis match</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I present end to end solution for predicting a winner of ATP tennis match from names of both tennis players, surface and match type.&amp;nbsp;I start with presenting requirements for tennis predictions, then I&amp;nbsp;discuss&amp;nbsp;mathematical model applied for predicting a winner of tennis match, followed by software design and implementation of prediction application.&amp;nbsp;Validating accuracy of tennis prediction models formulates a topic of my future work on tennis markets.&lt;br /&gt;&lt;br /&gt;The product of my efforts presented here is a software library written in Scala programming language, which calculates probability of winning a tennis match. This library is open sourced and it is&amp;nbsp;publicly&amp;nbsp;available on GitHub. If you want to play with it, I recommended starting with unit tests, which should make it a little more clear how to use it.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;a href="https://github.com/danielkorzekwa/tennis-player-compare"&gt;https://github.com/danielkorzekwa/tennis-player-compare&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/danielkorzekwa/tennis-probability-calculator"&gt;https://github.com/danielkorzekwa/tennis-probability-calculator&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/danielkorzekwa/atpworldtour-api"&gt;https://github.com/danielkorzekwa/atpworldtour-api&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;Requirements&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Tennis prediction application is intended for supporting trading decisions on a Betfair betting exchange markets.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;User story:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;As a trader,&lt;br /&gt;I want to calculate probability of winning a tennis match,&lt;br /&gt;so that I can support my trading decisions.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Input:&lt;/b&gt;&lt;br /&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;Full names of tennis players, e.g. Roger Federer and Milos Raonic. ATP players only.&lt;/li&gt;&lt;li&gt;Court surface - CLAY, GRASS, HARD.&lt;/li&gt;&lt;li&gt;Match type - THREE_SET_MATCH, FIVE_SET_MATCH.&lt;/li&gt;&lt;li&gt;Prediction year - For calculating tennis probability for the current day, specify the current year (2012). To obtain tennis probability at the end of the past year, specify a year from the past, e.g. 2011. In the future, trader would like to specify a full date for prediction, either from the past, e.g. 2 year ago, or from the future, e.g. in 6 months.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;Probability of winning a tennis match for the first specified tennis player - It is a number between 0 and 1 (probability). Probability of winning a tennis match by the second player is 1-probability.&lt;/li&gt;&lt;/ul&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;Error should be reported if probability cannot be calculated. For example, if a player is not recorded on&amp;nbsp;&lt;a href="http://www.atpworldtour.com/"&gt;http://www.atpworldtour.com/&lt;/a&gt;&amp;nbsp;website.&lt;/li&gt;&lt;/ul&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;In the future, trader may want to know what is the confidence level of winning probability. Consider two games for the same player P1 against players P2 and P3. The probability of winning the game by player P1 against players P2 and P3 may be the same value of 0.4. But it may happen that the player P3 hasn't played any tennis match for last 3 months, which potentially could make us less confident about prediction for a game including this player. Trader would like to know about it. In other words, the probability of winning a game should be defined by two numbers, probability and a confidence level, possibly as a&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Normal_distribution"&gt;http://en.wikipedia.org/wiki/Normal_distribution&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;Tennis prediction model&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I considered a few different prediction methods for calculating probability of winning a tennis match, which could be classified into three categories:&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Predicting tennis outcome from probabilities of winning a point on serve and serve return by both players. Modelling a tennis game as a&amp;nbsp;&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Markov_chain"&gt;finite markov chain&lt;/a&gt;.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www1.fee.uva.nl/pp/klaassen/index_files%5Ciid.pdf"&gt;Klaassen, Magnus - 2001 - Are Points in Tennis Independent and Identically Distributed Evidence From a Dynamic Binary Panel Data Model&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://researchbank.swinburne.edu.au/vital/access/manager/Repository/swin:1559?query=+Combining+player+statistics+to+predict+outcomes+of+tennis+matches&amp;amp;y=0&amp;amp;x=0"&gt;Barnett, Clarke - 2005 - Combining player statistics to predict outcomes of tennis matches&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://researchbank.swinburne.edu.au/vital/access/manager/Repository/swin:220"&gt;Barnett, Brown, Clarke - 2006 - Developing a model that reflects outcomes of tennis matches&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://ideas.repec.org/a/bpj/jqsprt/v4y2008i2n15.html"&gt;O'Malley - 2008 - Probability Formulas and Statistical Analysis in Tennis&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://ideas.repec.org/a/bpj/jqsprt/v5y2009i3n7.html"&gt;Newton, Aslam - 2009 - Monte Carlo Tennis A Stochastic Markov Chain Model&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Neural networks. Predicting market outcome from tennis player statistics including percentage of first serve, winning percentage on the first serve return and few others.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.iaeng.org/publication/IMECS2009/IMECS2009_pp127-132.pdf"&gt;Somboonphokkaphan - 2009 - Tennis Winner Prediction based on Time-Series History with Neural Modeling&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Official ATP ratings and logistic regression.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://researchbank.swinburne.edu.au/vital/access/manager/Repository/swin:789?query=Using+official+ratings+to+simulate+major+tennis+tournaments&amp;amp;y=0&amp;amp;x=0"&gt;Clarke, Dyte - 2000 - Using official ratings to simulate major tennis tournaments&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.janmagnus.nl/papers/JRM065.pdf"&gt;Klaassen - 2003 - Forecasting the winner of a tennis match&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;I rejected prediction methods based on ATP ratings and logistic regression, which predict match winner from historical match outcomes, not taking into account probabilities of winning a tennis point. I believe the more data the better - there are far more points than matches played in tennis. Nonetheless, I still can see a value in applying logistic regression on top of probabilistic model. For instance, probabilistic model might be used for generating ratings for tennis players, which could be fit with logistic regression into tennis probability function.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;From both neural network and markov chain methods I prefer the latter, because it allows for modelling probability of winning a tennis match with two numbers: &amp;nbsp;probability and uncertainty level, modeled as 'mean' and standard deviation&amp;nbsp;respectively&amp;nbsp;(&lt;a href="http://en.wikipedia.org/wiki/Normal_distribution"&gt;http://en.wikipedia.org/wiki/Normal_distribution&lt;/a&gt;). This lets to differentiate between two players with similar probability of winning a point but with different uncertainty levels, which could be interpreted as player's consistency in a game.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;Eventually, I selected markov chain model, which calculates tennis match winner from probabilities of winning a point on serve and return by both players. Probability of winning a point is calculated from player statistics such as probability of first serve, probability of winning a point on first and second serve and probability of first and second serve return. Then probabilities of winning a game, set, tiebreak and match are calculated. My implementation of this prediction model is based on those two research papers:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://ideas.repec.org/a/bpj/jqsprt/v4y2008i2n15.html"&gt;O'Malley - 2008 - Probability Formulas and Statistical Analysis in Tennis&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://ideas.repec.org/a/bpj/jqsprt/v5y2009i3n7.html"&gt;Newton, Aslam - 2009 - Monte Carlo Tennis A Stochastic Markov Chain Model&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Accuracy of this model depends on two factors. First, probability of winning a point on serve by both players must be precise. Every precision error at this level propagates down through probabilities of winning a tennis game, set and match.&lt;br /&gt;&lt;br /&gt;Second, the algorithm for calculating game, set and match probabilities, which is based on&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Markov_chain"&gt;markov chain&lt;/a&gt;, makes assumption that points in tennis match are&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Normal_distribution"&gt;independently and&amp;nbsp;identically distributed&lt;/a&gt;. In other words, whether the probability of winning every point on serve by a player in a tennis match is constant or maybe it depends on a current score or who won last couple of points.&amp;nbsp;&amp;nbsp;Klassen and Magnum show in their paper (&lt;a href="http://www1.fee.uva.nl/pp/klaassen/index_files%5Ciid.pdf"&gt;Klaassen, Magnus - 2001 - Are Points in Tennis Independent and Identically distributed Evidence From a Dynamic Binary Panel Data Model&lt;/a&gt;), that points are not independent and identically distributed, however deviations are small and making this idd assumption should be fine in many use cases. How making this assumption impacts trader's needs for precise tennis predictions, I don't know yet.&lt;br /&gt;&lt;br /&gt;I'm not expecting this model to be very accurate, at least in its generic form, where probability of winning a point is derived purely from percentages of points won on serve and return by both players and by 'average player'. I implemented it to get some reference point I can compare other models with. I'm planning to discount most recent tennis matches less and I also want to compare it with Bradley-Terry, Elo, Glicko and TrueSkill models.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="font-size: large;"&gt;Design and implementation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There are three dedicated components contributing to functionality of comparing ATP tennis players: tennis-trader-compare, atpworldtour-api and tennis-probability-calculator.&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-Aubx-Zrtql0/Tx2EAe2yo3I/AAAAAAAAIDs/PlqD5okJfxA/s1600/Comparing+ATP+players_component.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="272" src="http://2.bp.blogspot.com/-Aubx-Zrtql0/Tx2EAe2yo3I/AAAAAAAAIDs/PlqD5okJfxA/s320/Comparing+ATP+players_component.jpg" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Component diagram for comparing ATP tennis players&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;The tennis-trader-compare component provides a high level interface for predicting outcome of tennis match.&amp;nbsp;&lt;a href="https://gist.github.com/1671926/d4ab720159bbecd19c478e047edf7eba0b836671"&gt;Interface definition&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The atpworldtour-api is an adapter for&amp;nbsp;&lt;a href="http://www.atpworldtour.com/"&gt;http://www.atpworldtour.com/&lt;/a&gt;&amp;nbsp;tennis statistics, which are used for calculating probability of winning a tennis point. &lt;a href="https://gist.github.com/1671913/1d11e7935c79cc5c36cf5b0c71accb735b2817fd"&gt;Interface definition.&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;Tennis-probability-calculator contains functions for calculating probability of winning a point, gem, set, tie break and tennis match. &lt;a href="https://gist.github.com/1671919/60919a394b4141a9c519aeb601a3d4ed0de886fe"&gt;Interface definition.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Flow of control&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-GyEoA57rRiE/Tx2EA_-MZ4I/AAAAAAAAIDw/C_MGLOeq2r0/s1600/Comparing+ATP+players_seq.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="205" src="http://2.bp.blogspot.com/-GyEoA57rRiE/Tx2EA_-MZ4I/AAAAAAAAIDw/C_MGLOeq2r0/s320/Comparing+ATP+players_seq.jpg" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Sequence diagram for comparing ATP tennis players&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Trader calls tennis-trader-compare with player full names, surface, match type and prediction year and receives&amp;nbsp;probability of winning a tennis match.&lt;/li&gt;&lt;li&gt;Tennis-trader-compare component obtains ATP match facts from&amp;nbsp;atpworldtour-api&amp;nbsp;component, e.g. frst serve %,1st serve point won %,&amp;nbsp;2nd serve point won %.&lt;/li&gt;&lt;li&gt;Tennis-trader-compare calls tennis-probability-calculator to calculate probability of winning a point and tennis match by both players.&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;Resources&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This list below contains additional research papers, which I collected for a purpose of my work described in this blog post.&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;a href="http://researchbank.swinburne.edu.au/vital/access/manager/Repository/swin:789"&gt;Clarke, Dyte - 2000 - Using official ratings to simulate major tennis tournaments&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.strategicgames.com.au/excel.pdf"&gt;Barnett, Clarke - 2002 - Using Microsoft Excel to model a tennis match&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.aenorm.eu/artikelen/47-klaassen.pdf"&gt;Klaassen, Magnus - 2003 - On the probability of winning a tennis match&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://strategicgames.com.au/PhD.pdf"&gt;Barnett - 2006 - MATHEMATICAL MODELLING IN HIERARCHICAL GAMES WITH SPECIFIC REFERENCE TO TENNIS&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://messymatters.com/sharad/papers/tournaments.pdf"&gt;Chen et al. - 2008 - Pricing Combinatorial Markets for Tournaments Extended Abstract&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.doc.ic.ac.uk/teaching/distinguished-projects/2011/x.huang.pdf"&gt;Huang - 2011 - Inferring Tennis Match Progress from In-Play Betting Odds&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-6879714003146028938?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/6879714003146028938/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2012/02/on-probability-of-winning-tennis-match.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/6879714003146028938'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/6879714003146028938'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2012/02/on-probability-of-winning-tennis-match.html' title='On probability of winning a tennis match'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-Aubx-Zrtql0/Tx2EAe2yo3I/AAAAAAAAIDs/PlqD5okJfxA/s72-c/Comparing+ATP+players_component.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-6952253780207359330</id><published>2012-01-11T22:23:00.000-08:00</published><updated>2012-01-13T05:22:41.098-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='trading'/><category scheme='http://www.blogger.com/atom/ns#' term='Genetic algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='Betting exchange'/><category scheme='http://www.blogger.com/atom/ns#' term='Reinforcement learning'/><category scheme='http://www.blogger.com/atom/ns#' term='Neural Networks'/><category scheme='http://www.blogger.com/atom/ns#' term='Evolutionary algorithm'/><title type='text'>Neural Networks and Genetic Algorithm in trading on a Betting Exchange</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This is a report on learning neural networks for trading on betting exchange horse racing markets.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/Neural_network"&gt;Neural Network [1]&lt;/a&gt; was learned using &lt;a href="http://blog.danmachine.com/2010/08/horse-racing-market-simulation.html"&gt;Market Simulator [2]&lt;/a&gt; with data collected for a period of 3 months between January and April 2011 for Horse Racing GB win only markets, which allows for replaying betting exchange market on a betting exchange and evaluating trading decisions.&lt;br /&gt;&lt;br /&gt;Example of collected market data:&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;{"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"}]}&lt;br /&gt;{"time":1282481934744,"eventType":"PLACE_BET","betSize":38.0,"betPrice":5.9,"betType":"LAY","marketId":101655582,"runnerId":4818333}&lt;br /&gt;...&lt;br /&gt;{"time":1282482515736,"eventType":"PLACE_BET","betSize":314.0,"betPrice":1.61,"betType":"BACK","marketId":101655582,"runnerId":4848193}&lt;br /&gt;{"time":1282482515736,"eventType":"CANCEL_BETS","betsSize":5.0,"betPrice":18.0,"betType":"LAY","marketId":101655582,"runnerId":4932435}&lt;br /&gt;{"time":1282482515736,"eventType":"PLACE_BET","betSize":17.0,"betPrice":20.0,"betType":"LAY","marketId":101655582,"runnerId":4932435}&lt;/blockquote&gt;Collected data included market prices, traded volume, volume of unmatched bets by price, current risk position, but no knowledge from historical market data was taken into account such as how good a given horse is comparing to other horses in a race. The output of neural network was either trading action to be taken in a current state, e.g. place bet, cancel bet, or indicator whether a given action, e.g. place bet (&amp;nbsp;(specified as an input to neural network),&amp;nbsp;is good or not decision.&lt;br /&gt;&lt;br /&gt;Neural Network wasn't learned from examples, as those didn't exists on how to trade in HR markets, but rather than that, it was optimized with &lt;a href="http://en.wikipedia.org/wiki/Genetic_algorithm"&gt;genetic algorithm [3]&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Simulated_annealing"&gt;simulated annealing [4]&lt;/a&gt;. This type of learning neural networks could be perceived as an example of &lt;a href="http://en.wikipedia.org/wiki/Reinforcement_learning"&gt;reinforcement learning [5]&lt;/a&gt; in an environment, in which we don't know how to act to achieve the goal, e.g. what trading decisions should be taken, but we know when we reach the goal, in this case it is positive &lt;a href="http://en.wikipedia.org/wiki/Expected_value"&gt;expected profit [6]&lt;/a&gt; from trading on a betting exchange markets.&lt;br /&gt;&lt;br /&gt;The best instance of learned neural network gives a positive profit per market by average of 5£ including 5% winning commission from trading on HR betting exchange markets. &amp;nbsp;But it also involves a big number of betting transactions, which causes additional transaction fees and takes overall profit per market from 5£ down to 2£. Adding additional costs around setting up hardware, technology and maintenance, limits the usage of presented trading technique to a research activity only. Involving a knowledge gained from historical data potentially could take this technique from a lab project to production ready system.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Neural network structure&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Structure 1:&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;b&gt;Input neurons&lt;/b&gt; - Runner prices, traded volume, unmatched volume, derivatives of price and traded volume, risk position.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Hidden layer&lt;/b&gt; - Single hidden layer.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Output neurons&lt;/b&gt; - Actions to be taken, e.g. 3 neurons: A (place back bet), B (place lay bet), C(place hedge bet).&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;b&gt;Activation function - &lt;/b&gt;Hyperbolic tangent. If output neuron value is higher than 0 then action is taken.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;Structure 2:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Input neurons&lt;/b&gt; -&amp;nbsp;Runner prices, traded volume, unmatched volume&amp;nbsp;, derivatives of price and traded volume, risk position, a proposal for a single action to be taken, e.g. place back bet.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Hidden layer&lt;/b&gt; - Single hidden layer.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Output neuron&lt;/b&gt; - Single neuron indicating how good action specified by an input layer is. Before taking any action, all possible actions are evaluated with neural network and the best one is executed.&lt;/li&gt;&lt;/ul&gt;The latter neural network produces good results (positive profit) faster than the former one, due to a smaller number of weights inside the neural network to be learned.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Learning process&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;First, neural network is initialized with an initial set of random weights, then market simulation is executed evaluating trading quality (market expected profit) of an agent over 100-300 markets. The overall expected profit from all markets is a quality value of a neural network. In the next step, neural network weights are updated applying evolutionary algorithm or simulated annealing and simulation process is repeated. A single learning iteration takes about 1 minute and the whole process took weeks till neural network was trained for giving positive profit. Learning was conducted on Intel Core i7 2.8GHz 8 Cores PC.&lt;br /&gt;&lt;br /&gt;The best learning results were achieved by applying co-evolution version of learning described above, where a number of traders have to fight each other on a betting exchange markets. With this approach weights of best traders are crossed each other by applying genetic algorithm.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-size: large;"&gt;What's next?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the next step I plan to take advantage of a knowledge from historical market data while learning and then executing trading agents. I'm looking at adopting probability theory,&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Bayesian_networks"&gt;Bayesian&amp;nbsp;networks [7]&lt;/a&gt;,&lt;a href="http://en.wikipedia.org/wiki/Logistic_regression"&gt; logistic regression [8]&lt;/a&gt; and other techniques suitable for&amp;nbsp;analysing&amp;nbsp;huge amount of historical market data.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;Notes&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A number of trading examples examined for a purpose of this research work are available here:&lt;br /&gt;&lt;a href="http://code.google.com/p/betting-ai/source/browse/#svn%2Ftrunk%2Ftrader-examples"&gt;http://code.google.com/p/betting-ai/source/browse/#svn%2Ftrunk%2Ftrader-examples&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;All software for a purpose of this project is written in a Scala programming language.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: large;"&gt;References&lt;/span&gt;&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Neural Network -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Neural_network"&gt;http://en.wikipedia.org/wiki/Neural_network&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Market Simulator -&amp;nbsp;&lt;a href="http://blog.danmachine.com/2010/08/horse-racing-market-simulation.html"&gt;http://blog.danmachine.com/2010/08/horse-racing-market-simulation.html&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Genetic algorithm -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Genetic_algorithm"&gt;http://en.wikipedia.org/wiki/Genetic_algorithm&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Simulated annealing -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Simulated_annealing"&gt;http://en.wikipedia.org/wiki/Simulated_annealing&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Reinforcement learning -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Reinforcement_learning"&gt;http://en.wikipedia.org/wiki/Reinforcement_learning&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Expected value -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Expected_value"&gt;http://en.wikipedia.org/wiki/Expected_value&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Bayesian networks -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Bayesian_networks"&gt;http://en.wikipedia.org/wiki/Bayesian_networks&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Logistic regression -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Logistic_regression"&gt;http://en.wikipedia.org/wiki/Logistic_regression&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-6952253780207359330?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/6952253780207359330/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2012/01/neural-networks-and-genetic-algorithm.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/6952253780207359330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/6952253780207359330'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2012/01/neural-networks-and-genetic-algorithm.html' title='Neural Networks and Genetic Algorithm in trading on a Betting Exchange'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-6632105400124624946</id><published>2011-07-29T16:17:00.000-07:00</published><updated>2011-07-29T16:54:59.260-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Real-time'/><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='Betting exchange'/><category scheme='http://www.blogger.com/atom/ns#' term='SCALA'/><category scheme='http://www.blogger.com/atom/ns#' term='virtual money'/><title type='text'>Real-time trading on a betting exchange with virtual money</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div style="text-align: justify;"&gt;Last year I created market data collector and market simulator, then I started analyzing betting exchange markets. Now I developed a computer system which allows for examining markets on a betting exchange&amp;nbsp;real-time&amp;nbsp;using virtual money. As opposed to my historical analysis, which was mostly automated AI aided process, real-time analysis is a purely manual activity.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-FRkNtAOKwWM/TjNE8Jim20I/AAAAAAAADog/XwJ_qdWOujQ/s1600/betex-server_2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="350" src="http://3.bp.blogspot.com/-FRkNtAOKwWM/TjNE8Jim20I/AAAAAAAADog/XwJ_qdWOujQ/s400/betex-server_2.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;Figure 1 Design for real time analysis of betting exchange markets.&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;First I developed betting exchange and I deployed it to Amazon Cloud, it is available at&amp;nbsp;&lt;a href="http://betex.danmachine.com/"&gt;http://betex.danmachine.com&lt;/a&gt;. Then I fed this betting exchange with horse racing real-time&amp;nbsp;market data &amp;nbsp;coming from Betfair betting exchange, so that I could place bets on those markets using virtual money.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;After that I created Google gadgets for displaying real time charts for win and place markets and to be able to place bets on a betting exchange.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-efhw26U25JA/Th8uk-89pLI/AAAAAAAADng/-M7vkmf9Fi4/s1600/betting_dashboard.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="186" src="http://2.bp.blogspot.com/-efhw26U25JA/Th8uk-89pLI/AAAAAAAADng/-M7vkmf9Fi4/s400/betting_dashboard.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;Figure 2 Google dashboard including real time charts for win and place markets and bet placement widget.&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;Having that, I'm able to observe betting exchange markets real-time and place bets not risking real money.&lt;br /&gt;&lt;br /&gt;The key software development technologies I applied are Scala for back-end and Javascript for front-end.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;References&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Betting Exchange Engine -&amp;nbsp;&lt;a href="http://code.google.com/p/betting-exchange/"&gt;http://code.google.com/p/betting-exchange/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Betting Exchange Server -&amp;nbsp;&lt;a href="http://code.google.com/p/betting-exchange-app/"&gt;http://code.google.com/p/betting-exchange-app/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Betting Exchange Feeder -&amp;nbsp;&lt;a href="http://code.google.com/p/betting-exchange-feeder/"&gt;http://code.google.com/p/betting-exchange-feeder/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Market Data Collector -&amp;nbsp;&lt;a href="http://code.google.com/p/betting-exchange-event-collector/"&gt;http://code.google.com/p/betting-exchange-event-collector/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Betting Google Gadgets -&amp;nbsp;&lt;a href="http://code.google.com/p/betting-exchange-google-gadget/"&gt;http://code.google.com/p/betting-exchange-google-gadget/&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-6632105400124624946?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/6632105400124624946/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2011/07/real-time-trading-on-betting-exchange.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/6632105400124624946'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/6632105400124624946'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2011/07/real-time-trading-on-betting-exchange.html' title='Real-time trading on a betting exchange with virtual money'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-FRkNtAOKwWM/TjNE8Jim20I/AAAAAAAADog/XwJ_qdWOujQ/s72-c/betex-server_2.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-2364155058483220633</id><published>2011-03-18T10:54:00.000-07:00</published><updated>2011-04-01T01:37:14.131-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='trading'/><category scheme='http://www.blogger.com/atom/ns#' term='Betting exchange'/><category scheme='http://www.blogger.com/atom/ns#' term='stochastic optimisation'/><title type='text'>Stochastic optimisation in analysing efficiency of betting exchange markets</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div style="text-align: justify;"&gt;Currently, my research is&amp;nbsp;centred&amp;nbsp;around investigating semi-strong form efficiency &lt;a href="http://en.wikipedia.org/wiki/Efficient-market_hypothesis"&gt;[1]&lt;/a&gt; in betting exchange markets. Semi strong efficient market hypothesis says that all&amp;nbsp;publicly&amp;nbsp;available information about the market is reflected in the current market prices.&amp;nbsp;In other words, this hypothesis claims that it is not possible to make a positive profit from a long term betting, having access to all publicly available information, including historical prices trends, traded volume, news from magazines and newspapers, scored goals and red cards in football markets, number of aces in tennis markets, and so on.&lt;br /&gt;&lt;br /&gt;Sometime ago, I reached a point at which my studying of betting exchange markets became complex and time consuming, consequently I decided to introduce stochastic optimisation &lt;a href="http://en.wikipedia.org/wiki/Stochastic_optimization"&gt;[2]&lt;/a&gt;&amp;nbsp;to boost performance of my research. I present, how I was analysing betting exchange markets before and after applying stochastic optimisation.&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Analysing betting exchange markets without adopting stochastic optimisation&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh3.googleusercontent.com/-YRexEHNbJwE/TX_LYYUqK6I/AAAAAAAAAMc/BKIY1Uzu4_Y/s1600/Analysingmarketswithoutadoptingstochasticoptimisation.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="https://lh3.googleusercontent.com/-YRexEHNbJwE/TX_LYYUqK6I/AAAAAAAAAMc/BKIY1Uzu4_Y/s1600/Analysingmarketswithoutadoptingstochasticoptimisation.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;/div&gt;&lt;ul style="text-align: left;"&gt;&lt;li style="text-align: justify;"&gt;&lt;b&gt;Collect event driven market data&lt;/b&gt; - Market data is collected in a form of market events, e.g. PLACE_BET, CANCEL_BET &lt;a href="http://blog.danmachine.com/2010/07/bettingai-market-data-collector-design.html"&gt;[3]&lt;/a&gt;, which is used later for replaying markets with market simulator and betting exchange engine&lt;a href="http://blog.danmachine.com/2010/08/horse-racing-market-simulation.html"&gt; [4]&lt;/a&gt;. At the moment I'm collecting data for horse racing markets 10 minutes before in-play time, but in the future I will probably extend the scope of my research to cover in play football and tennis markets as well.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;ul style="text-align: left;"&gt;&lt;li style="text-align: justify;"&gt;&lt;b&gt;Design trading strategy&lt;/b&gt; - For example, to examine a hypothesis,which says that exchange price movements are correlated with traded volume, I design a trading strategy, which represents this claim. If this trading strategy gives a long term profit, then I could argue that market is inefficient with respect to correlation between price and traded volume.&lt;/li&gt;&lt;/ul&gt;&lt;ul style="text-align: left;"&gt;&lt;li style="text-align: justify;"&gt;&lt;b&gt;Evaluate trading strategy with market simulator and collected market data&lt;/b&gt; - Testing trading strategy on a historical data. At the moment I use data sets of 500 horse racing win markets, 10 minutes before in play time. In the world of financial markets, this phase refers to back testing &lt;a href="http://en.wikipedia.org/wiki/Backtesting"&gt;[5]&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;ul style="text-align: left;"&gt;&lt;li style="text-align: justify;"&gt;&lt;b&gt;Is trading strategy profitable?&lt;/b&gt; - If trading strategy is profitable I claim that market is inefficient and I proceed to prove it by running trading strategy on a real betting exchange markets &lt;a href="http://blog.danmachine.com/2009/04/trading-at-betfair-betting-exchange.html"&gt;[6]&lt;/a&gt;&lt;a href="http://blog.danmachine.com/2009/03/automated-betting-with-betfair-business.html"&gt;[7]&lt;/a&gt;.&amp;nbsp;Otherwise I repeat research process from designing new trading strategy.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;A single research iteration, starting with defining market efficiency hypothesis, then designing trading strategy and evaluating it on market simulator takes a lot of time. It's quite clear that some optimisation process would be helpful to speed up this research process.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Analysing betting exchange markets with adopting stochastic optimisation&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-afJtMzE9U_I/TX_La5zzhJI/AAAAAAAAAMg/nrtGKV9rC4U/s1600/Analysingmarketswithadoptingstochasticoptimisation.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="https://lh6.googleusercontent.com/-afJtMzE9U_I/TX_La5zzhJI/AAAAAAAAAMg/nrtGKV9rC4U/s1600/Analysingmarketswithadoptingstochasticoptimisation.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;This version of a process for analysing betting exchange markets introduces one additional step, which is responsible for improving trading strategy applying stochastic algorithms. Consider a trading strategy which places a bet using simple if-else rule:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;i&gt;if(runner.price &amp;gt; betPrice) placeBackBet else placeLayBet.&lt;/i&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;In this example, stochastic optimisation is looking for the value of the betPrice parameter, for which trading strategy gives the highest possible profit. In reality, trading strategies are&amp;nbsp;parametrised&amp;nbsp;with multiple factors, which makes it much harder and time consuming to search for the best solution in a multi dimensional space. At the moment I use 'co-evolution gradient ascent with random restarts' algorithm, which is described in Essentials of&amp;nbsp;Meta-heuristics&amp;nbsp;book &lt;a href="http://www.goodreads.com/book/show/9734814-essentials-of-metaheuristics"&gt;[8]&lt;/a&gt;. Still,&amp;nbsp;there are other types of optimisation in my scope of interest, including other evolution algorithms and genetic programming.&lt;br /&gt;&lt;br /&gt;I use two separate market data sets for stochastic optimisation and evaluating optimised trading strategy with market simulator. Both sets contain about 500 markets each.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;For more information on how I use stochastic optimisation in practice please look at the following unit tests in Scala:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;ul&gt;&lt;li style="text-align: left;"&gt;Optimising single dimension trading strategy -&amp;nbsp;&lt;a href="http://code.google.com/p/betting-ai/source/browse/tags/betting-ai-1.3/trading-optimiser/src/test/scala/dk/bettingai/tradingoptimiser/CoevolutionHillClimbingTest.scala"&gt;http://code.google.com/p/betting-ai/source/browse/tags/betting-ai-1.3/trading-optimiser/src/test/scala/dk/bettingai/tradingoptimiser/CoevolutionHillClimbingTest.scala&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Optimising&amp;nbsp;multi dimensional trading strategy -&amp;nbsp;&lt;a href="http://code.google.com/p/betting-ai/source/browse/tags/betting-ai-1.3/trader-examples/src/test/scala/dk/bettingai/trader/pricepriceslope/PricePriceSlopeTraderRandomTest.scala"&gt;http://code.google.com/p/betting-ai/source/browse/tags/betting-ai-1.3/trader-examples/src/test/scala/dk/bettingai/trader/pricepriceslope/PricePriceSlopeTraderRandomTest.scala&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;References&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ol&gt;&lt;li style="text-align: left;"&gt;Semi-strong form efficiency -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Efficient-market_hypothesis"&gt;http://en.wikipedia.org/wiki/Efficient-market_hypothesis&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Stochastic optimisation -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Stochastic_optimization"&gt;http://en.wikipedia.org/wiki/Stochastic_optimization&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Design of event driven market data collector -&amp;nbsp;&lt;a href="http://blog.danmachine.com/2010/07/bettingai-market-data-collector-design.html"&gt;http://blog.danmachine.com/2010/07/bettingai-market-data-collector-design.html&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Replaying horse racing markets with market simulator -&amp;nbsp;&lt;a href="http://blog.danmachine.com/2010/08/horse-racing-market-simulation.html"&gt;http://blog.danmachine.com/2010/08/horse-racing-market-simulation.html&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Trading on a Betfair Betting Exchange with Apache SCXML-&amp;nbsp;&lt;a href="http://blog.danmachine.com/2009/04/trading-at-betfair-betting-exchange.html"&gt;http://blog.danmachine.com/2009/04/trading-at-betfair-betting-exchange.html&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Back testing -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Backtesting"&gt;http://en.wikipedia.org/wiki/Backtesting&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Automated betting with BetFair, Business Intelligence and Eclipse BIRT -&amp;nbsp;&lt;a href="http://blog.danmachine.com/2009/03/automated-betting-with-betfair-business.html"&gt;http://blog.danmachine.com/2009/03/automated-betting-with-betfair-business.html&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Essentials of metaheuristics -&amp;nbsp;&lt;a href="http://www.goodreads.com/book/show/9734814-essentials-of-metaheuristics"&gt;http://www.goodreads.com/book/show/9734814-essentials-of-metaheuristics&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-2364155058483220633?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/2364155058483220633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2011/03/stochastic-optimisation-in-analysing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/2364155058483220633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/2364155058483220633'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2011/03/stochastic-optimisation-in-analysing.html' title='Stochastic optimisation in analysing efficiency of betting exchange markets'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='https://lh3.googleusercontent.com/-YRexEHNbJwE/TX_LYYUqK6I/AAAAAAAAAMc/BKIY1Uzu4_Y/s72-c/Analysingmarketswithoutadoptingstochasticoptimisation.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-5113471106041594770</id><published>2011-01-22T16:49:00.000-08:00</published><updated>2011-02-15T07:36:03.985-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='SCALA'/><title type='text'>Moving from Java to Scala - One year later...</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div style="text-align: justify;"&gt;One year ago I posted on moving &amp;nbsp;from Java to Scala &lt;a href="http://blog.danmachine.com/2009/12/time-to-change-moving-from-java-to.html"&gt;[1]&lt;/a&gt;. At that time my experience with Scala was limited to reading some technical materials and to implementing a few simple mathematical algorithms such as weighed average. Even though I hadn't developed any project in Scala yet, I had a good feeling that moving from Java to Scala could be similarly right decision as moving from C/C++ to Java 10 years ago. Having only a good feeling usually is not enough to adopt a new programming language in a commercial project but it is certainly sufficient to use it for a research open source project. Because I was just about to start a new research project to develop artificial intelligence aided trading simulator&amp;nbsp;&lt;a href="http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence.html"&gt;[2]&lt;/a&gt;, I decided to choose Scala programming language instead of a well known and&amp;nbsp;commercially&amp;nbsp;proven Java. Now, one year later, after writing 8622 lines of code in Scala&amp;nbsp;&lt;a href="http://code.google.com/p/betting-ai/source/browse/#svn%2Ftrunk"&gt;[3]&lt;/a&gt;, reading Programming in Scala&amp;nbsp;book &lt;a href="http://www.goodreads.com/book/show/5680904-programming-in-scala"&gt;[4]&lt;/a&gt; and attending Martin Odersky's Scala course &lt;a href="http://skillsmatter.com/course/scala/object-oriented-meets-functional-an-exploration-of-scala"&gt;[5]&lt;/a&gt;, I believe I'm in a good position to review my original statement on moving from Java to Scala. Was it a good decision or I made a mistake? I will try to answer this question in a context of research open source project as well as I will make an attempt to apply my observations to enterprise and commercial environment.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Evaluation methodology&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Reading this Scala evaluation please put a bit of attention to what is it about and what it is not. For sure, I'm not trying to examine Scala just by looking only at its design, syntax and other language capabilities. Instead of that, I'm aiming to answer the questions raised in the introduction above.&amp;nbsp;Was it a good decision or I made a mistake adopting Scala? Is Scala ready for Enterprise project or not yet? To answer those questions, in addition to evaluating Scala itself, a few other factors have to be considered:&amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;&lt;b&gt;Programming language&lt;/b&gt; - Here, I evaluate features of Scala programming language, its paradigm, design and so on. In other words, all parts and aspects of Scala that were important for me developing trader simulator.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Testing&lt;/b&gt; - How do we test Scala code?&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Performance&lt;/b&gt; - How fast Scala programs are?&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;&lt;b&gt;Tools&lt;/b&gt; - Doing any serious software development and not using some useful tools is hardly possible. The most worth to look at are: Integrated Development Environment, build tool, continuous integration,&amp;nbsp;code coverage, static code analysis, memory and cpu profiler.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;&lt;b&gt;Language extensions&lt;/b&gt; - Powerful and robust programming language doesn't guarantee any success yet. Third party tools, libraries and frameworks, that come from both open source&amp;nbsp;community&amp;nbsp;and commercial vendors, are very important as well.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;&lt;b&gt;Interoperability&lt;/b&gt; - Interoperability with other programming languages by no means is a must requirement in developing some kinds of computer systems, especially with the most popular ones such as Java and C/C++.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;&lt;b&gt;Monitoring and maintenance&lt;/b&gt; - In enterprise, assuring high availability at the level 99.99 and higher is a fundamental thing and requires wide range of tools for production monitoring and analysis. &amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;&lt;b&gt;Support&lt;/b&gt; - Adapting new technology,&amp;nbsp;particularly&amp;nbsp;programming language, always involves some risk. Active world wide community, availability of trainings, forum, mailing list is very important. Additionally, well established global commercial company that stays behind programming language makes us to believe that we won't stay alone in the future.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;&lt;b&gt;Scala skills&lt;/b&gt; - Even the most powerful weapon won't win the battle if you don't have a &amp;nbsp;well skilled army that is able to use it.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;&lt;b&gt;Time to Market&lt;/b&gt; - Eventually, whether or not it is worth to use a particular technology is a business decision that is based on some short and long term financial indicators. Though, we do software for money and having a fun may be just a nice side effect of that.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;One more aspect that has to be taken into account for completeness of this evaluation is a business domain to which programming language is applied to. In this case it is risk management, data collection, market simulation and trading on betting exchange &lt;a href="http://en.wikipedia.org/wiki/Betting_exchange"&gt;[6]&lt;/a&gt; markets.&amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;There is not much point evaluating any programming language and not taking&amp;nbsp;business&amp;nbsp;domain into account. There are many programming languages in the world and some may fit one business domain whereas others master somewhere else. For instance Erlang fit well telecom, C is great for developing embedded systems, dynamic languages such as Ruby or Groovy are&amp;nbsp;useful&amp;nbsp;for developing web applications and Java fit well everywhere as a general purpose language. Scala has some better and worse appliances as well.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;To evaluate Scala programming language in a context of all categories and business domain mentioned above, I will examine all of them one by one&amp;nbsp;applying the following point system:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;1 - poor, 2 - fair, 3 - good, 4 - very good, 5 - excellent&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;Finally I will make an attempt to interpret those scores and to come up with some relevant conclusions.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Evaluation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Over last year, developing trading simulator I was taking some notes on many aspects of adopting Scala programming language in a light of all&amp;nbsp;evaluation&amp;nbsp;categories presented above. I share with you all my thoughts and observation I made on Scala and I hope you will find them useful when taking your own decision on adopting Scala for some of your projects.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Programming language&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The trading simulator, that I decided to use Scala for, can be characterized as a complex algorithmic system that each line of code matters rather than a CRUD (create, read, update, delete) application &lt;a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete"&gt;[7]&lt;/a&gt;. Writing most of the code requires a lot of thinking up front and looking at a written code should make it obvious what it does and how does it work. For many reasons Java doesn't fit here well, mostly due to following an imperative programming &lt;a href="http://en.wikipedia.org/wiki/Imperative_programming"&gt;[8]&lt;/a&gt; paradigm and its verbose nature of a programming style. What I'm looking here for is a functional programming &lt;a href="http://en.wikipedia.org/wiki/Functional_programming"&gt;[9]&lt;/a&gt; and Scala is a place where I found it being simple and natural to use.&lt;br /&gt;&lt;br /&gt;Before I carry on, please forgive me for presenting hardly any Scala code in this post. I do it on purpose, because&amp;nbsp;my goal is not to show you how Scala syntax looks like and how to use it. For that, there are much better resources to go for, for instance great Programming in Scala book. In reverse, I prefer to focus on sharing with you my experience with Scala and then you can decide yourself whether or not it's worth to pursue it further.&lt;br /&gt;&lt;br /&gt;Now, probably some people would question, why Scala and not other functional programming language such as&amp;nbsp;Lisp &lt;a href="http://en.wikipedia.org/wiki/Lisp_%28programming_language%29"&gt;[10]&lt;/a&gt; or Erlang &lt;a href="http://en.wikipedia.org/wiki/Erlang_%28programming_language%29"&gt;[11]&lt;/a&gt;? Well, the main reason is that Scala code compiles to a byte code and runs on Java virtual machine, thus it is compatible with other Java applications. It is especially important if a majority of your code and libraries that you already use are coming from a Java world. The two libraries I was using myself for Trading Simulator project were Esper Complex Event Processing &lt;a href="http://http//esper.codehaus.org/"&gt;[12]&lt;/a&gt; and Jackson JSON parser &lt;a href="http://jackson.codehaus.org/"&gt;[13]&lt;/a&gt;. I would probably stay with Java if I couldn't use them in Scala.&lt;br /&gt;&lt;br /&gt;At this moment, others might ask why Scala and not let say Clojure &lt;a href="http://clojure.org/"&gt;[14]&lt;/a&gt; that is a functional programming language running on Java virtual machine as well? To answer this question we need to look at two features that distinguish both Scala and Clojure.&amp;nbsp;First, Scala syntax is similar to Java,&amp;nbsp;whereas Clojure is a Lisp dialect, that for me, a person who has been working mostly with Java for last 10 years, makes it far easier to use Scala than Clojure. Second,&amp;nbsp;Scala is a statically typed language &lt;a href="http://en.wikipedia.org/wiki/Static_typing#Static_typing"&gt;[15]&lt;/a&gt; and Clojure is a dynamic programming language &lt;a href="http://en.wikipedia.org/wiki/Static_typing#Dynamic_typing"&gt;[16]&lt;/a&gt;. Static typing is a core feature for me&amp;nbsp;when developing critical and complex applications, First of all, debugging and maintaining statically typed code is easier and faster, secondly code written in a statically typed language is less error prone due to picking up some errors on a compile time and that is true regardless how good unit tests are.&lt;br /&gt;&lt;br /&gt;There is one more important aspect of Scala that I'd like to mention to you. Scala is a multi-paradigm programming language, it means that it allows for mixing multiple programming styles such as object oriented, imperative and functional programming. &amp;nbsp;Whether it's good or not, it is not a question that could be answered with a simple yes or no. Supporters would say that programmers can pick up the best of all styles depends on theirs needs. Others would argue that putting together some features found in many other programming languages can't work well, mostly by increasing complexity and making a programming language obscure.&lt;br /&gt;&lt;br /&gt;If you ask myself on this topic, to some degree, I would agree with both positive and negative arguments above on multi-paradigm in Scala. On one hand, if Scala would be a pure functional language I wouldn't go for it. I like functional programming and I'm finding it very useful in many aspects of software development but I would lie if I said that imperative programming is a devil that we should all avoid. It's just not true and it's fair enough to look how popular Java nowadays is. One example of a computer system that imperative programming fits very well is a stateful &amp;nbsp;high performance betting exchange engine that is a part of trading simulator I was developing over last year. Moreover, it fits there even better when mixed up with functional programming.&lt;br /&gt;&lt;br /&gt;Regarding to a negative argument on a high complexity of Scala I have to admit that to a some level I agree with that. For instance please take a look at the one of the most commonly used method in a Scala version of a List class.&lt;br /&gt;&lt;br /&gt;//Builds a new collection by applying a function to all elements of this list.&lt;br /&gt;def map [B, That] (f: (A) ⇒ B)(implicit bf: CanBuildFrom[List[A], B, That]) : That&lt;br /&gt;&lt;br /&gt;Is it obvious to you what it is for? Would a novice Scala programmer understand it? Well, probably not easily, but&amp;nbsp;definitely&amp;nbsp;such syntax could discourage many of developers. To be fair, I have to mention that in Scala 2.8 this method in a Scala doc is presented following much simpler syntax,&amp;nbsp;but in overall, it may not change a quite bad initial impression.&lt;br /&gt;&lt;br /&gt;def map [B] (f: (A) ⇒ B) : List[B]&lt;br /&gt;&lt;br /&gt;Additionally, some complexity in Scala is dictated by assuring compatibility with Java. For example in Scala there is an Option class that can take two values, Some and None. It's a great replacement for null value in Java and all would be fine if null value wasn't available in Scala too. When I asked Martin Odersky why is that, he explained me it's mainly to be able to stay compatible with Java. I think it's a relatively low cost of that.&lt;br /&gt;&lt;br /&gt;There are many other examples that I could bring up to demonstrate how potentially evil Scala could be but it doesn't make too much sense. The Scala code that for someone is obscure, for others could be a nice and neat form of solving some specific problems. Personally, in most cases I found Scala syntax simple and natural to use and my opinion has not been changed after spending one year developing quite advanced application in Scala.&lt;br /&gt;&lt;br /&gt;Next positive aspect of Scala is its conciseness. We all know how Java verbose is and how many boiler code developers write everyday including constructors, getters, variable initialisation (type and generics),&amp;nbsp;semicolons&amp;nbsp;and many others. To illustrate that I present how a Person class is defined in both Java and Scala:&lt;br /&gt;&lt;br /&gt;Java version:&lt;br /&gt;&lt;br /&gt;public class Person {&lt;br /&gt;&amp;nbsp;&amp;nbsp;private final String firstName;&lt;br /&gt;&amp;nbsp;&amp;nbsp;private final String lastName;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;public Person(String firstName, String lastName) {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;this.firstName=firstName;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;this.secondName=secondName;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;public String getFirstName() { return this.firstName; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;public String getLastName() { return this.lastName; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;//hashcode, equals and toString methods&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Scala version:&lt;br /&gt;&lt;br /&gt;case class Person(firstName:String, lastName: String)&lt;br /&gt;&lt;br /&gt;If you think that I'm showing to you some marketing gadget similar to presentations on 'How to build a web based application in 5 minutes', I do assure you it is not the case. Over last year, I was discovering every month, more and more examples that were proving to me how useful concise syntax in Scala is.&lt;br /&gt;&lt;br /&gt;There are a few other features in Scala that are worth some attention, I won't describe them in details but I encourage you to read about them yourself in a Programming in Scala book. Those features include, creating DSL (domain specific language) &amp;nbsp;in Scala &lt;a href="http://en.wikipedia.org/wiki/Domain-specific_language"&gt;[17]&lt;/a&gt;, pattern matching &lt;a href="http://en.wikipedia.org/wiki/Pattern_matching"&gt;[18]&lt;/a&gt;, tail recursion &lt;a href="http://en.wikipedia.org/wiki/Tail_recursion"&gt;[19]&lt;/a&gt;, type inference &lt;a href="http://en.wikipedia.org/wiki/Type_inference"&gt;[20]&lt;/a&gt;, implicit conversions, xml and json parsing and concurrent programming with Actors &lt;a href="http://en.wikipedia.org/wiki/Actor_model"&gt;[21]&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Until now, I wasn't too critical on Scala, does it mean that Scala is a perfect programming language? Unfortunately, every rose has its thorn and Scala has one as well. It's a poor backward compatibility in Scala. For example, I started developing trading simulator with Scala 2.7 and then I migrated to version 2.8. Even though I wrote no more than 3K lines of code I faced a few compilation errors and one failure of a functional unit test. One of areas widely affected by those changes in Scala is Collections API (see Scala 2.8 Release Notes &lt;a href="http://www.scala-lang.org/node/7009"&gt;[22]&lt;/a&gt;). Scala team and Martin Odersky himself are justifying all those significant changes by improving overall quality and design of Scala. That of course makes sense but sometimes I feel that this improvement process is happening to fast and some formal body similar to JCP (Java Community Process) &lt;a href="http://jcp.org/"&gt;[23]&lt;/a&gt; would help. That is especially important now, at the day when Scala is entering Enterprise world.&lt;br /&gt;&lt;br /&gt;To summarise, how I'm describing Scala so far, it's a statically typed and multi-paradigm programming language that runs on Java virtual machine and provides Java like syntax with a few improvements. It sounds a bit familiar, doesn't it? Isn't it the old good Java with support of closures and some syntax improvements. If so, why I don't wait for some time until closures are supported in Java? Though I could live without closures for 10 years, so why I can't wait a bit more time? Actually this was one of the main questions I asked myself one year ago, before I started trading simulator. Then I asked the same question one year later to Martin Odersky and now I will try to answer this question to myself as well as to you dear readers in the end of this post.&lt;br /&gt;&lt;br /&gt;My overall score to Scala programming language is very good (4).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Testing&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Developers are provided with all they need to test Scala applications efficiently. To follow a Test Driven Development methodology &lt;a href="http://en.wikipedia.org/wiki/Test_driven_development"&gt;[24]&lt;/a&gt;, they can use popular in Java world Junit tool &lt;a href="http://junit.org/"&gt;[25]&lt;/a&gt;. If someone is more keen on&amp;nbsp;Behaviour&amp;nbsp;Driven Development &lt;a href="http://en.wikipedia.org/wiki/Behavior_driven_development"&gt;[26]&lt;/a&gt; then ScalaTest is a way to go &lt;a href="http://www.scalatest.org/getting_started_with_feature_spec"&gt;[27]&lt;/a&gt;. I use both of them and they work very well. Especially, the second tool&amp;nbsp;deserves some attention here, as it's a good example to illustrate one more powerful feature of Scala that I haven't presented to you yet. Please look at the following test written in a ScalaTest tool.&lt;br /&gt;&lt;br /&gt;scenario("pop is invoked on a non-empty stack") {&lt;br /&gt;&amp;nbsp;&amp;nbsp;given("a non-empty stack")&lt;br /&gt;&amp;nbsp;&amp;nbsp;when("when pop is invoked on the stack")&lt;br /&gt;&amp;nbsp;&amp;nbsp;then("the most recently pushed element should be returned")&lt;br /&gt;&amp;nbsp;&amp;nbsp;and("the stack should have one less item than before")&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is interesting here that it's an absolutely correct Scala code. Its syntax is provided by a domain specific language, which is built on top of Scala. Can Java make it? probably not. To make it working in Java we would need to create a DSL on top of Groovy and then call it from Java, for instance Easyb testing tool &lt;a href="http://code.google.com/p/easyb/"&gt;[28]&lt;/a&gt; represents this approach. Though, it's a bit problematic as calling Java code from Groovy carries on some level of overhead and complexity due to integrating two different languages.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;In my opinion, there are some business domains where ability to create domain specific languages in Scala is an extremely useful feature. The one example is a domain specific language for trading on financial markets.&amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;My overall score to Scala testing is very good (4).&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;/span&gt;&lt;/b&gt;&lt;b&gt;Performance&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;/b&gt;At first sight the performance in Scala is very good, comparable to Java, thus Scala code compiles to the same byte code as Java does and runs on the same Java virtual machine. Nevertheless, how fast Scala code is, may&amp;nbsp;vary from case by case and usually it's up to the way how the code is written. This awareness how to write a high performance Scala code is especially important for Java developers who are not very experienced in both Scala and functional programming.&lt;br /&gt;&lt;br /&gt;For instance poor knowledge of Collections API in Scala may lead developers to call often a size() method on a List class. Because this method is not an indexed sequence as it is in Java, therefore calling it is a very expensive operation as it has to traverse through all elements in a List to count all of them. The other example is to implement a function that multiplies all numbers in a List by 2 and then filter out all that are greater than 10. In Java, we would probably create a single loop that does this work but in Scala, following functional programming we could write:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;list.map(e =&amp;gt; e*2).filter(e =&amp;gt; e&amp;gt;10)&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Looks simple and in many cases that's the solution we would use but under the hood it's much more expensive algorithm that the iterative version in Java (&lt;a href="http://stackoverflow.com/questions/4899092/scala-performance-question"&gt;more details&lt;/a&gt;). On the other hand, having a choice between imperative and functional programming, availability of tail-recursion and so on, we can achieve better performance in Scala than in Java by carefully choosing proper algorithms for particular tasks.&amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;There is one important thing for me that I noticed myself after one year I spent with Scala. In Java, usually development can be characterized as 'write first then think' approach, in Scala it's in an opposite way 'think first then write'. In Java, most of code is constructed by combining some loops and variables together that in many cases is a routine work. Whereas in Scala, developer is much more&amp;nbsp;encouraged to think first and then write. From my own experience, when applying 'think first then write' approach, the final result of software development work can be impressive.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Next thing that I learnt myself by adopting the 'think first then write' approach and gaining some good skills in functional programming is that I became a better developer, whichever programming language I use, either Scala, Java or something else.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: justify;"&gt;Going back to a performance aspect in Scala, I would like to mention one improvement that was added to Scala version 2.8. It's a specialisation for auto boxing &lt;a href="http://en.wikipedia.org/wiki/Object_type_%28object-oriented_programming%29#Autoboxing"&gt;[29]&lt;/a&gt;, which regarding to Iulian Dragos &lt;a href="http://lamp.epfl.ch/~dragos/"&gt;[30]&lt;/a&gt;, creator of this feature, provides a performance improvement of a factor of 4 to 30. Iulian gave an interesting talk on this topic on December 2010 at Skills Matter in London. The pod cast is available here: &amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;a href="http://skillsmatter.com/podcast/scala/scala-performance-improvements-of-a-factor-of-4-to-30-boxing-and-specialization"&gt;http://skillsmatter.com/podcast/scala/scala-performance-improvements-of-a-factor-of-4-to-30-boxing-and-specialization&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;My overall score to Scala performance is very good (4).&lt;/span&gt; &lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Tools&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;Until now, there are not too many development tools created specifically to serve Scala, but&amp;nbsp;fortunately, thanks to compatibility with Java it doesn't look so bad.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: justify;"&gt;For a build tool, I adopted maven &lt;a href="http://en.wikipedia.org/wiki/Apache_Maven"&gt;[31]&lt;/a&gt;, which with some help of maven-scala-plugin &lt;a href="http://scala-tools.org/mvnsites/maven-scala-plugin/"&gt;[32]&lt;/a&gt; works very well.&amp;nbsp;Having that we use maven, there shouldn't be any problem to adopt some of popular Continuous Integration &lt;a href="http://en.wikipedia.org/wiki/Continuous_integration"&gt;[33]&lt;/a&gt; &amp;nbsp;tools such as Bamboo &lt;a href="http://www.atlassian.com/software/bamboo/"&gt;[34]&lt;/a&gt; or Ant Hill Pro &lt;a href="http://www.anthillpro.com/html/default.html"&gt;[35]&lt;/a&gt;. Alternatively you could use SBT &lt;a href="http://code.google.com/p/simple-build-tool/"&gt;[36]&lt;/a&gt;, simple build tool for Scala. You will find a&amp;nbsp;pod cast&amp;nbsp;on a Simple Build Tool here:&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;a href="http://skillsmatter.com/podcast/scala/simple-build-tool"&gt;http://skillsmatter.com/podcast/scala/simple-build-tool&lt;/a&gt;.&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;As Integrated Development Environment I utilised Eclipse Scala IDE plugin &lt;a href="http://www.scala-ide.org/"&gt;[37]&lt;/a&gt;. When I started using this&amp;nbsp;plug-in&amp;nbsp;more than one year ago it was very unstable and it was crashing my Eclipse a couple times a day. It was so&amp;nbsp;frustrating to a level&amp;nbsp;that I nearly abandoned Scala. By good luck I've been keeping up and sometime later, Scala IDE plug-in was getting better and better. At the moment there are still some features&amp;nbsp;barely supported such as&amp;nbsp;re-factoring or debugging, nonetheless at least it is stable enough to not complain to much. I heard some good opinions on IntelliJ Scala plugin &lt;a href="http://confluence.jetbrains.net/display"&gt;[38]&lt;/a&gt; but&amp;nbsp;because&amp;nbsp;I haven't used it myself I'm not able to give you more information.&lt;/div&gt;&lt;br /&gt;For a purpose of a memory and&amp;nbsp;CPU&amp;nbsp;profiling I use Jprofiler &lt;a href="http://www.ej-technologies.com/products/jprofiler/overview.html"&gt;[39]&lt;/a&gt; and Eclipse MAT (Memory Analyser Tool)&amp;nbsp;&lt;a href="http://www.eclipse.org/mat/"&gt;[40]&lt;/a&gt;. Despite of being dedicated Java tools, they can be used for analysing Scala applications as well. Personally, I found some difficulties while using those tools with Scala, for example they won't let you to analyse parts of your application that use some Scala features that are not available in Java, for instance companion objects and closures. I wouldn't say that it will stop you from using those tools, just the user experience may not be so good as when analysing Java applications.&lt;br /&gt;&lt;br /&gt;One family of tools that in my opinion at the moment are hardly usable in Scala are those, which do some sort of code analysis, for instance code coverage &lt;a href="http://en.wikipedia.org/wiki/Code_coverage"&gt;[41]&lt;/a&gt; and static code analysis &lt;a href="http://en.wikipedia.org/wiki/Static_code_analysis"&gt;[42]&lt;/a&gt;. Especially the code coverage tools are those, that I always use quite extensively. I tried to use Eclipse Emma plugin &lt;a href="http://www.eclemma.org/"&gt;[43]&lt;/a&gt; to check ad-hoc a code coverage for a written Scala code and it just didn't work, blowing up with some errors. I have no evidence on other code coverage tools but even if they work somehow, the reports they generate may not be well tuned against Scala code.&lt;br /&gt;&lt;br /&gt;Static code analysis tools are even less usable. I evaluated two popular Java tools, pmd &lt;a href="http://pmd.sourceforge.net/"&gt;[44]&lt;/a&gt; that operates on a source code level, and find bugs tool &lt;a href="http://findbugs.sourceforge.net/factSheet.html"&gt;[45]&lt;/a&gt;, which inspects Java byte code. Both of them report a big number of warnings and errors that are not relevant to a Scala code. That is not a surprise as those tools are optimized to run against Java code.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="margin: 0px;"&gt;My overall score to Scala tools is fair(2).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Language extensions&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Most of libraries and frameworks are available to Scala due to compatibility with Java, otherwise we wouldn't have to much choice. The two worth to mention native Scala extensions are Lift web framework &lt;a href="http://liftweb.net/"&gt;[46]&lt;/a&gt; and Akka actors platform &lt;a href="http://akka.io/"&gt;[47]&lt;/a&gt;. I have no much experience with Lift web framework so far, so I will leave you alone with it. In terms of Akka, it's a very interesting project lead by Jonas Bonér &lt;a href="http://jonasboner.com/"&gt;[48]&lt;/a&gt;. In a few words, it's a platform for developing event driven, distributed, scalable and fault tolerant systems adopting Actors concurrency model.&lt;br /&gt;&lt;br /&gt;The majority of libraries and frameworks from a Java world, should be possible to use quite smoothly, which among other things, is thanks to implicit conversions &lt;a href="http://en.wikipedia.org/wiki/Type_conversion"&gt;[49]&lt;/a&gt; in Scala. For example, in Java to convert between two different implementations of a List we would need to call&amp;nbsp;explicitly&amp;nbsp;some custom code that populates an output list by iterating through all elements of an input list. In Scala we also need to write a such code, but the difference is that it is called behind the scene. Please consider the Scala code example below.&lt;br /&gt;&lt;br /&gt;//Initialises java.util.ArrayList object with three integers and converts it&amp;nbsp;implicitly to a Scala List.&lt;br /&gt;val newList:List = Arrays.toList(1,2,3)&lt;br /&gt;&lt;br /&gt;It is like extending generic language rules for type conversions such as those between numeric types and it really makes it far easier to use external libraries in Scala.&lt;br /&gt;&lt;br /&gt;My overall score to Scala language extensions is good (3).&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;b&gt;Interoperability&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;Interoperability between Scala and other programming languages, including Java/C/C++, is very good, mostly because of running on Java virtual machine. What Java may talk to, Scala can do as well. Taking into account support for implicit conversions described above, I would state that Scala is one of the leaders of interoperability among all programming languages.&lt;br /&gt;&lt;br /&gt;My overall score to Scala interoperability is excellent (5).&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;b&gt;Monitoring and maintenance&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;For me, the main monitoring tool to analyse production Scala applications is JMX (Java Management Extensions) &lt;a href="http://en.wikipedia.org/wiki/Java_Management_Extensions"&gt;[50]&lt;/a&gt;, and again, this is with no surprise thanks to compatibility with JAVA. This tool does its job well when we want to analyse some predefined statistics, but sometimes we need to investigate some aspects of a production application while it's running and JMX can't provide all required data.&lt;br /&gt;&lt;br /&gt;To deal with such scenarios, Java provides&amp;nbsp;Java Virtual Machine Tool Interface (JVM TI) &lt;a href="http://en.wikipedia.org/wiki/Java_Virtual_Machine_Tools_Interface"&gt;[51]&lt;/a&gt; that allows for inspecting running Java applications but it can be used for Scala too. Imagine, there is a method inside running Scala application that calculates and returns some data and we want to be informed every time when this method is invoked and what is the value it returns. We can do such things with a btrace &lt;a href="http://kenai.com/projects/btrace/pages/Home"&gt;[52]&lt;/a&gt;, command line dynamic monitoring tool from open source world. Eventually if we prefer more sophisticated and powerful platform for monitoring production applications we could choose Dynatrace &lt;a href="http://www.dynatrace.com/en/"&gt;[53]&lt;/a&gt; commercial product. The first one works well with Scala, though not as good as with Java, because it's not a dedicated Scala tool. I haven't tried the second one with Scala but I expect it to work as well, thus it uses the same JVM TI interface as btrace does.&lt;br /&gt;&lt;br /&gt;My overall score to Scala monitoring and maintenance is good (3).&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;b&gt;Support&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;Scala community, including forum, mailing list and blogs, is not the biggest in the world, but it's very energetic. My feeling is that most people who are part of a Scala community are very&amp;nbsp;passionate&amp;nbsp;developers, which are always happy to help others to solve theirs problems. It was especially important for me on the beginning of my adventure with Scala.&lt;br /&gt;&lt;br /&gt;Next important part of a Scala support are books and here I also found a great position. It's a Programming in Scala book by Marting Oderski, Lex Spoon and Bill Venners. There is big chance that I wouldn't pursue Scala if this book hadn't existed. I'm a such sort of person who usually start learning some new technology by reading some good book. If one doesn't exist, then probably this technology is not worth a penny (at least not yet).&lt;br /&gt;&lt;br /&gt;One thing that would definitely help Scala to spread around the world is a global commercial vendor, such as Oracle or IBM. But even if no one ever exist it doesn't mean that Scala can't became a globally used programming language. Nobody should under estimate the power of an open source world wide community.&lt;br /&gt;&lt;br /&gt;My overall score to Scala support is good (3).&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Scala skills&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Even though I don't posses any professional data on a number of Scala developers in the world, I think no one will argue that it is far behind other programming languages such as Java or C/C++. I performed two simple experiments to get some data for you.&amp;nbsp;First I checked for Scala job trends &lt;a href="http://www.indeed.com/jobtrends?q=scala&amp;amp;l="&gt;[54]&lt;/a&gt;&amp;nbsp;and the number of job offers for Scala developers is barely&amp;nbsp;noticeable&amp;nbsp;but is growing dynamically over last two years. Second I searched for Scala developers on the linkedin.com social site and I got 1709 results. Just to mentioned that querying for Java developers returned 249,589 entries. It doesn't look good, does it?&amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;One positive aspect I found is that looking for Scala developers we could search for Java developers with Scala interests as well. The learning curve is not massive as Scala follows Java syntax. In such case, at least on experienced Scala developer would help the team adopting new programming language.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;My overall score to Scala skills is poor (1).&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Summary&lt;/span&gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;br /&gt;To summarise Scala evaluation, this is a scores matrix for all categories (1 - poor, 2 - fair, 3 - good, 4 - very good, 5 - excellent).&lt;br /&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Programming language - very good (4)&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Testing - very good (4)&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Performance - very good (4)&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Tools - fair (2)&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Language extensions - good (3)&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Interoperability - excellent (5)&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Monitoring and maintenance&amp;nbsp;&amp;nbsp;- good (3)&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Support&amp;nbsp;- good (3)&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Scala skills&amp;nbsp;- poor (1)&lt;/li&gt;&lt;/ul&gt;The best way to decide on some technology for some project is to ask about the time to market &lt;a href="http://en.wikipedia.org/wiki/Time_to_market"&gt;[55]&lt;/a&gt;, however the problem&amp;nbsp;arises&amp;nbsp;when we stay in front of deciding on some new, not proved yet technology. In that cases, emerging technologies usually are on hiding to nothing, they can hardly win. But sometimes new technologies find a place on a market and I believe that Scala is one of them.&lt;br /&gt;&lt;br /&gt;Scala already has beaten Java for developing my research projects and I have no temptation to move back. How about Scala in Enterprise? Here, I'm not so optimistic. Java is a really strong player and being just a better programming language may not be enough. What if Java finally provides functional programming and some better and more concise syntax? What if then Scala disappears from a market and we are in a half way through migrating our applications from Java to Scala? Will we move back to Java? Who will pay for that? Those are the questions that everyone must answer himself.&lt;br /&gt;&lt;br /&gt;One advice I can give you myself is to not adapt Scala, just because someone says it's cool, so I want to be cool too. Something that works well in someone's business domain may not work for you. Be reasonable and try to get some experience with Scala first, for instance by getting involved in some open source projects.&lt;br /&gt;&lt;br /&gt;Thank you for your attention and I hope you enjoyed it. I invite you to comment on this post and to share your thoughts with others. Daniel.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;References&lt;/span&gt;&lt;/div&gt;&lt;ol&gt;&lt;li style="text-align: left;"&gt;Post on moving from Java to Scala - http://blog.danmachine.com/2009/12/time-to-change-moving-from-java-to.html&lt;/li&gt;&lt;li style="text-align: left;"&gt;Initial post on applying artificial&amp;nbsp;intelligence&amp;nbsp;to betting exchange research&amp;nbsp;- http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence.html&lt;/li&gt;&lt;li style="text-align: left;"&gt;Betting AI project sources - &amp;nbsp;http://code.google.com/p/betting-ai/source/browse/#svn%2Ftrunk&lt;/li&gt;&lt;li style="text-align: left;"&gt;Programming in Scala book by Marting Oderski, Lex Spoon and Bill Venners - http://www.goodreads.com/book/show/5680904-programming-in-scala&lt;/li&gt;&lt;li style="text-align: left;"&gt;Scala course by Marting Odersky and Julain Dragos -&amp;nbsp;http://skillsmatter.com/course/scala/object-oriented-meets-functional-an-exploration-of-scala&lt;/li&gt;&lt;li style="text-align: left;"&gt;Betting exchange -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Betting_exchange"&gt;http://en.wikipedia.org/wiki/Betting_exchange&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;CRUD -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete"&gt;http://en.wikipedia.org/wiki/Create,_read,_update_and_delete&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Imperative programming -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Imperative_programming"&gt;http://en.wikipedia.org/wiki/Imperative_programming&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Functional programming -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Functional_programming"&gt;http://en.wikipedia.org/wiki/Functional_programming&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Lisp programming language -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Lisp_%28programming_language%29"&gt;http://en.wikipedia.org/wiki/Lisp_(programming_language)&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Erlang programming language-&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Erlang_%28programming_language%29"&gt;http://en.wikipedia.org/wiki/Erlang_(programming_language)&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Esper Complex Event Processing tool - http://&lt;a href="http://esper.codehaus.org/"&gt;http://esper.codehaus.org/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Jackson high-performance JSON parser -&amp;nbsp;&lt;a href="http://jackson.codehaus.org/"&gt;http://jackson.codehaus.org/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Clojure programming language -&amp;nbsp;&lt;a href="http://clojure.org/"&gt;http://clojure.org/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Static typing -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Static_typing#Static_typing"&gt;http://en.wikipedia.org/wiki/Static_typing#Static_typing&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Dynamic typing -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Static_typing#Dynamic_typing"&gt;http://en.wikipedia.org/wiki/Static_typing#Dynamic_typing&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;DSL (Domain Specific Language) -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Domain-specific_language"&gt;http://en.wikipedia.org/wiki/Domain-specific_language&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Pattern matching -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Pattern_matching"&gt;http://en.wikipedia.org/wiki/Pattern_matching&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Tail recursion -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Tail_recursion"&gt;http://en.wikipedia.org/wiki/Tail_recursion&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Type inference -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Type_inference"&gt;http://en.wikipedia.org/wiki/Type_inference&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Actor model -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Actor_model"&gt;http://en.wikipedia.org/wiki/Actor_model&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Scala 2.8 Release Notes -&amp;nbsp;&lt;a href="http://www.scala-lang.org/node/7009"&gt;http://www.scala-lang.org/node/7009&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;JCP (Java Community Process) -&amp;nbsp;&lt;a href="http://jcp.org/en/home/index"&gt;http://jcp.org&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Test Driven Development -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Test_driven_development"&gt;http://en.wikipedia.org/wiki/Test_driven_development&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Junit Test Driven Development tool -&amp;nbsp;&lt;a href="http://junit.org/"&gt;http://junit.org/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;BDD (Behavior Driven Development) -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Behavior_driven_development"&gt;http://en.wikipedia.org/wiki/Behavior_driven_development&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;ScalaTest BDD tool -&amp;nbsp;&lt;a href="http://www.scalatest.org/getting_started_with_feature_spec"&gt;http://www.scalatest.org/getting_started_with_feature_spec&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Easyb BDD tool -&amp;nbsp;&lt;a href="http://code.google.com/p/easyb/"&gt;http://code.google.com/p/easyb/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Auto boxing -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Object_type_%28object-oriented_programming%29#Autoboxing"&gt;http://en.wikipedia.org/wiki/Object_type_(object-oriented_programming)#Autoboxing&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Iulian Dragos -&amp;nbsp;&lt;a href="http://lamp.epfl.ch/~dragos/"&gt;http://lamp.epfl.ch/~dragos/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Maven build tool -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Apache_Maven"&gt;http://en.wikipedia.org/wiki/Apache_Maven&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Maven-scala-plugin -&amp;nbsp;&lt;a href="http://scala-tools.org/mvnsites/maven-scala-plugin/"&gt;http://scala-tools.org/mvnsites/maven-scala-plugin/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Continuous Integration -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Continuous_integration"&gt;http://en.wikipedia.org/wiki/Continuous_integration&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Bambo CI tool -&amp;nbsp;&lt;a href="http://www.atlassian.com/software/bamboo/"&gt;http://www.atlassian.com/software/bamboo/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Ant Hill Pro CI tool -&amp;nbsp;&lt;a href="http://www.anthillpro.com/html/default.html"&gt;http://www.anthillpro.com/html/default.html&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Simple Build Tool -&amp;nbsp;&lt;a href="http://code.google.com/p/simple-build-tool/"&gt;http://code.google.com/p/simple-build-tool/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Eclipse Scala IDE -&amp;nbsp;&lt;a href="http://www.scala-ide.org/"&gt;http://www.scala-ide.org/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;IntelliJ Scala IDE - h&lt;a href="http://confluence.jetbrains.net/display/SCA/Getting+Started+with+IntelliJ+IDEA+Scala+Plugin"&gt;ttp://confluence.jetbrains.net/display/SCA/Getting+Started+with+IntelliJ+IDEA+Scala+Plugin&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Jprofiler tool -&amp;nbsp;&lt;a href="http://www.ej-technologies.com/products/jprofiler/overview.html"&gt;http://www.ej-technologies.com/products/jprofiler/overview.html&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Eclipse Memory Analyser Tool -&amp;nbsp;&lt;a href="http://www.eclipse.org/mat/"&gt;http://www.eclipse.org/mat/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Code coverage -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Code_coverage"&gt;http://en.wikipedia.org/wiki/Code_coverage&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Static code analysis -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Static_code_analysis"&gt;http://en.wikipedia.org/wiki/Static_code_analysis&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Eclipse Emma code coverage plugin -&amp;nbsp;&lt;a href="http://www.eclemma.org/"&gt;http://www.eclemma.org/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;PMD static code analysis tool -&amp;nbsp;&lt;a href="http://pmd.sourceforge.net/"&gt;http://pmd.sourceforge.net/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Find bugs static code analysis tool -&amp;nbsp;&lt;a href="http://findbugs.sourceforge.net/factSheet.html"&gt;http://findbugs.sourceforge.net/factSheet.html&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Lift web framework -&amp;nbsp;&lt;a href="http://liftweb.net/"&gt;http://liftweb.net/&lt;/a&gt;&lt;div style="margin: 0px;"&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Akka actors platform -&amp;nbsp;&lt;a href="http://akka.io/"&gt;http://akka.io/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Jonas Bonér home page -&amp;nbsp;&lt;a href="http://jonasboner.com/"&gt;http://jonasboner.com/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Type conversion -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Type_conversion"&gt;http://en.wikipedia.org/wiki/Type_conversion&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Java Management Extensions (JMX) -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Java_Management_Extensions"&gt;http://en.wikipedia.org/wiki/Java_Management_Extensions&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Java Virtual Machine Tool Interface (JVM TI) -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Java_Virtual_Machine_Tools_Interface"&gt;http://en.wikipedia.org/wiki/Java_Virtual_Machine_Tools_Interface&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Btrace dynamic tracing tool -&amp;nbsp;&lt;a href="http://kenai.com/projects/btrace/pages/Home"&gt;http://kenai.com/projects/btrace/pages/Home&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Dynatrace monitoring production applications tool -&amp;nbsp;&lt;a href="http://www.dynatrace.com/en/"&gt;http://www.dynatrace.com/en/&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Job trends report on Scala jobs -&amp;nbsp;&lt;a href="http://www.indeed.com/jobtrends?q=scala&amp;amp;l="&gt;http://www.indeed.com/jobtrends?q=scala&amp;amp;l=&lt;/a&gt;&lt;/li&gt;&lt;li style="text-align: left;"&gt;Time to market -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Time_to_market"&gt;http://en.wikipedia.org/wiki/Time_to_market&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-5113471106041594770?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/5113471106041594770/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2011/01/moving-from-java-to-scala-one-year.html#comment-form' title='43 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/5113471106041594770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/5113471106041594770'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2011/01/moving-from-java-to-scala-one-year.html' title='Moving from Java to Scala - One year later...'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><thr:total>43</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-5830518000681321464</id><published>2010-11-25T05:04:00.000-08:00</published><updated>2010-12-01T23:57:00.263-08:00</updated><title type='text'>Analysing Betting Exchange markets with Complex Event Processing, Esper and Scala</title><content type='html'>&lt;div style="text-align: justify;"&gt;Recently, I posted on analysing betting exchange markets with &lt;a href="http://blog.danmachine.com/2010/08/horse-racing-market-simulation.html"&gt;b&lt;/a&gt;etting market simulator and time line charts (&lt;a href="http://blog.danmachine.com/2010/10/market-analysis-with-time-line-charts.html"&gt;read more...&lt;/a&gt;) At that time, I demonstrated charts with runner price that don't present a significant analytical value, except of being &amp;nbsp;a good example to introduce charting feature of betting market simulator. This day, I present how to analyse betting exchange markets with&amp;nbsp;&lt;a href="http://esper.codehaus.org/"&gt;Esper&lt;/a&gt;&amp;nbsp;complex event processing tool and Scala. This should be more useful in practice than studying simple metrics such as runner price or traded volume.&lt;br /&gt;&lt;br /&gt;Complex event processing is a broad concept. I use it for analysing different types of market data such as price, probability, traded volume, risk metrics, etc. Complex event processing allows me to combine all those metrics altogether and prepare custom analysis &amp;nbsp;quickly and with minimal programming effort. I found it useful in both real time event processing as well as in historical analyses. There are many complex event processing tools on the market, both commercial and open source. The one I use is Esper,&amp;nbsp;an open source tool that makes complex event processing simple in Java programming &amp;nbsp;language.&lt;br /&gt;&lt;br /&gt;One of core features of Esper is an ability to create sliding windows and then, on top of that, to calculate some metrics such as avg, min, max or recognise patterns such as correlation between runner price and runner traded volume.&amp;nbsp;Additionally,&amp;nbsp;sliding windows may be used to calculate derivatives, which is an example that I will present in this post. Basically, I will demonstrate how to calculate first derivative of runner traded volume with respect to time and then how to calculate the second derivative. I'm finding those metrics useful to analyse correlation between market runner implied probability and traded volume for betting markets.&lt;br /&gt;&lt;br /&gt;Below I present three charts for horse racing market during 10 minutes before market is turned in play. The first chart shows implied probability (1/runner price) for all market runners, for that, no complex event processing is required. The second chart presents the first derivative of traded volume with respect to time for all market runners, where as the last one displays the second derivative of runner traded volume.&lt;br /&gt;&lt;br /&gt;To create a chart with implied probabilities for all market runners, we need to iterate through all market runners, then calculate runner implied probability and add it to chart values that will be used to generate time&amp;nbsp; line chart after simulation with Market Simulator tool is finished:&lt;br /&gt;&lt;div style="margin: 0px;"&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt; &lt;span class="Apple-style-span" style="color: #134f5c;"&gt;-------------------------------------------------------------------------------------------------------------&lt;br /&gt;// For all market runners add implied probability to time line chart&lt;br /&gt;for(runnerId &amp;lt;- ctx.runners.map(_.runnerId)) {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;&amp;nbsp; //get best back and lay prices for market runner&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt; &amp;nbsp;&amp;nbsp;val bestPrices = ctx.getBestPrices(runnerId) &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;&amp;nbsp; // calculate average price between best back and lay prices&lt;br /&gt;&amp;nbsp;&amp;nbsp;val avgPrice = PriceUtil.avgPrice(bestPrices._1.price -&amp;gt; bestPrices._2 .price)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;&amp;nbsp; //add average prices to chart values&lt;br /&gt;&amp;nbsp;&amp;nbsp;ctx.addChartValue(runnerId.toString, 1/avgPrice)&lt;br /&gt;}&lt;br /&gt;-------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://code.google.com/p/betting-ai/source/browse/trunk/trader-examples/src/main/scala/dk/bettingai/trader/prob/ProbabilityTrader.scala"&gt;Scala class to calculate implied probability is here. &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_vHBR1L4_xvs/TOqi0xnJUgI/AAAAAAAAAKA/qPinBgMfK-A/s1600/probability_chart.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="206" src="http://4.bp.blogspot.com/_vHBR1L4_xvs/TOqi0xnJUgI/AAAAAAAAAKA/qPinBgMfK-A/s320/probability_chart.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: center;"&gt;Figure 1 Implied probability for all market runners, y_axis - traded volume, x_axis - time&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;In order to display derivative of runner traded volume with respect to time we use the following formula:&lt;br /&gt;&lt;br /&gt;y(v1,v0,t1,t0) = (v1 - v0) / (t1-t0) where&lt;br /&gt;&lt;ul&gt;&lt;li&gt;y -&amp;nbsp;derivative of runner traded volume with respect to time&lt;/li&gt;&lt;li&gt;v1- runner traded volume at time t1&lt;/li&gt;&lt;li&gt;v0 - runner traded volume at time t0&lt;/li&gt;&lt;li&gt;t1 - time t1, in this example t1-t0 = 120sec&lt;/li&gt;&lt;li&gt;t0 - time t0&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;To calculate this function value &amp;nbsp;for every second during last 10 minutes before horse racing market is turned in play, a sliding window is a way to go. Having a sliding window available for every second with a size of 120sec, we can obtain the first and the last values of traded volume in that window. The last value is a traded volume at time t1, whereas the first value is a traded volume at time t0, which is t1-120sec. All that to work requires just a bit of Esper declarative configuration.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div&gt;First of all, we need to send a timestamped event to Esper engine with trader volume for a market runner:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;-------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;//Create market event as a map with three attributes: runnerId, traded volume and timestamp&lt;br /&gt;val event = Map("runnerId" -&amp;gt; runnerId,"tradedVolume" -&amp;gt; ctx.getRunnerTradedVolume(runnerId).totalTradedVolume,"timestamp"-&amp;gt; ctx.getEventTimestamp/1000)&lt;br /&gt;&lt;br /&gt;//Send event to Esper&lt;br /&gt;epService.getEPRuntime().sendEvent(event, "TradedVolumeEvent")&lt;br /&gt;-------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;then we create a sql like query to calculate derivative value and register it with Esper engine.&amp;nbsp;One thing worth to mention is the last part of this query 'group by runnerId'. Events have to be grouped by runner id, because events for many market runners are processed.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="margin: 0px;"&gt;&lt;br /&gt;&lt;div&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;-------------------------------------------------------------------------------------------------------------&lt;br /&gt;val expression = "select runnerId, (last(tradedVolume)-first(tradedVolume)) / (last(timestamp)-first(timestamp)) as delta from TradedVolumeEvent.win:time(120 sec) group by runnerId"&lt;br /&gt;&lt;br /&gt;val statement = epService.getEPAdministrator().createEPL(expression)&lt;br /&gt;-------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;The value of this query is calculated every time when new event is added to Esper engine, a simple listener updates time line chart with derivative value:&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;-------------------------------------------------------------------------------------------------------------&lt;br /&gt;statement.addListener(new UpdateListener {&lt;br /&gt;&amp;nbsp;&amp;nbsp;def update(newEvents: Array[EventBean], oldEvents: Array[EventBean] ) {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;val delta = newEvents(0).get("runnerId"),newEvents(0).get("delta").asInstanceOf[Double]&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ctx.addChartValue("tv" + delta)&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;})&lt;br /&gt;-------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;a href="http://code.google.com/p/betting-ai/source/browse/trunk/trader-examples/src/main/scala/dk/bettingai/trader/tradedvolumedelta/TradedVolumeDeltaTrader.scala"&gt;Scala class to calculate derivative of traded volume is here. &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_vHBR1L4_xvs/TOqi642CLII/AAAAAAAAAKE/Yx61eKkYw64/s1600/traded_volume_delta_chart.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="207" src="http://4.bp.blogspot.com/_vHBR1L4_xvs/TOqi642CLII/AAAAAAAAAKE/Yx61eKkYw64/s320/traded_volume_delta_chart.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: center;"&gt;Figure 2 Derivative of traded volume for all market runners with respect to time&lt;/div&gt;&lt;br /&gt;&lt;div style="margin: 0px;"&gt;&lt;div&gt;Calculating the second derivative of runner traded volume requires two phases. First of all, the first derivative of traded volume is calculated and added to Esper engine as an event:&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;-------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;insert into TradedVolumeDeltaEvent select runnerId,timestamp,(last(tradedVolume)-first(tradedVolume))/(last(timestamp)-first(timestamp)) as tradedVolumeDelta from TradedVolumeEvent.win:time(120 sec) group by runnerId&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;-------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;Then the second derivative is calculated using sql like query:&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;-&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;select runnerId,(last(tradedVolumeDelta)-first(tradedVolumeDelta))/(last(timestamp)-first(timestamp)) as tradedVolumeDeltaPrim from TradedVolumeDeltaEvent.win:time(120 sec) group by runnerId&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;-------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;a href="http://code.google.com/p/betting-ai/source/browse/trunk/trader-examples/src/main/scala/dk/bettingai/trader/tradedvolumedeltaprim/TradedVolumeDeltaPrimTrader.scala"&gt;Scala class to calculate the second derivative of traded volume is here.&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_vHBR1L4_xvs/TOqjBA6-GeI/AAAAAAAAAKI/DO9nCs0mt-o/s1600/traded_volume_deltaprim_chart.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="207" src="http://2.bp.blogspot.com/_vHBR1L4_xvs/TOqjBA6-GeI/AAAAAAAAAKI/DO9nCs0mt-o/s320/traded_volume_deltaprim_chart.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: center;"&gt;Figure 3 Second derivative of traded volume for all market runners with respect to time.&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;There are junit tests for all three scala classes that I'm referring to (&lt;a href="http://code.google.com/p/betting-ai/source/browse/trunk/trader-examples/#trader-examples/src/test/scala/dk/bettingai/trader"&gt;here&lt;/a&gt;), so you can run them yourself if you want to play with examples on complex event processing that I presented in this post. Those junit tests generate the same html graphs as above into a target directory. Eventually please use maven command 'mvn clean install' inside&amp;nbsp;&lt;a href="http://code.google.com/p/betting-ai/source/browse/trunk/trader-examples/"&gt;http://code.google.com/p/betting-ai/source/browse/trunk/trader-examples/&lt;/a&gt;&amp;nbsp;to run all junit tests with one call.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;References:&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ol&gt;&lt;li&gt;Complex Event Processing -&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Complex_event_processing"&gt;http://en.wikipedia.org/wiki/Complex_event_processing&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Esper -&amp;nbsp;&lt;a href="http://esper.codehaus.org/"&gt;http://esper.codehaus.org/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Scala -&amp;nbsp;&lt;a href="http://www.scala-lang.org/"&gt;http://www.scala-lang.org/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Betting Market Simulator -&amp;nbsp;&lt;a href="http://code.google.com/p/betting-ai/"&gt;http://code.google.com/p/betting-ai/&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-5830518000681321464?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/5830518000681321464/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2010/11/analysing-betting-exchange-markets-with.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/5830518000681321464'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/5830518000681321464'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2010/11/analysing-betting-exchange-markets-with.html' title='Analysing Betting Exchange markets with Complex Event Processing, Esper and Scala'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_vHBR1L4_xvs/TOqi0xnJUgI/AAAAAAAAAKA/qPinBgMfK-A/s72-c/probability_chart.png' height='72' width='72'/><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-7471838608484692452</id><published>2010-10-22T05:12:00.000-07:00</published><updated>2010-10-23T02:32:40.093-07:00</updated><title type='text'>Market analysis with time line charts</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;In my last post I was writing about&amp;nbsp;analysing&amp;nbsp;trading strategies with a &lt;a href="http://blog.danmachine.com/2010/08/horse-racing-market-simulation.html"&gt;market simulator&lt;/a&gt;. This time I'd like to present a charts feature that makes it easier to analyse trading strategies. Before I start, a bit of information for those who read my blog for the first time.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The &lt;a href="http://blog.danmachine.com/2010/08/horse-racing-market-simulation.html"&gt;market simulator&lt;/a&gt; I'm referring to, allows for betfair market simulations that produce results very close to running trading strategies on real betfair markets. It's due to replaying market in a form of bet placement events on a real betting exchange engine.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Time line charts can present any data including standard metrics such as price, probability, traded volume, customer ifwin, customer expected liability, etc, as well as any transformation of those basic metrics, e.g. math functions such as derivativess, statistical, etc. I present below three chart examples. The first chart represents probability for all market runners during last 10 minutes before market is turned in play.&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_vHBR1L4_xvs/TMFlTaGdYuI/AAAAAAAAAJw/wX2AhZCszRY/s1600/trading_chart_prob" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="207" src="http://1.bp.blogspot.com/_vHBR1L4_xvs/TMFlTaGdYuI/AAAAAAAAAJw/wX2AhZCszRY/s320/trading_chart_prob" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;1. Probability for all market runners&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Where as the second and third charts present market expected profit for two different trading strategies. As you can see, one of them generates profit, while the next one generates loss.&amp;nbsp;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_vHBR1L4_xvs/TMFtcu82gJI/AAAAAAAAAJ0/jLNgHhqKfGM/s1600/trading_chart_exp1" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="207" src="http://2.bp.blogspot.com/_vHBR1L4_xvs/TMFtcu82gJI/AAAAAAAAAJ0/jLNgHhqKfGM/s320/trading_chart_exp1" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&amp;nbsp;2. Market current expected for a market (profit)&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_vHBR1L4_xvs/TMFtrPGMt6I/AAAAAAAAAJ4/BqhjtIcmMkY/s1600/trading_chart_exp2" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="208" src="http://2.bp.blogspot.com/_vHBR1L4_xvs/TMFtrPGMt6I/AAAAAAAAAJ4/BqhjtIcmMkY/s320/trading_chart_exp2" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&amp;nbsp; 3. Market current expected for a market (loss)&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;One more thing worth to mention is a great flexibility that makes it possible to presents aggregated metrics across both time and many markets. What metrics are&amp;nbsp;presented&amp;nbsp;is up to a trader implementation class. Consider the trader implementation below:&lt;/div&gt;&lt;br /&gt;def execute(eventTimestamp:Long,ctx: ITraderContext)= {&lt;br /&gt;&amp;nbsp; if(bestPrices._2.price&amp;gt;2)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ctc.placeBet(2,bestPrices._2.price,BACK,runnerId)&lt;br /&gt;&amp;nbsp; ctx.addChartValues(ctx.risk.ifWin) &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;There is a method on a trader context named ctx.addChartValues(...), that adds timestamped metrics to be displayed on a chart after simulation is finished. Let say we want to present log(ifWin), then just call:&lt;/div&gt;&lt;br /&gt;ctx.addChartValues(log(ctx.risk.ifWin))&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;References&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Background, vision and high level design of the market simulator:&amp;nbsp;&lt;a href="http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence.html"&gt;http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence.html&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="https://docs.google.com/leaf?id=0AQAuZwf4UIO6ZGZmemcyNF8xNDM3MnQybWRz&amp;amp;sort=name&amp;amp;layout=list&amp;amp;pid=0BwAuZwf4UIO6OGExYjRhODgtZjk1MS00OWRlLWI0MzktNTY2YzBkN2RhYjA5"&gt;&lt;/a&gt;&amp;nbsp;Background, vision and high level design of the market data collector:&amp;nbsp;&lt;a href="http://blog.danmachine.com/2010/07/bettingai-market-data-collector-design.html"&gt;http://blog.danmachine.com/2010/07/bettingai-market-data-collector-design.html&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Project home page:&amp;nbsp;&lt;a href="http://code.google.com/p/betting-ai/"&gt;http://code.google.com/p/betting-ai/&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-7471838608484692452?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/7471838608484692452/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2010/10/market-analysis-with-time-line-charts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/7471838608484692452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/7471838608484692452'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2010/10/market-analysis-with-time-line-charts.html' title='Market analysis with time line charts'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_vHBR1L4_xvs/TMFlTaGdYuI/AAAAAAAAAJw/wX2AhZCszRY/s72-c/trading_chart_prob' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-846954188537793501</id><published>2010-08-27T05:14:00.000-07:00</published><updated>2010-08-27T05:22:30.140-07:00</updated><title type='text'>Horse racing market simulation</title><content type='html'>&lt;div style="text-align: justify;"&gt;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):&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;***********************************************************************************&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;*Market Simulator Copyright 2010 Daniel Korzekwa(http://danmachine.com) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;*Project homepage: http://code.google.com/p/betting-ai/ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;*Licenced under Apache License 2.0(http://www.apache.org/licenses/LICENSE-2.0) &amp;nbsp; &amp;nbsp;*&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;***********************************************************************************&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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%&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Simulation is finished in 65907 milliseconds.&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Expected profit report for trader dk.trader.Trader:&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;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&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;------------------------------------------------------------------------------------&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;TotalExpectedProfit=-149.05 TotalMatchedBets=5044 TotalUnmachedBets=249&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;The list below presents a few market events for a horse racing market:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;{"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"}]}&lt;br /&gt;{"time":1282481934744,"eventType":"PLACE_BET","betSize":38.0,"betPrice":5.9,"betType":"LAY","marketId":101655582,"runnerId":4818333}&lt;br /&gt;...&lt;br /&gt;{"time":1282482515736,"eventType":"PLACE_BET","betSize":314.0,"betPrice":1.61,"betType":"BACK","marketId":101655582,"runnerId":4848193}&lt;br /&gt;{"time":1282482515736,"eventType":"CANCEL_BETS","betsSize":5.0,"betPrice":18.0,"betType":"LAY","marketId":101655582,"runnerId":4932435}&lt;br /&gt;{"time":1282482515736,"eventType":"PLACE_BET","betSize":17.0,"betPrice":20.0,"betType":"LAY","marketId":101655582,"runnerId":4932435}&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Example of trader implementation:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;/**Executes trader implementation so it can analyse market on a betting exchange and take appropriate bet placement decisions.&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; *&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; * @param ctx Provides market data and market operations that can be used by trader to place bets on a betting exchange market&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; */&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;def execute(ctx: ITraderContext) = {&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;for(runner &amp;lt;- ctx.runners) {&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;val bestPrices = ctx.getBestPrices(runner.runnerId)&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;if(bestPrices._1&amp;gt;2) {&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;ctx.placeBet(2,bestPrices._1,BACK,runner.runnerId)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;ctx.placeBet(2,bestPrices._1 - 0.02,LAY,runner.runnerId)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;}&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;if(bestPrices._2&amp;lt;2.2) {&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;ctx.placeBet(2,bestPrices._2,LAY,runner.runnerId)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;ctx.placeBet(2,bestPrices._2 + 0.02,BACK,runner.runnerId)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;}&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Project home page&lt;/b&gt;&lt;br /&gt;&lt;a href="http://code.google.com/p/betting-ai/"&gt;http://code.google.com/p/betting-ai/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-846954188537793501?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/846954188537793501/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2010/08/horse-racing-market-simulation.html#comment-form' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/846954188537793501'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/846954188537793501'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2010/08/horse-racing-market-simulation.html' title='Horse racing market simulation'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-7614768418131655328</id><published>2010-07-07T04:45:00.000-07:00</published><updated>2010-07-07T05:11:08.781-07:00</updated><title type='text'>The BettingAI  - Market Data Collector  Design</title><content type='html'>&lt;h3 style="font-family: Verdana; font-size: 12pt;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;Background&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;&lt;div style="direction: inherit; font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: justify;"&gt;Trading analyst wants to analyse trading strategies using historical market data and&amp;nbsp;&lt;a href="http://code.google.com/p/betting-ai/" id="rkau" target="_blank" title="the Market Simulator tool"&gt;the Market Simulator tool&lt;/a&gt;. For the purpose of that, a real market data for markets on the Betfair betting exchange has to be collected.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style="font-family: Verdana; font-size: 12pt;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7538904595934077017&amp;amp;postID=7614768418131655328" id="Vision_0013168621808290482_440" name="Vision_0013168621808290482_440"&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;Vision&lt;/span&gt;&lt;/h3&gt;&lt;div style="direction: inherit; font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;&lt;br /&gt;The vision is to create a standalone application that is collecting market data until &amp;nbsp;it is terminated by a user. Collected market data is written to files on a file system (one file per market) in a format that is supported by&amp;nbsp;&lt;a href="http://code.google.com/p/betting-ai/" id="f97." target="_blank" title="the Market Simulator tool"&gt;the Market Simulator tool&lt;/a&gt;.&amp;nbsp;&lt;/div&gt;&lt;div style="direction: inherit; font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="direction: inherit; font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;The following input parameters for the application are provided:&lt;/div&gt;&lt;div style="direction: inherit; font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Betfair account credentials: user name, password and product id.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Time interval of the market data collection.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style="direction: inherit; font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="direction: inherit; font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;&lt;div style="direction: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: justify;"&gt;The market data should be collected for:&lt;/div&gt;&lt;div style="direction: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: justify;"&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Horse racing win only markets.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;The time period starting 10 minutes before market start time until market is turned in play.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;br /&gt;&lt;h3 style="font-family: Verdana; font-size: 12pt;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;Requirements&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="direction: inherit; font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;As a trading analyst.&lt;/span&gt;&lt;br /&gt;&lt;div style="direction: inherit; font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;I want to collect market data for markets on the Betfair betting exchange.&lt;br /&gt;&lt;div style="direction: inherit; margin-bottom: 0px; margin-top: 0px;"&gt;So that I can run market simulation and test trading strategy for a real market data.&lt;/div&gt;&lt;br /&gt;&lt;div style="direction: inherit; margin-bottom: 0px; margin-top: 0px;"&gt;Acceptance criteria:&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Market data is collected in a format that is support by the&amp;nbsp;&lt;a href="http://code.google.com/p/betting-ai/" id="hwx4" target="_blank" title="MarketSimulator ver 1.0"&gt;MarketSimulator ver 1.0&lt;/a&gt;&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;a href="http://code.google.com/p/betting-ai/" id="hwx4" target="_blank" title="MarketSimulator ver 1.0"&gt;&lt;/a&gt;Market data is stored in text files (one file per one market)&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Market data is collected for all Horse Racing win only markets.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Market data is collected starting 10 minutes before market start time until it's turned in play.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Installation package supported by both Windows and Linux operating systems is provided.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Command line interface is provided with the following input parameters:&amp;nbsp;&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Betfair account credentials: user name, password and product id.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Time interval of the market data collection.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;/ul&gt;&lt;div style="direction: inherit; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;h3 style="font-family: Verdana; font-size: 12pt;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;User interface&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;&lt;br /&gt;As a trading analyst I want to start market data collector from the command line interface as presented below:&lt;br /&gt;&lt;br /&gt;MarketDataCollector bfUser=john bfPassword=bravo6 bfProductId=82 collectionInterval=1&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;user name, password and product id - Credentials for the Betfair account that is used for market data collection.&amp;nbsp;&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;collectionInterval [seconds] - The time interval for the market data collection.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;[BEGINNING OF THE OUTPUT]&lt;/span&gt;&lt;br /&gt;&lt;div style="direction: inherit; font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;Market data collection is started.&lt;/div&gt;&lt;div style="direction: inherit; font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;[THE END OF THE OUTPUT]&lt;br /&gt;&lt;br /&gt;&lt;h3 style="font-family: Verdana; font-size: 12pt;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;Component design&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_vHBR1L4_xvs/TDRooK-M83I/AAAAAAAAAJA/Iax7FcUoBaQ/s1600/MarketDataCollector+-+component+design.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_vHBR1L4_xvs/TDRooK-M83I/AAAAAAAAAJA/Iax7FcUoBaQ/s320/MarketDataCollector+-+component+design.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="direction: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="direction: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="direction: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;"&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Market Data Collector Launcher - Parses input parameters and starts scheduler for Market Data Collector Task.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Market Data Collector Task - Gets market events for all monitored markets and stores them in files on a file system (one file per market).&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Market Event Producer&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;First of all, get list of all monitored markets from the betfair api. Then for each market do the following:&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Get market prices and total traded volume from the Betfair API.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Calculate market events that represent the delta between previous and current state of the market. If no previous market state is available then CREATE_MARKET event will be generated as the first on the list.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Add those market events to the Betex (Implementation of a betting exchange), then get market prices and total traded volume for the market and compare both data against market prices and total traded volume that was received from the Betfair API. The reason for that is to check if market events have been generated correctly. If both data don't match then exception should be thrown.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;After all markets are processed, market events for all market are returned.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Market Event Calculator - Calculates market events that represent the delta between previous and current state of the market. If no previous market state is available then CREATE_MARKET event will be generated as the first event on the list.&lt;/li&gt;&lt;/ul&gt;&lt;div style="direction: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style="font-family: Verdana; font-size: 12pt;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;Deployment design&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: medium; font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_vHBR1L4_xvs/TDRos6A8HmI/AAAAAAAAAJI/Zvlgs9n5gXw/s1600/MarketDataCollector+-+deployment+design.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_vHBR1L4_xvs/TDRos6A8HmI/AAAAAAAAAJI/Zvlgs9n5gXw/s320/MarketDataCollector+-+deployment+design.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="direction: inherit; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Java VM - The Betting AI application is written in the Scala programming language that is running within the Java virtual machine.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Scala - The scala language distribution, contains scala libraries that are required to run scala applications.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Market Data Collection - Executables of the Market Data Collector, contains start script to run market data collection.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;File system - Market Data Collector is storing collected market data on a files system (one file per market).&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Betfair API WS - This is Betfair public API that is used to collect market data.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-7614768418131655328?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/7614768418131655328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2010/07/bettingai-market-data-collector-design.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/7614768418131655328'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/7614768418131655328'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2010/07/bettingai-market-data-collector-design.html' title='The BettingAI  - Market Data Collector  Design'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_vHBR1L4_xvs/TDRooK-M83I/AAAAAAAAAJA/Iax7FcUoBaQ/s72-c/MarketDataCollector+-+component+design.png' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-583898972577296958</id><published>2010-04-19T02:54:00.000-07:00</published><updated>2010-04-19T09:06:51.856-07:00</updated><title type='text'>The Betting AI (Artificial intelligence) - domain model, components, deployment</title><content type='html'>&lt;a href="http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence-user.html"&gt;Previous part of the betting ai design.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;b&gt;Domain model&lt;/b&gt;&lt;/h3&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_vHBR1L4_xvs/S8wpr5YWGPI/AAAAAAAAAIg/8M1mdyfBOdA/s1600/11" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_vHBR1L4_xvs/S8wpr5YWGPI/AAAAAAAAAIg/8M1mdyfBOdA/s320/11" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style="font-size: small;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Betting Exchange - "...is a form of bookmaking in which the operator offsets its risk perfectly through technology, such that the effect to the customer is that customers are seen to bet between themselves..." - from &lt;a href="http://en.wikipedia.org/wiki/Betting_exchange" id="zd8n" title="Wikipedia"&gt;Wikipedia&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Market - "...The market is where you place a bet on an event. Any given event, such as a soccer match, may have a number of different markets: for example, Match Odds, a Handicap and First Goalscorer markets. This is the place to view the odds and have a bet..." - from &lt;a href="http://help.betfair.com/glossary/m.en.html#market" id="xrcd" title="Betfair help"&gt;Betfair help&lt;/a&gt;.&lt;/li&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;market id - Unique &amp;nbsp;market id.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;market name - e.g. Match Odds or Place market&lt;/li&gt;&lt;li style="text-align: justify;"&gt;event name - e.g. Mat Utd vs Arsenal&lt;/li&gt;&lt;li style="text-align: justify;"&gt;market state -&amp;nbsp;&lt;span style="font-family: verdana,sans-serif;"&gt;active/in play/settled&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: justify;"&gt;&lt;span style="font-family: verdana,sans-serif;"&gt;selection id - Unique selection id, e.g. 100 for Manchester United and 101 for Arsenal.&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: justify;"&gt;&lt;span style="font-family: verdana,sans-serif;"&gt;selection name - e.g. Arsenal&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Bet - "...A ‘Back’ bet is a bet on something to happen – a horse to win a race, a football team to win, a person to be evicted from Big Brother etc. It’s just like the bet you’d regularly place with a traditional bookmaker or tote, or even with your mates..." - from &lt;a href="http://help.betfair.com/contents/itemId/i65767719/index.en.html" id="oq9s" title="Betfair help"&gt;Betfair help&lt;/a&gt;. "...Laying a bet means you are betting on something not to happen – a match not to end in a draw, a horse not to come in first, a rugby team not to win by over 7 pts etc..." - from &lt;a href="http://help.betfair.com/contents/itemId/i65767719/index.en.html" id="bm3i" title="Betfair help"&gt;Betfair help&lt;/a&gt;&lt;/li&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;bet price - Bet odds. Chances of winning written in a decimal format = 1/probability, e.g. 1/0.5 = 2 ( fifty-fifty).&lt;/li&gt;&lt;li style="text-align: justify;"&gt;bet size, e.g. 20£&lt;/li&gt;&lt;li style="text-align: justify;"&gt;bet type - Back or lay.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;market id/selection id - Unique id of a particular selection in a given market.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;bet status - Unmatched, matched, cancelled (by user), lapsed (by a betting exchange, e.g. when market is turned in play), settled.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Historical market data - Represents the whole market life cycle: market creation, bet placement, turning market in play, bet placement in play and market settlement. It allows to replay a market from the past.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Trader - Responsible for analysing market and taking appropriate bet placement decision. The aim of bet placement is to guarantee the highest profit with the lowest risk. There are two types of traders, a real trader that is represented by human and artificial trader that is represented by computer software. The main aim of this project is to provide a simulation environment for testing artificial traders.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Expected profit - This is a measure that tells, what would be the profit in a long term if the same market was processed many times. For instance if the expected market profit is 10, then it means that for 100 'exactly the same' markets the profit would be 1000. It may happen that for the first market the profit will be -23 and for the next market it will be 12, but in total, based on a theory of probability it should be approximately 1000.&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Component design&lt;/h3&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_vHBR1L4_xvs/S8wp0MClrkI/AAAAAAAAAIo/16wOktywhdo/s1600/2" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_vHBR1L4_xvs/S8wp0MClrkI/AAAAAAAAAIo/16wOktywhdo/s320/2" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Components:&amp;nbsp;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;User - A person who is using the market simulation. Usually it's a market analyst or a real trader.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Simulator App - Provides a command line interface to the market simulation. Read the configuration of the historical market data and the trader implementation, runs simulation and displays expected profit report on the screen.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Simulator - Does exactly the same as a simulator application, but provides application programming interface instead of command line interface.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Market Event Processor - Parses historical market event in a string format, e.g. CREATE_MARKET and calls appropriate method on a betting exchange, e.g. createMarket(market:Market)&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Trader - Analyses markets on a betting exchange and places bets.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Expected Profit Calculator - Reads matched bets for user (e.g. trader) from a betting exchange and calculates expected market profit report.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;Betex - It's a betting exchange that provide peer-to-peer betting services.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Flow of control:&lt;/div&gt;&lt;ol&gt;&lt;li style="text-align: justify;"&gt;User starts the market simulator giving the path to the file with the historical market data and the name of the trader implementation class. After the market simulation is finished the market expected profit report for the trader is printed on the screen.&lt;/li&gt;&lt;/ol&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ol start="2"&gt;&lt;li style="text-align: justify;"&gt;The Simulator Application calls the Simulator component with the input parameters provided by the user.&lt;/li&gt;&lt;/ol&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ol start="3"&gt;&lt;li style="text-align: justify;"&gt;The Simulator component reads the file with historical market data and for each historal market event, calls both MarketEventProcessor and Trader. After all historical market events are processed, it calls the ExpectedProfitCalculator to get the market expected profit report.&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;Deployment design&lt;/h3&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_vHBR1L4_xvs/S8x_kzg5BPI/AAAAAAAAAI4/wBG-I_ppECs/s1600/4" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_vHBR1L4_xvs/S8x_kzg5BPI/AAAAAAAAAI4/wBG-I_ppECs/s320/4" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Java VM - The Betting AI application will be written in the Scala programming language that is running within the Java virtual machine.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Scala - The scala language distribution, contains scala libraries that are required to run scala applications.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Betting AI application - Binaries of the betting ai application, contains start script to run market simulation.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Historical market data file - This file contains historical market data that is used for market simulation. &lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Trader implementation class - This file contains trader implementation that market simulation is executed for.&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;References&lt;/h3&gt;Project home page:&lt;a href="http://code.google.com/p/betting-ai/"&gt; http://code.google.com/p/betting-ai/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-583898972577296958?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/583898972577296958/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence_19.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/583898972577296958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/583898972577296958'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence_19.html' title='The Betting AI (Artificial intelligence) - domain model, components, deployment'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_vHBR1L4_xvs/S8wpr5YWGPI/AAAAAAAAAIg/8M1mdyfBOdA/s72-c/11' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-3715995008158547064</id><published>2010-04-14T01:17:00.000-07:00</published><updated>2010-04-19T03:04:09.572-07:00</updated><title type='text'>The Betting AI (Artificial intelligence) - user interface and input data</title><content type='html'>&lt;a href="http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence_09.html"&gt;Previous part of the betting ai design.&lt;/a&gt;&lt;br /&gt;&lt;a href="http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence_19.html"&gt;Next part of the betting ai design. &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3 style="font-size: 12pt;"&gt;User interface&lt;/h3&gt;As a trading analyst I want to run the market simulation from a command line interface as presented below:&lt;br /&gt;&lt;br /&gt;app_name marketData=[market_data_file] traderImpl=[trader_impl_class]&lt;br /&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;app_name - Name of the application, e.g. market_simulator&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;marketData - Text file with market data that will be used for the simulation. Go to the next chapter 'Input data' for more details.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;traderImpl - Fully classified name of the trader implementation class that the simulation will be executed for. Go to the next chapter 'Input data' for more details.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;After simulation is started, the following output is presented on the screen:&lt;br /&gt;&lt;br /&gt;[BEGINNING Of THE OUTPUT]&lt;br /&gt;&lt;br /&gt;Simulation is started.&lt;br /&gt;Simulation progress: 1% 2% 3% 4% 5% 6% ....................................................... .................................................................................................................&lt;br /&gt;..................................100%&lt;br /&gt;Simulation is finished in 23 sec.&lt;br /&gt;&lt;br /&gt;Expected profit report for trader com.dk.bettingai.trader.SimpleTraderImpl:&lt;br /&gt;&lt;br /&gt;&lt;span class="GlobalBoldedText Apple-style-span"&gt;Catt 7th Apr&lt;/span&gt;: 14:10 7f Claim Stks&amp;nbsp;&amp;nbsp;&amp;nbsp; expProfit=28 expAggrProfit=28&amp;nbsp; mBets=34 uBets=17&lt;br /&gt;&lt;span class="GlobalBoldedText Apple-style-span"&gt;Catt 7th Apr&lt;/span&gt;: 14:40 1m6f Hcap &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; expProfit=4&amp;nbsp;&amp;nbsp; expAggrProfit=32&amp;nbsp; mBets=27 uBets=2&lt;br /&gt;...&lt;br /&gt;&lt;span class="GlobalBoldedText Apple-style-span"&gt;&lt;span class="GlobalBoldedText Apple-style-span"&gt;Nott 7th Apr&lt;/span&gt;&lt;/span&gt;: 17:20 1m Hcap &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; expProfit=-6&amp;nbsp; expAggrProfit=136 mBets=45 uBets=57&lt;br /&gt;-------------------------------------------------------------------------------------&lt;br /&gt;TotalExpectedProfit=136 TotalMatchedBets=457 TotalUnmachedBets=262&lt;br /&gt;[END Of THE OUTPUT]&lt;br /&gt;&lt;br /&gt;Definitions:&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;expProfit - Expected market profit based on all matched bets on the market placed by trader.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;expAggrProfit- Expected profit for the market and all prior markets.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;mBets - Number of matched bets on the market placed by trader.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;uBets - Number of unmatched bets on the market placed by trader.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;TotalExpectedProfit - Expected profit for all markets and all matched bets placed by trader.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;TotalMatchedBets - Number of all matched bets for all markets placed by trader.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;TotalUnmatchedBets - Number of all unmatched bets for all markets placed by trader.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h3 style="font-size: 12pt;"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=7538904595934077017&amp;amp;postID=3715995008158547064" id="Input_data_8132565543055534_90_4054775983095169" name="Input_data_8132565543055534_90_4054775983095169"&gt;&lt;/a&gt;Input data&lt;/h3&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;To run the market simulation, user has to provide the historical market data and the trader implementation class.&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;The historical market data is provided as a text file, that contains the number of events for the market management and the bet placement. The list below presents all possible event types:&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;CREATE_MARKET&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Market id, market name, event name, number of winners, market time.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;List of selections: selection id, selection name.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;TURN_MARKET_INPLAY&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Market id.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;SETTLE_MARKET&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Market id, list of selection ids for winners.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;PLACE_BET&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Bet size, bet price, bet type (back/lay), market id, selection id.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;CANCEL_BET&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Bet id.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;The trader implementation class implements the following interface:&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Interface name: Trader&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;Interface operations:&amp;nbsp;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;execute():void&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;setBetexPublicApi(betexPublicApi: BetexPublicApi):void&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-top: 0px;"&gt;BetexPublicApi:&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;getActiveMarkets&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Input - None.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Output -&amp;nbsp; All markets that are not closed. The following attributes are returned: market id, market name, event name, market time.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;getMarketData&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Input - Market id.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: verdana,sans-serif;"&gt;Output - All back and lay stakes for each price on the exchange for a given market.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: verdana,sans-serif;"&gt;Output - Market id, market name, event name, selection ids/names, number of winners, market status (active/in play/settled), market time.&lt;/span&gt;&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: verdana,sans-serif;"&gt;Output - matched amounts at each price on all of the runners.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;placeBet - Place a bet on a betting exchange.&amp;nbsp;&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Input: Bet size, bet price, bet type (back/lay), market id, selection id&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;cancelBet - Cancel a bet.&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Input - Bet id.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Output - None.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;getBets - Returns bets for a given user on a betting exchange&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Input: User id, bet status (matched, unmatched, matched_unmatched, settled, cancelled, lapsed)&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Output: List of bets (bet id, bet size, bet price, bet type, market id, selection id, bet status).&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;h3 style="font-size: 12pt;"&gt;References&lt;/h3&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #333333; font-family: 'Trebuchet MS',Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;"&gt;Project home page:&amp;nbsp;&lt;a href="http://code.google.com/p/betting-ai/" style="color: #445566;"&gt;http://code.google.com/p/betting-ai/&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-3715995008158547064?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/3715995008158547064/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence-user.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/3715995008158547064'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/3715995008158547064'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence-user.html' title='The Betting AI (Artificial intelligence) - user interface and input data'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-2623232210771286516</id><published>2010-04-09T04:14:00.000-07:00</published><updated>2010-04-14T01:36:05.268-07:00</updated><title type='text'>The Betting AI (Artificial intelligence) - requirements</title><content type='html'>&lt;a href="http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence.html"&gt;Previous part of the betting ai design.&lt;/a&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #333333; font-family: 'Trebuchet MS', Verdana, Arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;a href="http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence-user.html"&gt;Next part of the betting ai design.&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 16px;"&gt;Functional requirements&lt;/span&gt;&lt;/h3&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;Use case scenario:&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;As a trading analyst&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;I want to choose historical market data for the simulation, e.g. all market data for the period from 01.02.2010 to 10.02.2010&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Historical market data represents the whole market life cycle: market creation, bet placement, turning market in play, bet placement in play and market settlement.&lt;/li&gt;&lt;/ul&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;Then I want to choose trader implementation that the bet placement intelligence should be tested for.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px;"&gt;Trader implementation should be executed every time the historical market event is processed. For instance when market is created or when bet is placed or market is turned in play. When trader is executed it can check the market state, runner prices, etc. and take appropriate trading decisions.&lt;/li&gt;&lt;/ul&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;Then I want to run simulation.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;The aim of the simulation is to test, how a trader implementation would behave if it was running live on the betting exchange. Of course the market simulation will never return the same results as testing trader on a real betting exchange, however they both should be similar as far as possible.&lt;/li&gt;&lt;/ul&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Finally I want to see expected trader profit based on matched bets placed by trader and market probabilities derived from market prices before market is turned in play.&lt;/div&gt;&lt;ul style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Expected trader profit for market tells us what would be the profit in a long term if this market was processed many times. For instance if the expected market profit is 10, then it means that for 100 exactly the same markets the profit would be 1000. It may happen that for the first market the profit will be -23 and for next market it will be 12, but in total, based on a theory of probability it should be approximately 1000.&lt;/li&gt;&lt;/ul&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;h3 style="font-family: Verdana; font-size: 12pt;"&gt;Non-functional requirements&lt;/h3&gt;&lt;ul style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Performance - Running the market simulation for 10 markets with 10 runners each and collected data for 10 minutes with 1 second interval should take maximum 1 second.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Command line interface - The market simulation should be started from the command line interface.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Multi-platform - It should be possible to run the market simulation on Windows and Linux operating systems.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Historical market data - All historical market data for the market simulation should be read from a single file on a file system.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Installation - The application for the market simulation should be delivered as a zip file. To install and run the market simulation the following steps should be required:&lt;/li&gt;&lt;ul style="margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Unzip the application.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Go to the application folder.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Run start script and provide file with the historical market data and the trader implementation.&lt;/li&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Print the simulation report to the output screen.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana; font-size: 13px; margin-bottom: 0px; margin-top: 0px;"&gt;&lt;li style="margin-bottom: 0px; margin-top: 0px; text-align: justify;"&gt;Easy to run the market simulation for different traders - Running the market simulation for different traders should require only to change the name of the trader provided on the command line interface.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;h3 style="font-family: Verdana; font-size: 12pt;"&gt;References&lt;/h3&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;&lt;span class="Apple-style-span" style="color: #333333; font-family: 'Trebuchet MS', Verdana, Arial, sans-serif; line-height: 18px;"&gt;Project home page:&amp;nbsp;&lt;a href="http://code.google.com/p/betting-ai/" style="color: #445566;"&gt;http://code.google.com/p/betting-ai/&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-2623232210771286516?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/2623232210771286516/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence_09.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/2623232210771286516'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/2623232210771286516'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence_09.html' title='The Betting AI (Artificial intelligence) - requirements'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-3083910532136060593</id><published>2010-04-05T02:30:00.000-07:00</published><updated>2011-01-30T15:59:04.857-08:00</updated><title type='text'>The Betting AI (Artificial intelligence) - project initiation</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;a href="http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence_09.html"&gt;Next part of the betting ai design.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span"&gt;Background&lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;In 2008 I started a research project that was to analyse and understand behaviours on a betting exchange. On the beginning of my research I created &lt;a href="http://code.google.com/p/flexibet/"&gt;FlexiBet&lt;/a&gt;, automated betting system based on state machines. For the purpose of the Flexibet project I developed &lt;a href="http://blog.danmachine.com/2009/04/trading-at-betfair-betting-exchange.html"&gt;betting-scxml&lt;/a&gt;, domain specific language for creating automated betting strategies based on &lt;a href="http://en.wikipedia.org/wiki/SCXML"&gt;SCXML&lt;/a&gt; state machines.&amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Having that, I created a few betting strategies and I put them live to get some data to analyse. In the next step I analysed collected data, then I created new betting strategy and I put it live again to get more data to analyse.&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;I was evolving betting strategies and analysing collected data for one year or so, until it became time consuming and difficult to continue. It was because of using manual data analysis, mostly based on SQL and Eclipse Birt Business Intelligence. Despite of being simple and handy for creating simple reports, I found it difficult to analyse complex data.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: auto;"&gt;&lt;div style="text-align: auto;"&gt;&lt;b&gt;Vision&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The vision is to apply neural network technique to analyse markets on a betting exchange. I want to create a trader based on a neural network that can take appropriate bet placement decisions. Then, trader should be tested on a historical market data to measure how efficient the trader's intelligence is.&lt;/div&gt;&lt;br /&gt;Use case scenario:&lt;br /&gt;I want to choose historical market data for the simulation, e.g. all market data for the period from 01.02.2010 to 10.02.2010&lt;br /&gt;&lt;br /&gt;Then I want to choose trader implementation that the bet placement intelligence should be tested for.&lt;br /&gt;&lt;br /&gt;Then I want to run simulation.&lt;br /&gt;&lt;br /&gt;Finally I want to see expected trader profit based on matched bets placed by trader and market probabilities derived from market prices before market is turned in play.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;References&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;Project home page: &lt;a href="http://code.google.com/p/betting-ai/"&gt;http://code.google.com/p/betting-ai/&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-3083910532136060593?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/3083910532136060593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/3083910532136060593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/3083910532136060593'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2010/04/betting-ai-artificial-intelligence.html' title='The Betting AI (Artificial intelligence) - project initiation'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-2525672796815181573</id><published>2009-12-29T02:58:00.000-08:00</published><updated>2010-01-03T00:56:42.084-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Betting exchange'/><category scheme='http://www.blogger.com/atom/ns#' term='Probability'/><category scheme='http://www.blogger.com/atom/ns#' term='SCALA'/><category scheme='http://www.blogger.com/atom/ns#' term='Price'/><title type='text'>Time to change  - Moving from Java to Scala</title><content type='html'>&lt;div&gt;&lt;div style="text-align: justify;"&gt;The end of the year is a good time to look backwards and ask yourself a few questions. The question I'm asking myself every year is whether or not it's a good moment to change my core programming language. The last time I answered 'yes' was eight years ago. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;That time I was working for a software company where the lion's share of software code was written in C/C++ and nobody wanted to hear about Java. There were two major reasons for that, first of all, people generally were against any changes, secondly almost everyone used to think that Java is slow and not appropriate programming language for developing large scale and distributed computer systems. Finally choosing Java for developing next-gen company products was a bull's eye shot.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Now, eight years later, I feel again that it's a good moment to go forward. This time I'm moving from Java to Scala. In reference to scala-lang.org: &lt;blockquote&gt;Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages, enabling Java and other programmers to be more productive. Code sizes are typically reduced by a factor of two to three when compared to an equivalent Java application [1]&lt;/blockquote&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A good way to present the difference between two programming languages is to show the same code written in both of them. The code below presents following steps:&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;Create list of three decimal prices [2].&lt;/li&gt;&lt;li&gt;Convert prices to probabilities, probability = 1/price.&lt;/li&gt;&lt;li&gt;Print all probabilities to the console.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;b&gt;Scala code:&lt;/b&gt;&lt;/div&gt;&lt;pre class="brush: java"&gt;//Convert prices to probabilities&lt;br /&gt;//and display them to the console&lt;br /&gt;object PriceToProbability extends Application {&lt;br /&gt; val prices = List(2d,3d,4d)&lt;br /&gt; val probabilities = prices.map(s =&gt; 1/s)&lt;br /&gt; probabilities.foreach(println)&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;Java code:&lt;/span&gt;&lt;/div&gt;&lt;pre class="brush: java"&gt;//Convert prices to probabilities&lt;br /&gt;//and display them to the console&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.Arrays;&lt;br /&gt;import java.util.List;&lt;br /&gt;&lt;br /&gt;public class PriceToProbability {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;   List prices = Arrays.asList(2d,3d,4d);&lt;br /&gt;   List probabilities = new ArrayList();&lt;br /&gt;&lt;br /&gt;   for(Double price: prices) {&lt;br /&gt;     probabilities.add(1/price);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   for(Double probability: probabilities) {&lt;br /&gt;     System.out.println(probability);&lt;br /&gt;   }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Nice, isn't it? Although it's a very simple example, it illustrates how neat and concise Scala could be. Is a Scala for you? it depends on the business domain that you want to apply it for. My domain is mostly represented by risk management and algorithmic trading and many aspects of Scala fit there perfectly. For example functional programming is very useful for implementing various calculations and mathematical algorithms.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;For those, who want to learn more about Scala, I'd like to recommend very good book, actually one of the best books I read this year. Despite the fact it's a technical book I would compare it to reading Harry Potter. Simple language, easy to understand, short chapters and can't stop reading it. Here is the link: &lt;a href="http://www.artima.com/shop/programming_in_scala"&gt;Programming in Scala by Martin Odersky&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Reference&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;ol&gt;&lt;li&gt;&lt;a href="http://www.scala-lang.org/"&gt;Scala website.&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Fixed-odds_betting"&gt;Decimal odds (prices)&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-2525672796815181573?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/2525672796815181573/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2009/12/time-to-change-moving-from-java-to.html#comment-form' title='20 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/2525672796815181573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/2525672796815181573'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2009/12/time-to-change-moving-from-java-to.html' title='Time to change  - Moving from Java to Scala'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><thr:total>20</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-8908351592498512691</id><published>2009-12-04T11:51:00.000-08:00</published><updated>2009-12-20T12:24:27.833-08:00</updated><title type='text'>Bio heat map of the Barclays Premier League - Winner 2009/10</title><content type='html'>The picture below presents a bio heat map of a betting exchange market.&lt;br /&gt;&lt;br /&gt;Market: Barclays Premier League - Winner 2009/10 market.&lt;br /&gt;Time: 04 December 2009 19:51&lt;br /&gt;&lt;br /&gt;Function: tv = f(r,p,t)&lt;br /&gt;&lt;ul&gt;&lt;li&gt;tv - total traded volume on the given runner in a particular market&lt;/li&gt;&lt;li&gt;r - market runner&lt;br /&gt;&lt;/li&gt;&lt;li&gt;p - price&lt;/li&gt;&lt;li&gt;t - time&lt;/li&gt;&lt;/ul&gt;Color - green to black to red&lt;br /&gt;&lt;ul&gt;&lt;li&gt;green - 0 traded volume&lt;/li&gt;&lt;li&gt;black - middle between min and max&lt;/li&gt;&lt;li&gt;red - max traded volume&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_vHBR1L4_xvs/SxlpQTGjwZI/AAAAAAAAAGQ/ut4vSpFANWs/s1600-h/BarclaysPremierLeagueWinner2009_10.PNG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 369px; height: 400px;" src="http://4.bp.blogspot.com/_vHBR1L4_xvs/SxlpQTGjwZI/AAAAAAAAAGQ/ut4vSpFANWs/s400/BarclaysPremierLeagueWinner2009_10.PNG" alt="" id="BLOGGER_PHOTO_ID_5411472155988967826" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-8908351592498512691?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/8908351592498512691/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2009/12/bio-heat-map-of-barclays-premier-league.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/8908351592498512691'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/8908351592498512691'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2009/12/bio-heat-map-of-barclays-premier-league.html' title='Bio heat map of the Barclays Premier League - Winner 2009/10'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_vHBR1L4_xvs/SxlpQTGjwZI/AAAAAAAAAGQ/ut4vSpFANWs/s72-c/BarclaysPremierLeagueWinner2009_10.PNG' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-930268487729074119</id><published>2009-11-29T07:34:00.000-08:00</published><updated>2009-12-10T11:21:21.980-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='heat map'/><category scheme='http://www.blogger.com/atom/ns#' term='Betting exchange'/><category scheme='http://www.blogger.com/atom/ns#' term='BetFair'/><category scheme='http://www.blogger.com/atom/ns#' term='research'/><title type='text'>Bio heat map of a betting market</title><content type='html'>&lt;div style="text-align: justify;"&gt;It's a beginning of my research on a lifetime of a betting exchange market and my preliminary goal is to underatand how market grows and evolves during its lifetime.&lt;br /&gt;&lt;br /&gt;One of  my first thoughts was to present a market in a form suitable for analysis using a sense of sight and image recognition. In the first instance I decided to try a &lt;a href="http://en.wikipedia.org/wiki/Heat_map"&gt;bio heat map&lt;/a&gt;  that is commonly used in a science to present gene, weather or biological maps.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The picture below presents a bio heat map for a betting exchange market: tv = f(r,p,t)&lt;br /&gt;&lt;ul&gt;&lt;li&gt;tv - total traded volume on the given runner in a particular market&lt;/li&gt;&lt;li&gt;r - market runner&lt;br /&gt;&lt;/li&gt;&lt;li&gt;p - probability&lt;/li&gt;&lt;li&gt;t - time&lt;/li&gt;&lt;/ul&gt;Color - green to black to red&lt;br /&gt;&lt;ul&gt;&lt;li&gt;green - 0 traded volume&lt;/li&gt;&lt;li&gt;black - middle between min and max&lt;/li&gt;&lt;li&gt;red - max traded volume&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_vHBR1L4_xvs/SxK3v9h14vI/AAAAAAAAAFM/wbKk-k4rmiI/s1600/betting_market_sample_gene.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 150px; height: 288px;" src="http://1.bp.blogspot.com/_vHBR1L4_xvs/SxK3v9h14vI/AAAAAAAAAFM/wbKk-k4rmiI/s400/betting_market_sample_gene.jpg" alt="" id="BLOGGER_PHOTO_ID_5409588137023628018" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Having that, I'm going to record a lifetime of a market and replay it with an increased speed and make some initial analyses.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-930268487729074119?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/930268487729074119/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2009/11/bio-heat-map-of-betting-market.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/930268487729074119'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/930268487729074119'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2009/11/bio-heat-map-of-betting-market.html' title='Bio heat map of a betting market'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_vHBR1L4_xvs/SxK3v9h14vI/AAAAAAAAAFM/wbKk-k4rmiI/s72-c/betting_market_sample_gene.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-599055594848415401</id><published>2009-08-26T05:51:00.002-07:00</published><updated>2009-11-29T12:05:12.942-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='simulator'/><category scheme='http://www.blogger.com/atom/ns#' term='Betting exchange'/><category scheme='http://www.blogger.com/atom/ns#' term='BetFair'/><category scheme='http://www.blogger.com/atom/ns#' term='android'/><category scheme='http://www.blogger.com/atom/ns#' term='game'/><title type='text'>AndroBet - The Betting Exchange simulation game</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;a href="http://code.google.com/p/androbet/"&gt;&lt;/a&gt;Andro Bet is a betting exchange simulation game. The aim is to make the highest profit by backing and laying the same selection in the market. Game starts with the screen presenting market view for a single selection that player can place bets on. After 3 minutes of the game the runner outcome (winner or loser) is calculated and the profit&amp;amp;loss is displayed on the screen.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_vHBR1L4_xvs/SpUxOC_InrI/AAAAAAAAADo/BAXA7vk59J0/s1600-h/market_view.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 161px; height: 228px;" src="http://4.bp.blogspot.com/_vHBR1L4_xvs/SpUxOC_InrI/AAAAAAAAADo/BAXA7vk59J0/s400/market_view.png" alt="" id="BLOGGER_PHOTO_ID_5374255847726161586" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;On top of market view there is a status bar. On the left side of a status bar there is a profit for outcomes (winner and loser) that is based on all player's matched bets. On the right side of a status bar there is a remaining time of a game. In the centre of a market view there is a ladder price widget. The middle column contains all unmatched bets for all users on a betting exchange. Unmatched back bets are on the blue background, whereas unmatched lay bets are on the pink background. Each cell contains two numbers, on top of a cell there is a price, whereas on the bottom of a cell there is total value of unmatched bets for all users on this price. The left and right columns present all unmatched back and lay bets placed by a player. The player's unmatched back bets are in the left column, whereas the player's unmatched lay bets are in the right column. When the player’s bet is matched then it disappears from the cell.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Player may place back and lay bets, but once bet is placed, it can’t be cancelled.  Bets are placed by tapping the cells, in the left and right columns of a market view.  The size of one bet is 2, whereas the price is determined by the row tapped by a player. To place a back bet, tap the cell in the left column. To place a lay bet, tap the cell in the right column. The left and right columns display only player’s bets that remain unmatched.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_vHBR1L4_xvs/SpUxkxKwo8I/AAAAAAAAADw/NxtmXLz6R9Q/s1600-h/game_results.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 161px; height: 228px;" src="http://3.bp.blogspot.com/_vHBR1L4_xvs/SpUxkxKwo8I/AAAAAAAAADw/NxtmXLz6R9Q/s400/game_results.png" alt="" id="BLOGGER_PHOTO_ID_5374256238080074690" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;After game is finished the result is presented to a player. It contains starting price that is used to calculate selection’s outcome and the player’s profit.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Resources&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: left;"&gt;AndroBet on YouTube: &lt;a href="http://www.youtube.com/watch?v=dEDwtmKLIZc"&gt;http://www.youtube.com/watch?v=dEDwtmKLIZc&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;AndroBet on Google Code: &lt;a href="http://code.google.com/p/androbet/"&gt;http://code.google.com/p/androbet/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-599055594848415401?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/599055594848415401/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2009/08/androbet-betting-exchange-simulation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/599055594848415401'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/599055594848415401'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2009/08/androbet-betting-exchange-simulation.html' title='AndroBet - The Betting Exchange simulation game'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_vHBR1L4_xvs/SpUxOC_InrI/AAAAAAAAADo/BAXA7vk59J0/s72-c/market_view.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-7703648744017562178</id><published>2009-04-21T14:00:00.000-07:00</published><updated>2011-03-17T12:24:34.126-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Betting exchange'/><category scheme='http://www.blogger.com/atom/ns#' term='BetFair'/><category scheme='http://www.blogger.com/atom/ns#' term='Apache SCXML'/><title type='text'>Trading at BetFair betting exchange with Apache SCXML</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div style="text-align: justify;"&gt;The main concept of trading is to buy at low price and to sell at high price, e.g. to buy/sell shares at a stock exchange. Similar idea is behind a betting exchange, but instead of  shares issued by companies there are horse racing, tennis and football markets, instead of buying/selling shares, bets are placed. For example if two bets are placed on the same horse in a horse race, one bet at a lower price that the horse will lose and second bet at a higher price that the horse will win ,then whether or not a horse is a winner there is always a profit from these two bets.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;How to trade at BetFair trading exchange?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;At BetFair betting exchange (Figure 1) there are markets, e.g. tennis match or horse race. On each market there are runners, e.g. horses in a horse race. On runners the back/lay bets are placed. Back bet means that the runner will win, lay bet when it will lose. Bets are placed on a given price, which represents the chances of winning, e.g. price 2.0 is a 50% of chances (1/2=0.5), price 1.01 is a 99% of chances (1/1.01=0.99), 1000 is a 0.1% of chances (1/1000=0.001). For example when  a back bet is placed for 3$ at price of 2 and horse wins, then the profit is (3*2)-3 = 3$.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_TV098I9EDPs/SeohxbTXUQI/AAAAAAAAABM/mCX1F-jXr08/s1600-h/horse+market+panel" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5326106642345316610" src="http://1.bp.blogspot.com/_TV098I9EDPs/SeohxbTXUQI/AAAAAAAAABM/mCX1F-jXr08/s400/horse+market+panel" style="cursor: pointer; display: block; height: 247px; margin: 0px auto 10px; text-align: center; width: 400px;" /&gt;&lt;/a&gt;Figure 1. Horse racing market with runners and prices (source: betfair.com).&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;On the same time the price to lay (pink color) is always higher than the price to back (blue color), and placing two bets (back and lay) on the same time never  gives a profit. Example:&lt;br /&gt;&lt;br /&gt;Bets on a first runner (Shemoli):&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Back bet for 2$ at price 2.12&lt;/li&gt;&lt;li&gt;Lay bet for 2$ at price 2.14&lt;/li&gt;&lt;/ul&gt;When the runner is a winner then the profit/loss is: 2*(2.12-1) -2(2.14-1) =  2.24 - 2.28 = - 0.04&lt;br /&gt;When the runner is a looser then the profit/loss is: -2 + 2 = 0&lt;br /&gt;&lt;br /&gt;But firstly, when the back bet is placed, e.g, on a price 3.0 and some time later the lay bet is placed on a price 2.12 then the profit/loss is never negative. Example:&lt;br /&gt;&lt;br /&gt;Bets on a first runner (Shemoli):&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Back bet for 2$ at price 3.0&lt;/li&gt;&lt;li&gt;Lay bet for 2$ at price 2.14&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;When the runner is a winner then the profit/loss is: 2*(3-1) -2(2.14-1) =  4 - 2.28 = 1.72&lt;br /&gt;When the runner is a looser then the profit/loss is: -2 + 2 = 0&lt;br /&gt;&lt;br /&gt;The chart below (Figure 2) presents the price over the time for Shemoli runner. The key point of trading is to predict the trend of price. It allows to back on a high price and lay at a low price and to make a profit regardless of a market outcome.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_TV098I9EDPs/SeoiFbwth1I/AAAAAAAAABU/XryBNvAPuF0/s1600-h/LoadRunnerInfoChartAction.do.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5326106986065790802" src="http://3.bp.blogspot.com/_TV098I9EDPs/SeoiFbwth1I/AAAAAAAAABU/XryBNvAPuF0/s400/LoadRunnerInfoChartAction.do.jpg" style="cursor: pointer; display: block; height: 255px; margin: 0px auto 10px; text-align: center; width: 350px;" /&gt;&lt;/a&gt;Figure 2. Price chart for horse runner (source: betfair.com).&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;How I use Apache SCXML to trade at BetFair?&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;The simplest scenario of trading is to place two bets on the same runner, one back bet and one lay bet. It can be described by the following states and transitions between them (Figure 3):&lt;/div&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;No bets - When the runner price is increasing (price.slope&amp;gt;15), then a back bet is placed on it (placeBet betType='B' size=2 price=runner.priceToBack). The 'price.slope' parameter determines the angle of a price trend over last 15 minutes. When the angle is bigger than 0 then price is increasing, when is less than 0 then it is decreasing.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;Back matched - When the best available price to lay on the runner is lower than the price that the back bet was matched on, then a lay bet is placed. It assures the profit regardless of  a market outcome.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Lay matched - Back and lay bets are matched. Do not place any more bets on the runner.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_TV098I9EDPs/Se4hleUIznI/AAAAAAAAACk/JPOypfx0UMk/s1600-h/jessica1d.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5327232336902278770" src="http://2.bp.blogspot.com/_TV098I9EDPs/Se4hleUIznI/AAAAAAAAACk/JPOypfx0UMk/s400/jessica1d.jpg" style="cursor: pointer; display: block; height: 340px; margin: 0px auto 10px; text-align: center; width: 400px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: center;"&gt;Figure 3. Trading strategy (States machine) GUI editor.&lt;/div&gt;&lt;br /&gt;My betting application  allows to trade exactly in the same way as described above and usually it's a several minutes to prepare and execute new betting strategy:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Creata a state machine diagram using GUI editor.&lt;/li&gt;&lt;/ul&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;Export state machine to SCXML file (see Figure 4) - SCXML is an xml  format from W3C consortium, that describes a state machine. Because of a generic nature of SCXML, I extended it with many features, e.g. placeBet, cancelBet, variables used in conditions: runner.slope, runner.bwinPrice, runner.oddsCheckerPrice.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Import SCXML file to my betting application, where it's executed by betting engine based on Apache SCXML - Apache SCXML is a Java library  to parse and execute state machines in a SCXML format.&lt;/li&gt;&lt;/ul&gt;&lt;pre class="brush: xml"&gt;&lt;scxml initialstate="noBets" my="http://my.custom-actions/CUSTOM" version="1.0" xmlns="http://www.w3.org/2005/07/scxml"&gt;&lt;br /&gt;&lt;br /&gt;&lt;state id="noBets"&gt;&lt;br /&gt;&lt;transition cond="price.slope gt 15" target="backMatched"&gt;&lt;br /&gt;&lt;my:placebet bettype="B" price="runner.priceToBack" size="2"&gt;&lt;/my:placebet&gt;&lt;br /&gt;&lt;/transition&gt;&lt;br /&gt;&lt;/state&gt;&lt;br /&gt;&lt;br /&gt;&lt;state id="backMatched"&gt;&lt;br /&gt;&lt;transition cond="price.priceToLay lt lastBackBet.avgPriceMatched" target="layMatched"&gt;&lt;br /&gt;&lt;my:placebet bettype="L" price="runner.priceToLay" size="2"&gt;&lt;/my:placebet&gt;&lt;br /&gt;&lt;/transition&gt;&lt;br /&gt;&lt;/state&gt;&lt;br /&gt;&lt;br /&gt;&lt;state id="layMatched"&gt;&lt;/state&gt;&lt;br /&gt;&lt;br /&gt;&lt;/scxml&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div style="text-align: center;"&gt;Figure 4. State machine for trading strategy in a SCXML format.&lt;/div&gt;&lt;br /&gt;The presented example of state machine for betting strategy is very simple, however complex state machines can be created as well. The diagram below presents state machine for trading strategies on Soccer and Horse Racing markets.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_TV098I9EDPs/Se4UZMq_lsI/AAAAAAAAACc/p8ShMcHta_U/s1600-h/jessica2d.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5327217832356714178" src="http://4.bp.blogspot.com/_TV098I9EDPs/Se4UZMq_lsI/AAAAAAAAACc/p8ShMcHta_U/s400/jessica2d.jpg" style="cursor: pointer; display: block; height: 273px; margin: 0px auto 10px; text-align: center; width: 400px;" /&gt;&lt;/a&gt;Figure 4. State machine for trading strategies at Soccer and Horse Racing markets.&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;Adopting state machine to design and execute trading strategies is a powerful technique. First of all it's an easy and quick to design any kind of strategy and present it in a simple graphical  format. More over it doesn't require any special skills and can be performed by trading specialist, who doesn't know to much about computers or programming languages. Also describing trading strategy as a state machine allows to prepare very useful reports, e.g. what is the profit/loss per states over the time. Such report provides information that is essential to eliminate wrong states and evolve toward better design. In the end I'd like to mention that state machine can evolve itself, empowered by Business Intelligence and Machine Learning techniques.&lt;/div&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;Resources&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Betting_exchange"&gt;&lt;/a&gt;&lt;a href="http://code.google.com/p/scxml-betting-engine/"&gt;Scxml Betting Engine on Google Code&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;References&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Betting_exchange"&gt;Betting exchange&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Betfair"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_24"&gt;Betfair&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.eclipse.org/birt/phoenix/"&gt;&lt;/a&gt;&lt;a href="http://en.wikipedia.org/wiki/SCXML"&gt;SCXML&lt;/a&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_25"&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://commons.apache.org/scxml/"&gt;Apache SCXML&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Bye,&lt;br /&gt;Daniel&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-7703648744017562178?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/7703648744017562178/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2009/04/trading-at-betfair-betting-exchange.html#comment-form' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/7703648744017562178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/7703648744017562178'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2009/04/trading-at-betfair-betting-exchange.html' title='Trading at BetFair betting exchange with Apache SCXML'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_TV098I9EDPs/SeohxbTXUQI/AAAAAAAAABM/mCX1F-jXr08/s72-c/horse+market+panel' height='72' width='72'/><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-8123506123291290389</id><published>2009-03-14T14:05:00.000-07:00</published><updated>2011-03-17T12:24:18.484-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='BetFair'/><category scheme='http://www.blogger.com/atom/ns#' term='Eclipse BIRT'/><title type='text'>Automated betting with BetFair, Business Intelligence and Eclipse BIRT</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div style="text-align: justify;"&gt;When you place a single bet on a tennis match (market), you need to decide, which tennis player (runner) to bet on. Usually it’s based on your intelligence. By your intelligence I mean experience, knowledge, common sense, etc. When you use automated betting, then you place a lot of bets every day and the decision process becomes much more complicated. I this case you need something more than your intelligence, what you need is a Business Intelligence (BI).&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Regarding to Wikipedia, Business Intelligence (BI) refers to skills, technologies, applications and practices used to help a business acquire a better understanding of its commercial context. In my betting application I use Business Intelligence for:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Historical  data analysis – e.g. create reports/charts to show profit for sports/regions over the time.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Data mining – e.g. to recognize some particular situations when I win or lose.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Automated decision making system - based on evolutionary algorithms, e.g. eliminate wrong betting strategies during evolution process.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;In this post I describe how I analyse historical data using Eclipse Business Intelligence and Reports Tools (BIRT) technology. Eclipse BIRT is an open source Java project from IBM and it’s a powerful tool, especially to create custom multi dimensional reports and charts. It provides easy to use GUI designer to create and run reports. The GUI designer can be used as a stand alone application or a plugin in Eclipse IDE. Also a web based reports viewer is provided, which in my opinion isn’t very good. Finally there is a very well documented API, that allows to integrate BIRT charts and reports into a thirt-party applications.&lt;br /&gt;&lt;br /&gt;The examples below present BIRT chart and table report integrated into web console of my betting application.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_TV098I9EDPs/ScLROxP4kZI/AAAAAAAAAAU/ZWaZ5hTNpP0/s1600-h/profit_per_week.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5315040561918939538" src="http://4.bp.blogspot.com/_TV098I9EDPs/ScLROxP4kZI/AAAAAAAAAAU/ZWaZ5hTNpP0/s400/profit_per_week.png" style="cursor: pointer; display: block; height: 232px; margin: 0px auto 10px; text-align: center; width: 400px;" /&gt;&lt;/a&gt;Figure 1 Profit per week over the time.&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_TV098I9EDPs/ScPq5v5dUcI/AAAAAAAAAAk/PWe2nXWweZA/s1600-h/_1237576372064.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5315350263058223554" src="http://1.bp.blogspot.com/_TV098I9EDPs/ScPq5v5dUcI/AAAAAAAAAAk/PWe2nXWweZA/s400/_1237576372064.png" style="cursor: pointer; display: block; height: 400px; margin: 0px auto 10px; text-align: center; width: 375px;" /&gt;&lt;/a&gt;Figure 2 Profit per sport/region over the time.&lt;/div&gt;&lt;/div&gt;&lt;span style="font-size: 130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;How I use Eclipse BIRT?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;In my betting application BIRT reports and charts are integrated into  a web console, which is based on a Wicket framework. The figure 3 presents all components involved in designing, generating and presenting reports to the user.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_TV098I9EDPs/ScUoBlwtsFI/AAAAAAAAAA0/5qvXow2kBxc/s1600-h/BI.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5315698942962151506" src="http://3.bp.blogspot.com/_TV098I9EDPs/ScUoBlwtsFI/AAAAAAAAAA0/5qvXow2kBxc/s400/BI.png" style="cursor: pointer; display: block; height: 230px; margin: 0px auto 10px; text-align: center; width: 400px;" /&gt;&lt;/a&gt;Figure 3 Design of Birt reports.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;Diagram details:&lt;/div&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;ReportsViewer - Allows to choose report and values for report parameters and displays report to the user as html page. List of available reports is obtained  from reports directory on a file system.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Reports files - BIRT reports created by reports designer.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Reports Designer - GUI reports designer provided by Eclipse BIRT (see Figure 4). It's a powerful tool and allows to create almost all types of reports and charts you can ever think about. The best is that it can be used by a non technical person, e.g. business intelligence specialist. Also it is possible to parametrize reports, e.g. create report to show profit per sport/report with two input parameters: sport and region.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;BirtEngine - Generates report in a html/pdf format based on a report file and reports data from data source, e.g. from database.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Database - Repository of betting history, e.g. account statement, markets, bets, prices.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_TV098I9EDPs/ScUuaGeFllI/AAAAAAAAAA8/rr3r_N70eZk/s1600-h/birt+designer.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5315705961129023058" src="http://1.bp.blogspot.com/_TV098I9EDPs/ScUuaGeFllI/AAAAAAAAAA8/rr3r_N70eZk/s400/birt+designer.png" style="cursor: pointer; display: block; height: 233px; margin: 0px auto 10px; text-align: center; width: 400px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;Figure 4 BIRT Designer.&lt;/div&gt;&lt;br /&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size: 100%;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Business Intelligence is a crucial element of every automated betting application. Correctly used can significantly improve performance of betting. Moreover, it discovers new horizons and ways of betting hidden behind  a huge amount of historical data.&lt;/div&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;&lt;br /&gt;References&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Betting_exchange"&gt;Betting exchange&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Betfair"&gt;Betfair&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.eclipse.org/birt/phoenix/"&gt;Eclipse BIRT&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Bye,&lt;br /&gt;Daniel&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-8123506123291290389?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/8123506123291290389/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2009/03/automated-betting-with-betfair-business.html#comment-form' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/8123506123291290389'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/8123506123291290389'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2009/03/automated-betting-with-betfair-business.html' title='Automated betting with BetFair, Business Intelligence and Eclipse BIRT'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_TV098I9EDPs/ScLROxP4kZI/AAAAAAAAAAU/ZWaZ5hTNpP0/s72-c/profit_per_week.png' height='72' width='72'/><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7538904595934077017.post-2337685762899475828</id><published>2009-02-26T14:33:00.000-08:00</published><updated>2011-03-17T12:23:53.633-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Betfair API'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='CXF'/><category scheme='http://www.blogger.com/atom/ns#' term='Maven'/><category scheme='http://www.blogger.com/atom/ns#' term='Spring'/><title type='text'>BetFair Java API with Apache CXF, Spring and Maven</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In this post I present how to login and place a bet on BetFair in Java. Betfair provides a webservice API to get events, markets, place a bet and do many other things. There are several ways to use this API in Java but personally I prefer one of the easiest and quickest of them, which is based on Apache CXF technology.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Apache CXF is a professional open-source Java library to create webservice clients and servers. It generates a webservice java client automatically from a wsdl file, that works very well with BetFair API. Thus calling most of a BetFair operations such a login, getEvents, placeBet is very simple and is just a couple of lines.&lt;/div&gt;&lt;br /&gt;The diagram below presents how BetfairService is designed and used in my betting application:&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;a href="http://2.bp.blogspot.com/_vHBR1L4_xvs/Sxvxf6bZa2I/AAAAAAAAAGY/quygnNV8-y0/s1600-h/BettingService.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5412184907778190178" src="http://2.bp.blogspot.com/_vHBR1L4_xvs/Sxvxf6bZa2I/AAAAAAAAAGY/quygnNV8-y0/s400/BettingService.png" style="cursor: pointer; display: block; height: 208px; margin: 0px auto 10px; text-align: center; width: 400px;" /&gt;&lt;/a&gt;Diagram details:&lt;br /&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;BFGlobalService/BFExchangeService - Betfair webservices generated by Apache CXF. GlobalService contains login operation and others, which don't require logging in. Whereas ExchangeService allows to get market data, place bets, get account information and others, which require user to be logged in.&lt;/li&gt;&lt;/ul&gt;&lt;ul style="text-align: left;"&gt;&lt;li style="text-align: left;"&gt;BettingServiceImpl - BetFair Facade, that simplifies access to the BetFair operations from a BettingEngine.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul style="text-align: left;"&gt;&lt;li style="text-align: left;"&gt;BettingEngine - Module of my application responsible for executing betting strategies.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;How to login to a Betfair account?&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;The login operation is provided by a BFGlobalService. To login to a Betfair account three parameters are required: user, password and productId. For Betfair free API the productId is 82.&lt;/div&gt;&lt;pre class="brush: java"&gt;//Login to a BetFair account.&lt;br /&gt;//&lt;br /&gt;public void login(String userName, String password, int productId) {&lt;br /&gt;&lt;br /&gt;//Creating login command which contains all login parameters.&lt;br /&gt;LoginReq req = new LoginReq();&lt;br /&gt;req.setUsername(userName);&lt;br /&gt;req.setPassword(password);&lt;br /&gt;req.setProductId(productId);&lt;br /&gt;req.setLocationId(0);&lt;br /&gt;req.setVendorSoftwareId(0);&lt;br /&gt;&lt;br /&gt;//Calling BetFair webservice login operaton.&lt;br /&gt;LoginResp resp = globalWebService.login(req);&lt;br /&gt;&lt;br /&gt;//Checking login result and storing session token, which is necessary to call BFExchangeService operations, e.g. getMarkets, placeBet.&lt;br /&gt;if (resp.getErrorCode().equals(LoginErrorEnum.OK))&lt;br /&gt;{&lt;br /&gt;state.setSessionToken(resp.getHeader(). getSessionToken());&lt;br /&gt;} else {&lt;br /&gt;throw new BetFairException("Login error. Error code: " + resp.getErrorCode() + ", api code: "&lt;br /&gt;+ resp.getHeader().getErrorCode());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;span style="font-size: 130%;"&gt;How to place a bet?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;The placeBet operation is provided by a BFExchangeService. There are many different bet types available. This example show how to place a back/lay bet on a betting exchange. The code snippet below presents a placeBet method with parameters:&lt;/div&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;marketId/selectionId - Which market runner the bet is placed on, e.g. draw in a football match, tennis player in a tennis match or horse in a horse race.&lt;/li&gt;&lt;/ul&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;betType - Back or lay , e.g. back bet means that something will happen, e.g. draw in a football match, lay means that it will not happen, e.g. tennis player will not win the match.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;betCategory - Exchange or SP(starting price) bet.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;price - Binary odds of a bet, e.g. 2.0&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;size - Stake of a bet, e.g. 20 dollars.&lt;/li&gt;&lt;/ul&gt;&lt;pre class="brush: java"&gt;//Place a bet on a BetFair&lt;br /&gt;//betting exchange.&lt;br /&gt;public void placeBet(int marketId, int selectionId, BetTypeEnum betType, BetCategoryTypeEnum betCategory,&lt;br /&gt;double price, double size) {&lt;br /&gt;&lt;br /&gt;//Creating request header with a session token returned by login operation.&lt;br /&gt;APIRequestHeader requestHeader = new APIRequestHeader();&lt;br /&gt;requestHeader.setSessionToken(sessionToken);&lt;br /&gt;&lt;br /&gt;//Creating placeBet command, which contains all required parameters.&lt;br /&gt;PlaceBetsReq req = new PlaceBetsReq();&lt;br /&gt;req.setHeader(requestHeader);&lt;br /&gt;&lt;br /&gt;ArrayOfPlaceBets arrayOfBets = new ArrayOfPlaceBets();&lt;br /&gt;PlaceBets placeBets = new PlaceBets();&lt;br /&gt;placeBets.setAsianLineId(0);&lt;br /&gt;placeBets.setBetCategoryType(betCategory);&lt;br /&gt;placeBets.setPrice(price);&lt;br /&gt;placeBets.setSize(size);&lt;br /&gt;placeBets.setBspLiability(0d);&lt;br /&gt;placeBets.setBetPersistenceType( BetPersistenceTypeEnum.NONE);&lt;br /&gt;placeBets.setBetType(betType);&lt;br /&gt;placeBets.setMarketId(marketId);&lt;br /&gt;placeBets.setSelectionId(selectionId);&lt;br /&gt;arrayOfBets.getPlaceBets().add(placeBets);&lt;br /&gt;req.setBets(arrayOfBets);&lt;br /&gt;&lt;br /&gt;//Calling placeBet operation on a BetFair webservice.&lt;br /&gt;PlaceBetsResp resp = exchangeWebService.placeBets(req);&lt;br /&gt;if (resp.getErrorCode().equals(...) {&lt;br /&gt;//Checking placing bet result.&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-size: 130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;How to generate &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size: 130%;"&gt;BFGlobal and BFExchange services with Maven and cxf-codegen-plugin?&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Because my betting tool uses a Maven build system, I use a cxf-codegen-plugin to generate java classes for BetFair webservices. There are two plugin executions to generate java classes for BFGlobal and BFExchange services. Java classes are generated from the wsdl files. See lines 17 and 37.&lt;/div&gt;&lt;br /&gt;&lt;pre class="brush: xml"&gt;&lt;plugin&gt;&lt;br /&gt;&lt;groupid&gt;org.apache.cxf&lt;/groupid&gt;&lt;br /&gt;&lt;artifactid&gt;cxf-codegen-plugin&lt;/artifactid&gt;&lt;br /&gt;&lt;version&gt;2.0.5-incubator&lt;/version&gt;&lt;br /&gt;&lt;executions&gt;&lt;br /&gt;&lt;br /&gt;&lt;execution&gt;&lt;br /&gt;&lt;id&gt;generate-sources_BFGlobalService&lt;/id&gt;&lt;br /&gt;&lt;phase&gt;generate-sources&lt;/phase&gt;&lt;br /&gt;&lt;configuration&gt;&lt;br /&gt;&lt;sourceroot&gt;&lt;br /&gt;${basedir}/target/generated-sources/src/main/ java&lt;br /&gt;&lt;/sourceroot&gt;&lt;br /&gt;&lt;wsdloptions&gt;&lt;br /&gt;&lt;wsdloption&gt;&lt;br /&gt;&lt;wsdl&gt;&lt;br /&gt;${basedir}/src/main/wsdl/ BFGlobalService.wsdl&lt;br /&gt;&lt;/wsdl&gt;&lt;br /&gt;&lt;/wsdloption&gt;&lt;br /&gt;&lt;/wsdloptions&gt;&lt;br /&gt;&lt;/configuration&gt;&lt;br /&gt;&lt;goals&gt;&lt;br /&gt;&lt;goal&gt;wsdl2java&lt;/goal&gt;&lt;br /&gt;&lt;/goals&gt;&lt;br /&gt;&lt;/execution&gt;&lt;br /&gt;&lt;br /&gt;&lt;execution&gt;&lt;br /&gt;&lt;id&gt;generate-sources_BFExchangeService&lt;/id&gt;&lt;br /&gt;&lt;phase&gt;generate-sources&lt;/phase&gt;&lt;br /&gt;&lt;configuration&gt;&lt;br /&gt;&lt;sourceroot&gt;&lt;br /&gt;${basedir}/target/generated-sources/src/main/ java&lt;br /&gt;&lt;/sourceroot&gt;&lt;br /&gt;&lt;wsdloptions&gt;&lt;br /&gt;&lt;wsdloption&gt;&lt;br /&gt;&lt;wsdl&gt;&lt;br /&gt;${basedir}/src/main/wsdl/ BFExchangeService.wsdl&lt;br /&gt;&lt;/wsdl&gt;&lt;br /&gt;&lt;/wsdloption&gt;&lt;br /&gt;&lt;/wsdloptions&gt;&lt;br /&gt;&lt;/configuration&gt;&lt;br /&gt;&lt;goals&gt;&lt;br /&gt;&lt;goal&gt;wsdl2java&lt;/goal&gt;&lt;br /&gt;&lt;/goals&gt;&lt;br /&gt;&lt;/execution&gt;&lt;br /&gt;&lt;/executions&gt;&lt;br /&gt;&lt;/plugin&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;How to configure &lt;/span&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;BFGlobal and BFExchange services with Spring?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-size: 100%;"&gt;The BFGlobal and BFExchange services are created by a JaxWsProxyFactory bean, which is configured using the class name of generated webservice and the url of a BetFair webservice. Afterwards BetFair services are injected into a BetFair facade, which is used by my betting application.&lt;/span&gt;&lt;span class="content"&gt;&lt;span class="block" style="margin-left: 0px;"&gt;&lt;code class="string"&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="content"&gt;&lt;span class="block" style="margin-left: 0px;"&gt;&lt;code class="string"&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre class="brush: xml"&gt;&lt;beans&gt;&lt;br /&gt;&lt;br /&gt;&lt;bean class="jm.flexibet.betfairservice. BetFairServiceImpl" id="betFairService"&gt;&lt;br /&gt;&lt;property name="exchangeWebService" ref="exchangeWebService"&gt;&lt;/property&gt;&lt;br /&gt;&lt;property name="globalWebService" ref="globalWebService"&gt; &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;bean class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean" id="proxyFactoryGlobalWebService"&gt;&lt;br /&gt;&lt;property name="serviceClass" value="com.betfair.publicapi.v3.bfglobalservice. BFGlobalService"&gt; &lt;/property&gt;&lt;br /&gt;&lt;property name="address" value="https://api.betfair.com/global/v3/ BFGlobalService"&gt; &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;bean bean="proxyFactoryGlobalWebService" class="com.betfair.publicapi.v3.bfglobalservice. BFGlobalService" id="globalWebService" method="create"&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;bean class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean" id="proxyFactoryExchangeWebService"&gt;&lt;br /&gt;&lt;property name="serviceClass" value="com.betfair.publicapi.v5.bfexchangeservice. BFExchangeService"&gt; &lt;/property&gt;&lt;br /&gt;&lt;property name="address" value="https://api.betfair.com/exchange/v5/ BFExchangeService"&gt; &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;bean bean="proxyFactoryExchangeWebService" class="com.betfair.publicapi.v5.bfexchangeservice. BFExchangeService" id="exchangeWebService" method="create"&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;&lt;/beans&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;Resources&lt;span style="font-size: 100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://code.google.com/p/betfair-api/"&gt;Betfair JAVA API on Google Code&lt;/a&gt;&lt;span style="font-size: 130%;"&gt;&lt;span style="font-size: 100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-size: 130%; font-weight: bold;"&gt;References&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Betting_exchange"&gt;Betting exchange&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Betfair"&gt;Betfair&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://bdp.betfair.com/"&gt;Betfair API&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Apache_CXF"&gt;Apache CXF&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Spring_Framework"&gt;Spring Framework&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Apache_Maven"&gt;Apache Maven&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;Bye,&lt;br /&gt;Daniel&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7538904595934077017-2337685762899475828?l=blog.danmachine.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.danmachine.com/feeds/2337685762899475828/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://blog.danmachine.com/2009/02/betfair-java-api-with-apache-cxf-spring.html#comment-form' title='19 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/2337685762899475828'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7538904595934077017/posts/default/2337685762899475828'/><link rel='alternate' type='text/html' href='http://blog.danmachine.com/2009/02/betfair-java-api-with-apache-cxf-spring.html' title='BetFair Java API with Apache CXF, Spring and Maven'/><author><name>Daniel Korzekwa</name><uri>https://profiles.google.com/108837894186457186045</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-XTGri0D-Am0/AAAAAAAAAAI/AAAAAAAAIBs/CzkXu-Okvx0/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_vHBR1L4_xvs/Sxvxf6bZa2I/AAAAAAAAAGY/quygnNV8-y0/s72-c/BettingService.png' height='72' width='72'/><thr:total>19</thr:total></entry></feed>
