algorithmic trading in foreign exchange based on order...

20
Algorithmic Trading in Foreign Exchange Based on Order Flow Mat‐2.4108 Independent Research Projects in Applied Mathematics 6 th February 2009 Helsinki University of Technology Department of Engineering Physics and Mathematics Tuomas Nummelin 62832W

Upload: others

Post on 21-Jan-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

AlgorithmicTradinginForeignExchangeBasedonOrderFlow

Mat‐2.4108IndependentResearchProjectsinAppliedMathematics

6thFebruary2009

HelsinkiUniversityofTechnology

DepartmentofEngineeringPhysicsandMathematics

TuomasNummelin

62832W

Page 2: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

2

1. ExecutiveSummaryThegoalofthisstudywastoconstructasimplifiedsimulationmodelforforeignexchangeandtotesttheperformanceoftradingalgorithms.Someofthetestedalgorithmsusetheinformationfromorderflowandthegoalwastoseewhethersignificant insight is gained from this it. After rigorous analysis it could bedeemed that the utilisation of order flow information does benefit thealgorithms. However, the results depend on how the information is used.Differences in performance are evident. The performances of algorithms varyfromamediocreandstableperformancelackingtheexceptionalhighprofits,toaperformance alteringmuch from the top profits to the largest loses. It is alsonoteworthythatthedifferentalgorithmsperformedwell,withbothasimulationdata setandwitha realdailydata set.This informationencouragesus to seekbetterwaystoutilizetheorderflowdata.

2.MotivationandBackgroundforResearch Thefocusofthisstudyisonautomatedtradinginforeignexchange(forex,FX).Focusingonamicrostructure‐basedorder flowwehopetoenhanceautomatedtrading inFXmarkets. Inordertoadapt themicrostructureviewtoautomatedtrading, we first look at the FX market and the FX spot rate determinationmodels, examiningmicrostructure basedmodels, and determinewhether theycanbeusedinautomatedtradingornot.Thisisthefirstpartofthisstudywhilethequantitativeanalysisofthechosenmodelimplementationisthesecondone.

Theforeignexchangemarketisacashinter‐bankorinter‐dealermarket,whichisthebiggestandmostliquidmarketintheworld.Theaveragedailyturnoverintraditional FXmarkets has grown by 69% since April 2004, to $3.2 trillion inApril2007(BIS,TriennalCentralBankSurvey2007).HowevertherecentcrisisinfinancialmarketshasaneffectinFXmarketaswell,butitisstilltooearlytosay what are the lasting consequences for market. Although the potentialmarkets and technical improvements in information and communicationtechnologies (ICT) the FX markets have turned in to actual 24/7 real timeelectronicmarketsusingelectronictradingsystemstobeveryattractivemarket.Theuseofautomatedtradingsystemshasincreased(www.wikipedia.com)anditisestimatedthataround25%automatedtradingin2008doesalltradeinFXmarkets.

Page 3: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

3

3. ForeignExchangeMarket:BriefOverviewAboutModels&MarketTraditionally,themodelsforFXspotratehavebeenextensivelybasedonmacroexchange models, which pay little attention to how actual trading in the FXmarketiscarriedout,eventhoughmacroeconomicmodelsdotakeintoaccountsuch factors as GDP, monetary politics, etc. These models have been used tomodelmediumtolongterm(afewmonthstoyears)developmentsinFXrates.However, these models have little or no prediction power in the short term(MeeseandRogoff1983,1997).Theimplicitassumptionincorporatedinmacromodelsisthatthedetailsoftrading(i.e.whoquotescurrencypricesandhowthetrade takesplace)areunimportant toexchange rate changesovermonthsandquartersorlonger.Incontrast,micromodelsexaminehowinformationrelevanttothespotpriceofthecurrencyisreflectedinthespotexchangerateviatradingprocess. Based on this microstructure, the trading process is not an ancillarymarketactivitythatcanbeignoredwhenconsideringexchangeratebehaviour.Instead, the tradingprocess canbe seen as a crucial factor in theprocess thatdeterminestheFXspotrate.

TheFXmarketconsistsoftwosegments;theinterbankmarketandthecustomermarket.Theadvancementsintradingtechnologyhavereshapedthestructureofthe FX market; the electronic brokers in interbank markets and the internettrading for customers have been themain driving factors of the restructuring(Rime).Intheinterbankmarket,tradingiseitherdirect(bilateralortakingplacebetween dealers) or brokered (interdealer trades). Prior to the Internetrevolution,customerstradedwiththebank.However,nowadayscustomershavethepossibilitytotradethroughelectronicbrokeringsystemswhichhavebecomethedefactosystemsoftoday. Therefore,weshouldconsidercustomersastheultimate end‐users of currency. Customers can be broadly defined as beingcentral banks, governments, importers and exporters of goods, financialinstitutions,likehedgefunds,andprivateindividuals.ThemarketiscentralisedunlikebeforetheICTimprovementswhentheFXmarketwasdecentralisedcallmarket. The fundamental nature of currency trading (i.e. due different timezones there exists a continuous need to recognize the value of differentcurrencies)ledtothedecentralisedandcontinuousmarket.

