<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by David Marcos on Medium]]></title>
        <description><![CDATA[Stories by David Marcos on Medium]]></description>
        <link>https://medium.com/@davidmarcos2002?source=rss-1040a91103d7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VtumVQEtC--5iLULap26bQ@2x.jpeg</url>
            <title>Stories by David Marcos on Medium</title>
            <link>https://medium.com/@davidmarcos2002?source=rss-1040a91103d7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 23:21:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@davidmarcos2002/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Algorithmic trading wheels and reinforcement learning for best execution and optimal routing]]></title>
            <link>https://medium.com/@davidmarcos2002/algorithmic-trading-wheels-and-reinforcement-learning-for-best-execution-and-optimal-routing-4023634be5fa?source=rss-1040a91103d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/4023634be5fa</guid>
            <category><![CDATA[quantitative-finance]]></category>
            <category><![CDATA[portfolio-management]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[algorithmic-trading]]></category>
            <dc:creator><![CDATA[David Marcos]]></dc:creator>
            <pubDate>Fri, 09 Dec 2022 15:41:31 GMT</pubDate>
            <atom:updated>2023-01-06T16:29:59.930Z</atom:updated>
            <content:encoded><![CDATA[<h3>Demystifying Trading</h3><p>Being a trader may be cool, but it is not an easy job. Contrary to the popularized view of traders and brokers relaxing on the beach while they tell each other that the market is a “fugazi”, they routinely perform tasks that require great skill and bring much value to society.</p><p>In its pure sense trading means effecting an exchange between two counterparties. After the transaction, both parties are, in theory, better off since each has exchanged some of what she has for some of what she needs. That is, trading is not a zero but a <strong>positive-sum game</strong>. Furthermore, the existence of financial markets allows buyers and sellers to have a common place to easily find goods, services, or financial instruments for investment, i.e., it guarantees the existence of <strong>liquidity</strong>. Most importantly, the more players in the marketplace, and the less frictions we have (such as fees, taxes, regulated trading hours, etc.), the easier it is to have an <strong>efficient market</strong> [1]; that is, to achieve a continuous formation of “fair” prices, which act as <strong>economic signals</strong> of what is important to society [2].</p><p>Whether we refer to commodities trading, equities trading, or derivatives trading, the situation is no different: Buyers and sellers benefit, firms may use capital to innovate and create new value, and investors may see their savings increase through interest payments as global wealth (which is not a conserved quantity) grows. Effective trading is paramount to society, and in the end, whether good or bad, we are all investors and traders.</p><h3>Challenges in Trading Execution</h3><p>From a more technical perspective, traders aim to execute orders in the market defined by four characteristics: i) <strong>security</strong> (the instrument they are interested in), ii) <strong>side</strong> (buy or sell), iii) <strong>size</strong> (number of shares or cash notional to be traded), and iv) <strong>trading horizon</strong> (how much time they have to complete the order). Doing this well (or <em>optimally</em>) poses several questions to the trader:</p><p>1) As I have different <strong>venues</strong> and <strong>brokers</strong> available, with whom should I execute the order?</p><p>2) If the order is large or market liquidity is low, how should I execute the order throughout the trading horizon? Which<strong> strategy</strong> should I use?</p><p>3) Given that I need to comply with regulatory <strong>best execution</strong>, how do I ensure I do so?</p><p>4) If I have certain discretion, when should I go in or out of the trade? Is there <strong>momentum</strong> or <strong>mean-reversion</strong> in the market?</p><p>5) How can I <strong>automate</strong> the process?</p><p>The traditional approach to address these questions is as follows:</p><p>1) Finding the right trading destinations constitutes the <strong><em>optimal routing problem</em></strong>. Traders typically execute each order with whom they believe will provide a better price. Such belief may be based on historical observations, requested quotes, observed bid/ask prices, and alike. However, intuitively accounting for such factors is difficult and may be subject to bias, limited memory, and other human-related limitations.</p><p>2) Executing large orders across the trading horizon with minimal market impact and minimal timing risk (or volatility risk) represents the <strong><em>optimal execution problem</em></strong>. Once again, the intuition of traders to find the optimal trading path may be flawed: minimizing transaction costs ultimately depends on the shape and dynamics of the order book, including bid/ask spreads, depth, and volumes. As we will see, modelling such market microstructure can be addressed with statistical learning.</p><p>3) The regulation on <strong>best execution</strong> establishes that <em>investment firms must take adequate measures to obtain the best possible result when executing clients’ orders</em> [3]. Although rather generic, this definition mentions <em>“the best possible result”</em>. Therefore, traders and regulators should ask themselves “what is the best possible result?”. A correct answer can only be given in terms of a quantitative comparison among different executions. This would require knowing what would have been the outcome had the trader executed the order differently, but since the very act of executing an order affects the market, this cannot be precisely known (in technical words, <em>market impact cannot be precisely measured</em>). However, if we want to achieve best execution, we should, at the very least, use quantitative models to <em>estimate</em> the <em>price impact</em> and <em>costs</em> associated to different executions, and <em>transaction costs</em> should be defined as a mathematical distance to an “<strong>efficient trading frontier</strong>” [4]. Such approach is not common practice, and as such, many banks and asset managers are not correctly assessing performance and, strictly speaking, violating best execution.</p><p>4) Execution traders may have a view of the market dependent on mid-price moves, in which case they might decide to wait more or less time to enter a trade (start time). However, mid-price <strong>trends and patterns</strong> can also be captured with machine-learning models, which may help the trader in terms of capturing <em>alpha</em> (or excess returns).</p><p>5) Finally, the process of <strong>pre-trade</strong> (order routing and execution) and the process of <strong>post-trade</strong> (performance and <em>transaction cost analysis</em>) can both be made less manual. To do this correctly, it is important to use the appropriate execution benchmarks, and that only orders that are similar in nature are compared to each other. This might involve analysing order characteristics and pre-<strong>clustering</strong> orders in order to appropriately determine outlier trades or broker and trader performance.</p><p>In recent years, <strong><em>algorithmic trading wheels</em></strong> (or “algo wheels”) have emerged to tackle these problems. An algo wheel is a software that chooses brokers, venues, and/or execution algorithms, given certain rules or specifications established by the trader. The degree of sophistication of current algo wheels varies widely: from those using vanilla statistical analysis to those utilizing machine-learning models for optimal execution. However, traders typically find the underlying models somewhat obscure and hard to trust. Furthermore, these models are rather static: they do not adapt rapidly-enough to changing market conditions, yielding results that are good in sample, but clearly inappropriate out of sample.</p><p>Given these challenges, it is clear that significant effort should be put into the <em>modelling</em> aspects of Trading Execution.</p><h3>Reinforcement Learning: The right solution to Trading Execution</h3><p>Optimal routing and optimal execution can be both naturally expressed as <em>reinforcement learning</em> problems. In short, Reinforcement Learning is a sub-field of Machine Learning whereby an agent (trader in our context) chooses actions (brokers, venues, or execution volumes in our context) and receives a reward/punishment (profit/cost in our context). After this cycle the agent ends up in a new state and the process is repeated. Actions with higher rewards are chosen more frequently, thus “learning” an <strong>optimal</strong> <strong>policy</strong> (routing protocol or execution path in our context). Such an agent lives in a particular environment (marketplace in our case) that determines possible states, actions, and rewards.</p><h4>Optimal routing</h4><p>When receiving an order, a trader might choose to route it to a particular destination (broker or venue), or to split it across destinations, for its execution. Such choice is made according to the expectation of which destination will provide the best execution price. Generically speaking, the cost associated to this transaction will depend on <em>provided liquidity</em> (depth and shape of the order book), <em>mid-price</em>, <em>bid/ask spread</em>, and <em>commissions</em>. In order to determine favourable destinations, we could compare historical prices for similar orders and under similar market conditions. This is what execution traders do, intuitively.</p><p>The optimal routing problem is akin to a <strong>multi-armed bandit problem</strong> in machine learning literature [5]. Here an agent must choose among destinations whose underlying reward distribution is unknown. However, after every choice the outcome from every destination is somewhat revealed, allowing the agent to take a reinforcement-learning approach. For example, the agent can implement an “epsilon-greedy” algorithm, whereby in the next iteration he chooses to <em>“exploit”</em> the best destinations (those with the highest (time-weighted) cumulative reward up to that point in time) with probability <em>1-epsilon</em> (being <em>0 &lt; epsilon &lt; 1</em>) while he chooses to <em>“explore”</em> destinations different to those with the highest cumulative reward with probability <em>epsilon</em>. The results of this approach versus typical trader performance are indeed very promising.</p><h4>Optimal execution</h4><p>A second kind of problem that traders face is the following: Given an order, how should it be executed throughout the trading horizon? With a fast speed of execution (aggressive trader, aiming to finish the order rapidly) he might move the market against him (i.e. far away from the price at the order start) while with a slow speed of execution (passive trader, executing a large portion of the order at later times) the market might move against him (i.e. other traders may drive the mid-price away from that at the order start). In the first case we say that the trader generates a large <strong>market impact</strong>, or that he consumes a large portion of the order book. In the second case, we say that the trader experiences <strong>timing risk</strong> (or volatility risk), that is, price fluctuations that may lead to a higher execution price. There is therefore a trade-off between completing an order very quickly and very slowly, which gives rise to the concept of <strong>optimal trading path</strong>: the execution profile throughout the trading horizon with minimal market impact and minimal timing risk.</p><p>There are many models to determine the optimal trading path. Most of them assume a functional form of market impact (e.g. proportional to the square root or to the logarithm of executed volume per time interval) and assume a specific stochastic process for the price dynamics (e.g. market returns following a Gaussian or a t-Student distribution). The success of this procedure, however, relies on the quality of the model assumptions and on the calibration of the model parameters (which should be done fairly frequently due to changing market conditions). A natural alternative to address the optimal execution problem is using <strong>Reinforcement Learning</strong>.</p><p>The mapping of the optimal execution problem to a reinforcement learning problem is as follows: If we divide the trading horizon (for example 1 day) into time intervals (for example 30 minutes), at every point in time the trader asks himself “what percentage of the order should I execute in the next interval?”. Therefore, right before every interval the trader (reinforcement learning agent) is in a <strong>state</strong> defined by <em>time</em>, <em>remaining order size to be executed</em>, and <em>limit-order book characteristics</em>. He then decides to take an <strong>action</strong> (<em>volume to execute over the subsequent interval</em>) and depending on market impact and price volatility he will obtain a <strong>reward</strong> (<em>difference between the execution price and the mid-price at the order start</em>).</p><p>The advantages of using reinforcement learning for optimal execution are numerous, but can be briefly summarized as: i) the agent receives feedback after<strong> every trade</strong> and can thus rapidly adapt to changing market conditions, ii) a new modelling paradigm, different to that considering parametric or supervised-learning models is used, therefore not depending on the quality of <strong>parameter calibration</strong>, and iii) if fed with appropriate order-book data, the algorithm produces results that <strong>outperform </strong>standard execution benchmarks.</p><h3>Conclusion</h3><p>Overall, Reinforcement Learning represents a natural and advantageous technique to substantially improve<strong> Algorithmic Trading</strong>. More generically, given the advances in Artificial Intelligence, we may ask the question <em>“Can we build a machine that learns how to trade?”</em>. Seeing the recent progress from <em>OpenAI</em>, <em>DeepMind</em>, and alike, where we see super-human performance in games such as Go, Pong, Breakout, and other Atari games, together with signs of creativity and innovation from machines, it is natural to think that we can design a machine that mimics, and perhaps outperforms, the actions and behaviours of execution traders working at the main investment banks and hedge funds. This is a future that is worth considering and be well prepared for. Learning how machines think and bringing this knowledge to the field of Algorithmic Trading can only be beneficial for Traders, for AI, and for the world.</p><h3>References</h3><p>[1] E. F. Fama, <a href="https://www.jstor.org/stable/2325486"><em>Efficient Capital Markets: A Review of Theory and Empirical Work</em></a>. Journal of Finance <strong>25</strong> (2): 383–417 (1970).</p><p>[2] F. A. Hayek, <a href="https://www.jstor.org/stable/1809376"><em>The Use of Knowledge in Society</em></a>. The American Economic Review <strong>35</strong> (4): 519–530 (1945).</p><p>[3] <a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=uriserv%3AOJ.L_.2014.173.01.0349.01.ENG&amp;toc=OJ%3AL%3A2014%3A173%3ATOC"><em>Directive 2014/65/EU of the European Parliament and of the Council of 15 May 2014 on the markets in financial instruments and amending Directive 2002/92/EC and Directive 2011/61/EU (recast) (Text with EEA relevance)</em></a>, Art. 27, Sec. 1.</p><p>[4] R. Almgren and N. Chriss, <a href="https://www.risk.net/journal-risk/2161150/optimal-execution-portfolio-transactions"><em>Optimal Execution of Portfolio Transactions</em></a>, Journal of Risk <strong>3</strong> (2): 5–39 (2001).</p><p>[5] R. S. Sutton and A. G. Barto, <a href="https://mitpress.mit.edu/9780262039246/reinforcement-learning/"><em>Reinforcement Learning: An Introduction</em></a>. The MIT Press, Cambridge, Massachusetts (2018).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4023634be5fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>