FiQuant Market Simulator

  • 221 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
221
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Market Microstructure Simulator: developer’s point ofviewAnton KolotaevChair of Quantitative Finance, ´Ecole Centrale Parisanton.kolotaev@gmail.comJune 10, 2013Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 1 / 38
  • 2. Overview1 Introduction2 Simulator componentsSchedulerOrder booksOrdersTradersStrategiesObservables3 Using Veusz4 Web interface5 Exposing Python classes to Web-interface6 Future developmentsAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 2 / 38
  • 3. Evolution of the simulator1 Initial C++ version was developed in 2009-2011.2 C++ version based on template metaprogramming techniques wassuggested in 20123 Python version with Web interface is almost finished by June 20134 Optimized C++ version based on automatic code generation is to bedeveloped by September 2013Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 3 / 38
  • 4. InstallationOS supported: Linux, Mac OS X, WindowsBrowsers supported: Chrome, Firefox, Safari, OperaPython 2.7Python packages can be installed using pip or easyinstall:Veusz (for graph plotting)Flask (to run a Web-server)Blist (sorted collections used by ArbitrageTrader)Source code downloadable from SourceForgeAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 4 / 38
  • 5. Simulator componentsAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 5 / 38
  • 6. SchedulerMain class for every discrete event simulation system.Maintains a set of actions to fulfill in future and launches themaccording their action times: from older ones to newer.Interface:Event scheduling:schedule(actionTime, handler)scheduleAfter(dt, handler)Simulation control:workTill(limitTime)advance(dt)reset()Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 6 / 38
  • 7. Order bookRepresents a single asset traded in some market (Same asset tradedin different markets would be represented by different order books)Matches incoming ordersStores unfulfilled limit orders in two order queues (Asks for sell ordersand Bids for buy orders)Corrects limit order price with respect to tick sizeImposes order processing feeSupports queries about order book structureNotifies listeners about trades and price changesAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 7 / 38
  • 8. Order book for a remote traderModels a trader connected to a market by a communication channelwith non-negligible latencyIntroduces delay in information propagation from a trader to an orderbook and vice versa (so a trader has outdated information aboutmarket and orders are sent to the market with a certain delay)Assures correct order of messages: older messages always come earlierthan newer onesAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 8 / 38
  • 9. Basic ordersOrders supported internally by an order book:Market(side, volume)Limit(side, price, volume)Cancel(limitOrder)Limit and market orders notifies their listeners about all trades they takepart in. Factory functions are usually used in order to create orders.Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 9 / 38
  • 10. Meta ordersFollow order interface from trader’s perspective (so they can be usedinstead of basic orders) but behave like a sequence of base orders from anorder book point of view.Iceberg(volumeLimit, orderToSplit) splits orderToSplit topieces with volume less than volumeLimit and sends them one byone to an order book ensuring that only one order at time isprocessed thereAlwaysBest(volume, limitOrderFactory) creates a limit-likeorder with given volume and the most attractive price, sends it to anorder book and if the order book best price changes, cancels it andresends with a better priceWithExpiry(lifetime, limitOrderFactory) sends a limit-likeorder and after lifetime cancels itLimitMarket(limitOrderFactory) is like WithExpiry but withlifetime equal to 0Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 10 / 38
  • 11. TradersSingle asset traderssend orders to order booksbookkeep their position and balancerun a number of trading strategiesnotify listeners about trades done and orders sentSingle asset traders operate on a single or multiple markets. Multiple assettraders are about to be added.Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 11 / 38
  • 12. Generic strategyGeneric strategy that wakes up on events given by eventGen, chooses sideof order to create using sideFunc and its volume by volumeFunc, createsan order via orderFactory and sends the order to the market using itstraderAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 12 / 38
  • 13. Signal strategySignal strategy listens to some discrete signal and when the signalbecomes more than some threshold it starts to buy. When the signal getslower than -threshold the strategy starts to sell.Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 13 / 38
  • 14. Trend follower strategyTrend follower is an instance of a signal strategy with signal equal to thefirst derivative of a moving average of the asset’s price (i.e trend).Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 14 / 38
  • 15. Two averages strategyTwo averages is an instance of a signal strategy with signal equal to thedifference between two moving averages of the asset’s price (i.e trend).Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 15 / 38
  • 16. Fundamental value strategyFundamental value strategy is an instance of a signal strategy with signalequal to the difference between the asset’s price and some fundamentalvalue.Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 16 / 38
  • 17. Mean reversion strategyMean reversion strategy is an instance of a fundamental value strategywith fundamental value equal to some moving average of the asset’s price.Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 17 / 38
  • 18. Dependency strategyDependency strategy is an instance of a fundamental value strategy withfundamental value equal to another asset’s price multiplied by given factor.Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 18 / 38
  • 19. Liquidity providerLiquidity provider sends limit-like orders with a price equal to the currentasset’s price multiplied by some randomly chosen factorAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 19 / 38
  • 20. Trade-if-profitable strategySuspends or resumes an underlying strategy basing on its performancebacktesting. By default, first derivative of a moving average of ’cleared’trader’s balance (trader’s balance if its position was cleared) is used toevaluate the efficiency.Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 20 / 38
  • 21. Choose-the-best strategyBacktests aggregated strategies and allows to run only to that one whohas the best performance. By default, first derivative of a moving averageof ’cleared’ trader’s balance is used to evaluate the efficiency.Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 21 / 38
  • 22. ObservableTraders and order books provide basic accessors to their current state butdon’t collect any statistics. In order to do it in an interoperable way anotion of observable value was introduced: it allows to read its currentvalue and notifies listeners about its change.Primitive observables ontraders: position, balance, market value of the portfolio, ’cleared’balance etc.order books: ask/mid/bid price, last trade price, price at volume,volume of orders with price better than given one etc.OnEveryDt(dt, dataSource) evaluates dataSource every dtmoments of time. Often used with Fold(observable,accumulator) where accumulator may be a moving average oranother statistics collector.History of an observable can be stored in a TimeSerie and rendered lateron a graph.Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 22 / 38
  • 23. Using VeuszWhen developing a new strategy it is reasonable to test it using scriptsand visualize results by VeuszAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 23 / 38
  • 24. Rendering graphs by VeuszAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 24 / 38
  • 25. Web interfaceWeb interface allows to compose a market to simulate from existingobjects and set up their parametersAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 25 / 38
  • 26. Time seriesTimeseries field of a trader or an order book instructs what data should becollected and rendered on graphsAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 26 / 38
  • 27. Rendering resultsAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 27 / 38
  • 28. Node aliasesObject tree nodes can be assigned aliases that can be used later to refer tothe sub-tree (explicit by-value or by-reference cloning semantics is to beimplemented)Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 28 / 38
  • 29. WorkspacesEvery user (identified by browser cookies) may switch between multipleworkspaces. Workspaces can be forked, removed or created from a set ofpredefined ones.Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 29 / 38
  • 30. Exposing Python classes to Web-interfacedisplayable label for the class (’Random Walk’)docstring in rst formatproperty names and static constraints on types of their valuesAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 30 / 38
  • 31. Type systemPrimitive types: int, float, stringNumeric constraints: less than(2*math.pi, non negative)User-defined classes. If a property constraint is type B then any objectof type D can be used as its value provided that D derives from B.Array types: meta.listOf(types.IStrategy)Functional types: meta.function((Side, Price, Volume),IOrder)Possible improvements:meta.function((a1, ..., aN), rettype) could be used wheremeta.function((a1, ..., aN, b1, ..., bM), rettype) isexpectedmeta.function((..., B, ...), rettype) could be used wheremeta.function((..., D, ...), rettype) is expected if D caststo Bmeta.function(args, D) could be used wheremeta.function(args, B) is expected if D casts to BAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 31 / 38
  • 32. Future developmentsC++ version:1 Implement core functionality (scheduler, order books, basic orders andtraders) in C++ (already done) and provide extension points to allowto a user create strategies and meta orders in Python (or use existingones)2 Given object tree describing a simulation model, generate on the flyC++ code as instantiations of template classes corresponding toclasses in Python versionAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 32 / 38
  • 33. C++ versionFlexible as Python version and has performance comparable to a Chand-written version. The main problem: simulation configuring is notintuitive, so let’s do the configuration automatically by a code generator.Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 33 / 38
  • 34. Python version/Web interfaceAutomatic dependency tracking in Python code(observables/computed observables from KnockoutJs)Notion of variables in the Web interface to label common objectgraph subtreesModel graph representation in Web interface (???)Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 34 / 38
  • 35. Model graph representation in Web interfaceAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 35 / 38
  • 36. Simulation components (by Karol Podkanski)StrategiesRelative strength index (RSI). Buy/sell when stock isoversold/overbought according to the indexStop-loss strategy. Applied to any strategy in order to limit losses ifthey reach a certain thresholdMulti-armed bandit. Evaluate an array of strategies and assign themscores based on their efficiency. A strategy is then chosen randomly,with a distribution based on the scores.Other meta-strategies (???)Pairs trading. A dependence between two assets is assumed (forexample, correlation). A trade is initiated when a function of the twoassets (for example: weighted average) deviates from it’s mean value.Volume managementEnter/exit time management (currently random or constant)Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 36 / 38
  • 37. Simulation components (by Karol Podkanski)Observables (Indicators):VolatilityVolumePerformanceRelative strength indexTechnical analysisTrendline: support and resistanceNew High/LowChannelsDouble Top/BottomHead and ShouldersAdd position constraints to traders:traders have to allocate their limited resourcescertain assets cannot be shortedAnton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 37 / 38
  • 38. Thank you!Anton Kolotaev (ECP) FiQuant Market Simulator June 10, 2013 38 / 38