4. MicrostructureModelsMarketmicrostructureisapartoffinanceconcerningindetailshowthetradingofassetsoccursinthemarkets.Themainfocusofmicrostructuremodelsishowthe tradingprocess affects assetprices, quotes, transaction costs, volumes andtradingbehaviour.Theearliestmicrostructuremodelsfocusedonmacroaspectofthemarketsandconsideredlongtermeconomicalscaleissuesinthemarkets.Howeveruntil the1980‐90’s themicrostructuremodelshavenotbeenseenasveryprominentinshort‐termexchangerateprediction.Onerelevantfactisthatthe ICT technology has made it possible to record detailed data abouttransactions in themarkets and give researchers theneeded empirical data todevelop models. However, it is still today one drawback of microstructuremodelsthattheyneedtohavesufficientdatatovalidation.Thedevelopmentinmicrostructuremodelshasbeenfastandprofitable.

Page 4: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

4

AmajordevelopmentinmicrostructuremodelinginFXwasachievedin1999,when Evans and Lyons (Evans and Lyons, 1999) presented their paper aboutorderflowandexchangeratedynamics.Theyintroducedasimplemodel,whichcaptured the high R2 statistics in daily DM/USD and YEN/USD spot ratedynamics. The overall fit of themodel is striking, compared to the traditionalmacro models, with R2 statistics of 64% and 45% for the DM and YENrespectively. It is remarkable that themodel captures the essentials from themacropointofviewaswellasthemicropointofview.Themodelconsidersthatallmacroinformation(i.e.interestrate)isconsideredpublicinformation.Privateornon‐public information(i.e.orderflow)isbasedmainlyonmicroindicators.Theinformationprocessoraggregationoftheprivateinformationisembeddedintheorderflowwhichisthesourceofinformationdiffusioninthemodel.Eventhoughthemodelisbetterthantraditionalmacroeconomicmodels,itstillisfarfrom perfect. To some extent, models with roughly 50% R2‐statistics can beregardedasgoodmodelsinthefieldofFX.

The rationale behind order flow was analysed more closely and developedfurther by Evans and Lyons in 2004 (Evans and Lyons, 2004). This time theytook a different approach to exchange rate predictions; they focused oninformation sets and thediffusionof these sets in themarkets. Theirmodel isbasedonrationalexpectations(rationalexpectationsandportfolioshiftmodelscanbeseenastwoofthemostusedmodelideasinmicrostructure).Thesumofpresentvaluesofthemeasuredmacroeconomicfundamentalsandfundamentalswhicharenotexplainedwithmacroeconomic fundamentals, i.e.microstructuremeasures,formarelationforthepredictionofexchangerate.Thekeyempiricalfindings of their paper include transaction flows, forecasts of future macrovariables,suchasoutputgrowth,moneygrowth,andinflation.Transactionflowsgenerally forecast thesemacrovariablesbetter thanspotratesdo.Transactionflowsforecastfuturespotrates,andthoughflowsconveynewinformationaboutfuture fundamentals,much of this information is still not captured in the spotratesonequarterlater.Thesefindingsindicatethatorderflowhasasignificantroleinexchangeratepredictionthroughseveraldifferentchannels.

A different point of view to market dynamics comes from Bacchetta and VanWincoop (2004). Their model is based on heterogeneous information ofstandard dynamic monetary model for exchange rate determination. Theirfindings support the idea that heterogeneous information and different riskattitude through market makers disconnect changes in exchange rate frommacro fundamentals in the short run and the value of the order flow as thedistributorofprivateinformation.

Danielson and Payne (2002) analyse the forecasting power of order flow indifferenttimehorizonsandfoundthattheorderflowhassignificantmeaninginexchange rate forecasting. They examine different currency pairs and cross‐referencetheirfindingswithothercurrencypairscloselyrelatedtotheoriginalpairs’orderflows.

EvansandLyons(2005)takeamoredetailed lookatorder flowsandseparateorder flows in different segments and find that order flows based on

Page 5: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

5

heterogeneouscustomerscarrymoreinformationaboutthefuturevaluesofthefundamentalswhencustomersfocusedonlong‐terminvestments.

The central banks have also been keen to understand the FX marketmicrostructurefromtheregulatorypointofviewandalsoinextremesituations,where interventions are needed, to understand the possible impacts (Vitale P,2006).TheresearchareaofthemicrostructureandorderflowbasedmodelsinFXisapromisingresearchfieldinthenearfuture.Itcanbenotedthatthepointof view has expanded slightly towards the HiddenMarkov Processes that areseen as a new, very prominent, but loosely microstructure based method topredictexchangerates.

5. AutomatedTradingwithInformationfromMicrostructureModelsIn this section we consider, which improvements are possible in automatedtradingwith thehelpofbetterunderstandingof themarketmicrostructure. Inchapter5.1,wedefinethesimulationmarketmodel,whichisusedtomodelFXmarket.

5.1 SimulationModelforFXMarketThesimulationmodelisaportfolioshiftmodel,wherethesourceofthevariationin exchange rates is basedon shifts in portfolio balance of the customers. ThemodelisbasedontheworkofEvansandLyons(1999).Thismodelwaschosenasthebasisofthesimulationbecauseofitssimplicityandthefactthatnomodelhas performed consistently better in exchange rate prediction in all timehorizons.Sincethemainpointofthisstudyistodevelopatradingalgorithm,theuseof thissimplifiedmodel formarketsseemsreasonable.Asimulationmodelbased on rational expectations could have been an alternative approach.However, thealternativeapproachwasdiscardedbecause itwouldhave led totheuseofimpracticalestimations.

The portfolio shifts are not common knowledge at the time of occurrence.Commonknowledgeisknowntoeveryoneinthemarkets(e.g.currentexchangerateandeveryoneknowsthateveryoneknowsthateveryoneknowsadinfinum).The shifts are large enough that the clearing of the market requires rateadjustments of the spot rate. The fact that a portfolio shift is not commonknowledgeatthetimeofoccurrenceservesasaninitiatingsourceoforderflow.Whenacustomerplacesprivate(notpublicallyobserved)quotestodealerswhotrade among themselves in the interdealer markets to share the resultinginventory risk. The market learns about the initial portfolio shifts throughinterdealer trading.Though it canbeconsideredcommonpractice thatdealersdonotholdovernightrisks.Theinventoryrisksaresharedwiththepublic.Theinventoryriskisnotdefinedindetail.Itisusedasconceptinpotentiallossduethe inventory, which adjust the actions of traders. The public’s demand forforeign currency assets has to be less than perfectly elastic because if thecurrency assets are imperfect substitutes, price adjustments are required toclear themarket. Innovations in themodel are considered in twoparts;publicinformation(standardmacrofundamentals)andnon‐public,privateinformation

Page 6: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

6

inportfolioshifts.However,themodeldoesnottakeintoaccounttheunderlyingsourceoftheseportfolioshifts.

LetusconsiderapureexchangeeconomywithTtradingperiods.Theeconomyhastwoassets;risklessandriskywithstochasticpayoffrepresentingtheFX.ThepayofT+1periodsintheFX,denotedF,iscomposedofaseriesofincrementsrt,observed before trading in each period. This flow of realised incrementsrepresents publicly available macro economic information (e.g. interest ratechanges).

F ≡ rtt=1

T+1

∑ , rt ~ N (0,Σ t ) i.i.d (1)

ThesimulatedFXmarketismodelledasadecentraliseddealershipmarketwithNdealersindexedbyi,andcontinuumofnon‐dealercustomersindexedbyzininterval[0,1].Withineachtradingperiodthreeroundsoftradingaredone.Inthefirstround,dealers tradewithcustomers(thepublic), i.e. receivethecustomerorder flow, which carries the information about the portfolio shifts of thosecustomers.Inthesecondround,dealerstradeamongthemselvesininterdealermarket to share the resulting inventory risk. In the third round, dealers tradeagain,butthistimewiththepublictoshareriskmorebroadly.

Figure1.Timingoftheperiod

Nextweconsiderthedifferentroundsoftrading.

Page 7: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

7

Round1

Atthebeginningofeachperiodt inround1,allmarketparticipantsobservertperiod’st incrementforpayoff.Basedonrt andallotheravailable information(both public and private information) each dealer chooses simultaneously anindependent price with which he/she agrees to sell and buy any amount ofcurrencytohis/hercustomers.Wedenotedealer‐priceforround1fordealeriasPi1.Dealer‐priceisamappingfromrtandallotherinformationtorealnumbers.Themappingisdefinedbydealerpreferences.ThevalueofPi1canbethesameamong multiple trades but it does not have to be. Every dealer receives netcustomerordersinthevalueofci1thatisexecutedbyeachdealer’squotepricePi1. ci1 <0 denotes net customer sales (dealer purchases). Each net customerorder ci1 is independent across dealers. Customer net orders are distributedindependentlyfromri1.Customerorderrealisationsaredistributedci1~N(0,Σc1).These initial customer orders can be seen as preferred bilateral customertransactions.Thesecustomerordersrepresenttheportfolioshiftsonthepartofthe non‐dealer public information and the realisation of these orders is notpublicallyobserved.

Round2

Round 2 is the interdealer trading round. In the beginning of the round, eachdealer independently and simultaneously chooses his/her price with whichhe/sheiswillingtobuyandsellanyamountamongthedealers.TheinterdealerpricePi2fortraderiisamappingofPi1andci1torealnumbers.Theseinterdealerquotes are observable and available to all dealers in the market. Then eachdealer independently trades on the other dealers’ quotes. The orders on thesamequotingpriceareequallydistributedamong thedealerswhoarequotingthatprice.LetTi2denotethe(net)interdealertradeinitiatedbydealeriinround2.Attheendofround2,alldealersobservethenetinterdealerorderflowfromthatperiod

Δx = Ti 2i=1

N

∑ (2)

Equation (2) is the interdealer order flow and it is observed without noise,though adding noise to the equation does not affect the estimates. FXmarketinterdealerorderflowisrecorded,becausedealer‐dealertradesareobservable.However,customer‐dealertradesarenotpublicallyobserved.Thesignalsofthecustomerorderflowareembeddedintheinterdealerorderflowandthesignalsfromtheformercanbeobservedtosomeextent.

Round3

In round 3 dealers share the inventory risk with the non‐dealer public. Thesimulation model is derived from the Evans and Lyons (1999) model, which

Page 8: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

8

focusesondailyexchangerateprediction.However,muchshortertimeperiods(minutes) are considered in our simulation. In their paper Evans and Lyons(1999)consideredround3asanovernightrisksharinground.Althoughintheminuteconceptround3isstillarisksharinground,itisalsomorespeculative.Initially, each dealer simultaneously and independently quotes a price Pi3 atwhichhe/sheagrees tobuyandsell anyamount.Thesequotesareobservableandavailable to thepublic.Thenumberof customers is largecompared to thenumber of dealers, implying that the public’s capability to bear risk is greaterthan thatofdealers’. Thereforedealers set theprices according to thepublic’swillingness tobear the inventory imbalance risk. In the conceptofdaily trade,therearenoovernightnetpositionsfordealerswhereasintheminuteconceptthe imbalance risk can be seen as the unbearable exposure to exchange ratevariation.Typically thismeans thateachdealerhas limitedcurrencypositions,whicharesettokeeprisksacceptable.Theseround3pricesareconditionedbythe round 2 interdealer order flow. The interdealer order flow informs thedealersofthesizeofthetotalinventorythatthepublicneedstoabsorbinorderto achieve stock equilibrium. Knowing the size of the total inventory that thepublic needs to absorb is not sufficient for determining the price for round 3.Dealers need to know the risk‐bearing capability of the public (normalassumptionisthatitislessthaninfinite).Givennegativeexponentialutility,thepublic’s total demand for risky assets in round 3, denoted by c3, is a linearfunctionofitsexpectedreturnthatisconditionalonpublicinformation:

c3 = γ E P3,t+1Ω3[ ] −P3,t( ) (3)

Wherethepositivecoefficientγcapturestheaggregaterisk‐bearingcapacityofthe public, andΩ3 is the public information available at the time of trading inround3.

Equilibrium

Thedealer’sproblemisdefinedoverfourchoicevariables,thethreepricequotesPi1, Pi2, and Pi3, and the dealer’s interdealer trade Ti2 (the latter being acomponent of ∆x, the interdealer order flow). Themore detailed reasoning ofBayes‐Nash Equilibrium in Evans and Lyons (1999) leads to optimal tradingstrategyhavingthepricedifferenceinperiodtandt‐1as

Δpt = rt + λΔxt (4)

Where λ is a positive constant. The fact that this price change includes theinnovationinpayoffsrtone‐for‐oneisunsurprising.Theλ∆xtermistheportfolioshift term. The no arbitrage conditions ensures that, within a given round, alldealersquoteacommonprice.Giventhatalldealersquoteacommonprice,thispriceisnecessarilyconditionedoncommoninformationonly.Eventhoughrt iscommon information in the beginning of round 1, the order flow ∆xt is notobserveduntil theendof round2.Theprice for round3 trading,P3, thereforereflects the information in both r and ∆x. Interdealer order flow carries thesignalsfrominitialportfolioshifts,ifitisassumedthatthedealers’tradeisbasedon initial customer order flow and in that sense interdealer order flowcommunicatestheinitialportfolioshiftsinthemarket.However,theaggregated

Page 9: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

9

information aboutportfolio shifts is absorbed into themarket and theprice isadjusted based on known information about the relation between interdealerorderflowandsubsequentpriceadjustments.Thisprocessof informationflowtakesafiniteamountoftime.

For simulation purposes we define empirical implementation of the pricedifferenceequation:

Δpt = β1Δ it − ii*( ) + β2Δxt +ηt (5)

where∆ptisthechangeinthelogspotexchangeratefromtheendofperiodt‐1totheendofperiodt,∆(it–it*)isthechangeintheovernightinterestdifferentialfromperiodt‐1toperiodt(*denotesforeigncurrency),and∆xistheorderflowfromtheendofperiodt‐1totheendofperiodt(negativesigndenotesnetsalesofthehomecurrency).

Theovernightinterestrateisthemacrofundamentalofthemodel.Itisassumedto bring all macro information into the model. In the simulation market theempiricalpricingrelationisusedtoadjustexchangerate,accordingly

Δpt = ln St − ln St−1St = St−1e

Δpt (6)

whereStisthespotexchangerate.

In the simulationmarket, order flow has three components, two ofwhich arebasedontradingalgorithms,andonewhichisacombinedorderflowfromotherdealersinthemarket.Therelativesizesoftheorderflowscangreatlyinfluencethedynamicsofthemarketandthiscanbeseenasoneinterestingfactorinthesimulation model. The simulation market model is based on an equilibriummodel,whereit isassumedthatunlessshiftsoccurintheportfoliosbalanceonthemarket, it tends to stay in equilibrium state. The non‐algorithmic dealers’order flows in period i are assumed to be normally distributed, because it isassumed that each dealer’s customer order flow is independently normallydistributed. This assumption is based on the model assumption of round 2tradingstrategies.Inround2,thedealerstradesomefractionofcustomerorderflowas their interdealermarket flow,which leadstoasumdistribution,whichcan be modeled as a normal distribution (N(0,σ2)). The normal distributionparameters can be seen as average values of the periodic values of thewholemarket. Hence he simulation market model is based on market orders, if wegeneralise the conceptof limit orders.We can see that the limit orders canbeseenasapartof theorder flow inaperiod, just like themarketorders in thatperiod. However, the limit orders could give a more detailed view of thebuying/selling pressure of the market. In certain cases, when the triggeringcondition for a limit order ismet, the limit order canbe executed in the samewayasamarketorder.Limitorderscanbeconsideredtobufferthechangesinexchangerate.

Page 10: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

10

Figure2Overviewofsimultationmodel

Figure 2 shows the components of simulation model and some basicrelationships between components. In addition customers are added toalgorithms.However, thosecustomersarenotexplicitlymodeledinsimulation.Algorithms are assumed to take customers in account as algorithms try tomaximizetheirownprofit.

5.2 TradingAlgorithmBasedonMicrostructureKnowledge.InordertoanalysemicrostructurebasedalgorithmsinFXmarket,wetestthreedifferent kinds ofmodels. Recursive reinforced learning (RRL) basedmodel isnot truly dependent on understanding the microstructure of the market.However, to some extent it can be regarded as the algorithm that is based onmicrostructure ideology. A more detailed description of RRL can be found inExploringAlgorithmsforAutomatedFXTrading–ConstructingaHybridModelMat‐2.4177SeminaronCaseStudies inOperationsResearch,Spring2008.ThefundamentalideaoftheRRLisalsousedinthesecondmicrostructurealgorithm,whichisforthemostpartofsimilarconstructiontotheRRL.Inprinciple,ittriesto model the order flow using the RRL to achieve reasonable predictions ofexchange ratemovements. The thirdmodel is a combinationof thebasicRRLandsomedirectlyorderflowbasedindicator(and/orflowitself).

The order flow RRL algorithm is fundamentally similar to the normal RRLalgorithm,whichusesreturnsindecisionfunction.Intheorderflowmodel,thealgorithm uses differences in the order flow to predict the order flow in thefuture.Therationalebehindtheattempttopredictorderflowandthatwayformadecisionoftheshort/longpositionistheideaofthestrongdependenceofthe

Page 11: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

11

spotexchangerateandorderflow.However,therelationbetweenspotrateandorderflowisnotasevidentastherelationbetweenreturnsandspotrate.Intheorderflowalgorithmthedecisionestimateismainlybasedonadaptive,movingaverageofthedifferencesinorderflow.

Ft = tanh(uFt−1 + v0ot + v1ot−1 +K+ vmot−m +w) (7)

where ot‘s are differences in order flow at t, i.e. how much cumulativebuying/sellingpressure is changed in time t, Ft is thedecisionandu, vi,waresystemparameters.

Togeneralisedecisionsandtoensuredifferentiabilityofthedecision,hyperbolictangent is used.Even though the function is continuous, decisions arediscreteand achieve three different positions; long, neutral and short ([1,0,‐1]).Continuousdecisionscouldbeusedtomeasurethestrengthoftheimpact,whichis based on the variation of the exchange rate. The differentiability of thedecisionfunctionisimportantwhenconsideringgradient‐basedoptimizationofsystemparameters. Thewealthof the trader is defined as the sumof periodicincrements.

WT = Rtt=1

T∑

Rt = µ Ft−1rt −δ Ft −Ft−1( ) (8)

whereWtisthewealthofthetrader,Rtistheperiodicincrementinwealth,µ>0isthetradingpositionsize,δisthetransactioncost,andrtisthereturninperiodt.

Tomeasuretheperformanceofthealgorithm,autilityfunctionofthetraderisdefinedasafunctionofwealthandprofit(WT,Rt).Strictlyspeakingthemeasureof the performance is not a utility function in the conventional sense. Thedifferentialratio,liketheSharperatio,isusedasaperformancemeasureforthealgorithm.AnotherpossiblemeasureistheSterlingratio.ThedifferentialratioisusedtocapturethemarginalutilityoftheRtineachperiod.Inthealgorithmthedownsized deviation, which is based on the Sterling ratio, is used as the riskadjustedperformancemeasureforthesystemparameterupdate.

Sterling ratio =Annual Average Re turnMaximum Drawn −Down

(9)

Downsizeddeviationratiois

DDRt =Average(Rt )

DDT

,

DDT =1T

min Rt ,0{ }2

t=1

T

1/2 (10)

InordertousetheDDRintherecurrentlearning,ithastobedifferentiated.Thelearning is defined as the gradient of the utility with respect to the systemparameters.

Page 12: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

12

dUT

dθ=

dUT

dRtt=1

T

∑ dRt

dFt

dFtdθ

+dRt

dFt−1

dFt−1dθ

(11)

Usinggradientlearningwithlearningrateρ,theadjustmentoftheparametersis

Δθ = ρdUT (θ )dθ

(12)

Note that due to the inherit recurrence of the total derivatives, the entiresequence depends on the previous time periods. To correctly compute thelearning in a time sequence, we have to compute in a recursive manner. Thelearningequationhasaform

Δθ t = ρdDt

dRt

dRt

dFt

dFtdθ t

+dRt

dFt−1

dFt−1dθ t−1

(13)

whereDtisadifferentialofDDR.

The other algorithm, which uses direct information from the order flow, is ahybrid algorithm that uses a combinationof thedecision suggestedbynormalRRL algorithm and order flow based moving averages. In the simulations wedecidedtousethemovingaverageofthefivelastobservations.Thedecisionisbasedonheuristictestsoftheperformanceofthealgorithm.However,itcanbereasoned that if the intraday trading happenswith high frequency, then the 5minute time marginal can be seen as a practical time period. The algorithmcombinestheinformationfromvarioussubalgorithmpartsandmakesdecisionsbasedonthatinformation.Themostobviousadvantageofthisalgorithmisthatby combining information frommultiple sources, it reduces the risk of biasedonesourcedecision.Inthishybridalgorithm,theorderflowpartdeterminesthepossible future direction of the spot exchange rate, if we accept the positivecorrelationassumptionbetweentheorderflowandspotnominalexchangerate.TheRRLpartgivesestimatesnotonlyoftheamountofchangeinspotexchangerate,butalsosomeestimateofthedirection.

ThecombinedmodeloftheRRLandorderflowismorepromisingthantheuseofdirectRRLbasedon theorder flowalgorithm.Thedecision function inRRLmade it possible for us to utilise order flowmore accurately, though differentfunctionalformswerethoughtandtested.

6. QuantitativeAnalysisofthePerformanceThequantitativeanalysis isperformedwithsimulateddataandtosomeextentwithrealdailydata(EvansandLyons(1999)).Eventhoughusingthedailydatasomewhat changes thenature of the trading,which is doneby algorithms, thealgorithmsareunrelatedtothetimediscretionofthemarkettime.

Tomeasuretheperformanceofthealgorithms,threemeasuresareused;profit,Sharperatio, anddaily ranking,which ismadebyrankinganalysedalgorithmsbythedailyprofit(profitmadeindailytradingtakingplacebetween0900‐1700i.e.in480minutes).Sharperatioisdefinedas

Page 13: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

13

ST =mean Rt

var Rt

(14)

whereRtisthereturnintimet.

Thesimulationsaredonewithasetofsimulationparameters,wherethespreadfor the day is 0.005. The spread is large, but can be seen in highly volatilemarkets (i.e. RUB). Half of the used spread is used as the transaction cost fortrading. High spreads, like the one used, should encourage algorithms to dofewer tradesduring theday.Large spreadsarealsoused toencouragegainingdifferencesinsimulationresults.Thetestedalgorithmshaveeachapproximately5%shareof the total order flowof themarket.Thealgorithms canbe seen torepresentmajor players in themarket (10th largest overall currency trader byvolume in May 2008 did have about a 3% share of the overall volume(EuromoneyFXsurvey)).Theparametersthatdefinetherelationbetweenorderflowandspotexchangeratearetheorderofmagnitudeofthenetorderflowof10million,whichwill cause a 1%change in spot rate according to thebuyingpressureofthedemand.Themagnitudeoftherelationisoverestimatedtofindpossiblechanges inexchangerate.Basedonthis, thevolatilityof themarket ishigh. In the simulation, the spot exchange rate is updated every minute.However,themacropartoftheexchangeratepredictionisupdatedonlyevery200minutes (aboutonce in every3hours). It canbe seen that the changes inmacrofundamentalshavealowerfrequency.

The model parameters in RRL‐based algorithms can greatly affect theperformanceofthealgorithm.WeshouldkeepthisinmindwhenconsideringtheperformanceofRRL‐basedalgorithms.Themodelparameters, likethe learningrateandnumbersofdifferences that isused in themovingaveragepartof thedecision function, will greatly affect the performance of the algorithm. In thesimulation,theRRLmodelparametersareheuristicallychosenandhaveahighlikelihood of not being the optimal ones. The choice of the optimal modelparameters for RRL based algorithms can be seen as one of the drawbacks ofusingthesealgorithms

7. ResultsThe simulation results are based on 10000 simulation runs of the simulationtrading day (480 min = 8 hour trading day) to obtain statistically significantresults. It took a total of two days to compute these simulation runs. Firstwelookattheresultswithoutanyfilteringorremovalofbiasedobservations.Thentenbest and tenworstdaily results are removed fromeachalgorithm’s result.Toanalysetheperformanceofthealgorithm,theKruskal‐Wallisnon‐parametricone‐way analysis of variance test (Gibbons, J. D) is performed. The commondescriptivestatisticsoftheprofitsare:

Page 14: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

14

Table1.Profitsofthedifferentalgorithms.(Profitsaremeasuredaspercentsand1meansthatthe equity of the dealer has not changed during the day. Exceptionally highmagnitude of 103profits or loses are explained by the simulation spot exchange rate, which gives a slightpossibilitytogainunrealisticallyhugevariationsinexchangerate.)

InTable1weseethedescriptivestatisticsofalgorithms.,theRRL+orderflowindicatorandRRLperformedwell.However,theorderflowbasedRRLhadthehighest overall resultwhen therewas no removal of the 10 best daily results.Thehighestresultwasintheorderofmagnitudeof1e+6.However,thiskindofresultwascausedbyexceptionalvariationoftheexchangerate.Thefluctuationofexchangerateisaninheriteffectofthechosenmodelparameters,whichwerechosentoencourageexchangeratevariation.Itis,however,noteworthythattheRRL+orderflowindicatorhasalsothebiggeststandarddeviation.Thiscanbeseen as anundesirable characteristic for a good algorithm.On the other hand,RRLseemstoperformaveragelywitharathersmallstandarddeviation.

Figure3Box‐WhiskerPlotoftheprofits.(1istheorderflowRRL,2isRRL,3isRRL+orderflowindicator)

Page 15: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

15

BasedontheKurskal‐Wallis test,wecanreject thenullhypothesisof thesamemedian of all three algorithm’s profits with confidence of 95%. By continuingtesting, we can see that even the medians of the RRL and RRL + order flowindicator differ from each other. We can conclude that the RRL + order flowindicatorseemstooutperformtheothers.

Table2.Sharperatiodescriptivestatistics

Figure4Sharperatios(Ratiosofeachindividualsimulationdaysortedindescendingorder)

Table 2 and in Figure 4 show that the order flow RRL performs bothexceptionally well and very poorly with respect to the Sharpe ratio. This isespecially evident in Figure 4where the line of the order flowRRL is very S‐shapedwhencomparedtotheotheralgorithms.WeseethattheRRLstaysratherflatwithrespect to theSharperatioand therefore itsperformance is steady, ifnot themost profitable. RRL + order flow indicator seems to performwell ingeneral,butdoeshavesomebaddays.Tosummarize,wecanconcludethatRRL+order flow indicator is inaclassof itsown ingeneral.TheRRLperformsmoststeadily.Theorder flowRRLdoeshave some remarkabledays,but theoverallperformanceisnotgood.

Page 16: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

16

Figure5Dailyrankingofthealgorithms(Fromleft:numberonerankings,numbertworankings,numberthreerankings)

Figure 5 shows that RRL + order flow indicator captures most of the toprankings.RRLhas a consistentperformanceand ranksnumber two inmostofthedays.OrderflowRRLseemstobetheoptionwiththeweakestperformance.

Page 17: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

17

Figure6 Results from real daily data (toppanel: blue= exchange rate, greendashed= orderflow.Restofthepanels:pink=orderflowRRL,greendashed=RRL,bluedash‐dot=RRL+orderflowindicator)

WecanseeanoteworthytrendinFigure6.TheorderflowRRLoutperformstherestofthealgorithms.ThisismainlyduetothemorecautiousnatureoftheRRL+orderflowindicator,whichcanbeseeninthedecisionspanel(Figure6.thierdpanelfromthetop),wheretherearemanyzerodecisionsmadebyRRL+orderflow. Looking at the Sharpe ratio panel, we can see that order flow RRLalgorithmatalltimesperformswellandthatotheralgorithmsperformhorribly.In order to gain more realistic and statistically correct results, more genuineminute datawould have been needed. The parameterisation of the RRL‐basedalgorithmscanalsobeseenasarelevantfactor,sincethemodelparametersforRRLwere chosen to represent a volatile simulationmarket. The effects of theparameters aremost clearly seen in theRRL+order flow indicator algorithm;thealgorithmistoocarefulandthereforemakestoomanyzerodecisions(Figure6, thirdpanel).However, since limited genuinedatawas available for theRRLmodelparameters,wewereunabletochoosetheminanymorespecifiedway.

8. LimitationsoftheSimulationThe simulation is somewhat simplified. We were forced to determine somesimulation parameters, namely parameters for distributions of the order flow,size of the market, and segmentation of the different algorithms. From thealgorithm point of view, one limiting factor was the choice of the modelparameters. The lack of a limit order book can be seen as a hindrance in thesimulationmodel.Therealisticimplementationofalimitorderbookisdifficult,because in order todefine it realistically,wewouldneed to know the traders’strategiesofusingtousethelimitorderbook.Thereareseveralwaystousethe

Page 18: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

18

limit order book; it can be used as a risk control method as well as in anopportunisticway.Thesimulationwasbasedononlyalimitednumberofagentsandtherestofagentpopulationwasmodeledonlywithdistributions.

9. ConclusionsTheuseoftheorderflowinformationandbetterunderstandingoftheFXmarkethelpdevelopbetter tradingalgorithms.However, theefficientutilisationof thegained information seems to be hard. The hybrid algorithms are the mostpromising approach to construct a well‐performing algorithmic trader. Thebetter understanding of the market microstructure helps us to develop moreaccurate indicators and hence, to improve algorithmic trading. Based on thesimulations presented in this paper, the order flow information helps us todevelopbetteralgorithmictraders.However,constructinganefficientalgorithmremainsachallenge.AlgorithmsimplementedliketheRRLareblackboxmodels.Thesealgorithmsareverysensitive tomodelparameterchanges.Theprospectof RRL‐based algorithms being able to learn to pick certain features in the FXmarketandtomakedefeasibledecisionsbasedonthosefeaturesispromising.Inorder to gain better andmore accurate results, genuineminute‐based data isneeded. Itmightbeavailable in some time in the futuremainlybecauseof theadvances inalgorithmsandthe transition touseelectricalbrokersystems(e.g.EBS).

The next logical research challenge is to develop an even better and detailedunderstandingofthemarketmicrostructure.Afterthatwemightseetheuseofnew kinds of algorithms, e.g. Hidden‐Markov process based algorithms,whichareusedwithsuccessinspeechrecognition.Inthefutureitisinterestingtoseewhethertheuseofalgorithmictradingwillalterthedynamicsofthemarketandexchangerateprocess,ornot.

Page 19: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

19

10. References

MarkP.Austin,GrahamBates,MichaelA.H.Dempster,VascoLeemansand Stacy N William, 2004, Adaptive systems for foreign exchange trading,QuantitativeFinanceVolume4(August2004)C37–C45PhilippeBacchettaandEricvanWincoop,2006, CanInformationHeterogeneityExplain the Exchange Rate Determination Puzzle?, The American EconomicReview, AmericanEconomicAssociation,vol.96(3),pages552­576,June.

JonDanielsson,RichardPayne,JinhuiLuo,2002,ExchangeRateDeterminationandInter–MarketOrderFlowEffects(http://www9.georgetown.edu/faculty/evansm1/New%20Micro/DonPayneLui.pdf)(27.1.2009)

MartinD.D. Evans andRichardK. Lyons, 1999,Order flow and exchange ratedynamics(http://faculty.haas.berkeley.edu/lyons/)(27.1.2009)

MartinD.D. Evans andRichardK. Lyons, 2001,Order flow and exchange ratedynamics, (http://papers.ssrn.com/sol3/papers.cfm?abstract_id=174888)(27.1.2009)

MartinD.D.EvansandRichardK.Lyons,2004,ExchangeRateFundamentalsandOrderFlow (http://www9.georgetown.edu/faculty/evansm1/wpapers_files/flows&fundv6.pdf)(27.1.2009)

MartinD.D.EvansandRichardK.Lyons,2007,ExchangeRateFundamentalsandOrderFlow,(http://www9.georgetown.edu/faculty/evansm1/)(27.1.2009)

MartinD.D.EvansandRichardK.Lyons,2005,ANewMicroModelofExchangeRateDynamics,(http://www9.georgetown.edu/faculty/evansm1/)(27.1.2009)

Martin D. D. Evans and Richard K. Lyons, 2005, Understanding Order Flow(http://ideas.repec.org/p/geo/guwopa/gueconwpa~05‐05‐19.html)(27.1.2009)

Martin D. D. Evans, Richard K. Lyons,2005, MEESE‐ROGOFF REDUX:(https://www9.georgetown.edu/faculty/evansm1/Home%20page.htm)(27.1.2009)

Martin D. D. Evans, Richard K. Lyons, 2005, Understanding Order Flow(http://ideas.repec.org/p/geo/guwopa/gueconwpa~05‐05‐19.html)(27.1.2009)

MartinD.D.Evans,2008,OrderFlowsandTheExchangeRateDisconnectPuzzle(http://www9.georgetown.edu/faculty/evansm1/)(27.1.2009)J.D.Gibbons,1985,NonparametricStatisticalInference,2ndedition,M.Dekker.

Page 20: Algorithmic Trading in Foreign Exchange Based on Order Flowsalserver.org.aalto.fi/vanhat_sivut/Opinnot/Mat-2.4108/pdf-files/enum09.pdfAlgorithmic Trading in Foreign Exchange Based

20

J. Koskinen, J. Airas, T. Nummelin, T. Pekkala and J. Starczewski, ExploringAlgorithms for Automated FX Trading – Constructing a Hybrid Model, Mat‐2.4177 Seminar on Case Studies in Operations Research, Spring 2008(http://www.sal.tkk.fi/Opinnot/Mat‐2.4177/projektit2008.html)(27.12009)

Richard K. Lyons, 2001, Foreign Exchange: Macro Puzzles, Micro Tools(http://www.frbsf.org/publications/economics/review/2002/article4.pdf)(27.1.2009)

R.MeeseandK.Rogoff,1983,Empiricalexchangeratemodelsof theseventies,JournalofInternationalEconomics.143–24

R.Meese andK. Rogoff, 1997, The out‐of‐sample failure of empirical exchangerate models Exchange Rates and International Macroeconomics, ed. J Frenkel(Chicago:UniversityofChicagoPress)pp23–38

Dagfinn Rime, New Electronic Trading Systems in Foreign Exchange Markets,NewEconomyHandbook,2003,ElsevierScience(USA)

Paolo Vitale, A Market Microstructure Analysis Of Foreign ExchangeIntervention,ECBWorkingpapers,No629/May2006

FengWang,Xiao‐BingFeng,LuTang,MicroeconimicModelingandSimultionofExhcange Rate with Heterogeneous Strategies, Proceedings of the SixthInternationalConferenceonMachineLearningandCybernetics,HongKong,19‐22August2007

Micro‐BasedExchangeRateForecasting,NBERWorkingPaperSeries,(WorkingPaper11042,http://www.nber.org/papers/w11042)(2009) Euromoney FX survey FX Poll 2008: The Euromoney FX survey is the largestglobal poll of foreign exchange service providers.' (wikipedia)(http://www.euromoney.com/Poll/3301/PollsAndAwards/Foreign‐Exchange.html)(27.1.2009)