<?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 EASON on Medium]]></title>
        <description><![CDATA[Stories by EASON on Medium]]></description>
        <link>https://medium.com/@espaceship?source=rss-891c9427722------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6Gi-DUdmTsph3etmjfLhiw.jpeg</url>
            <title>Stories by EASON on Medium</title>
            <link>https://medium.com/@espaceship?source=rss-891c9427722------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 11:12:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@espaceship/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[Map the Chaos in S&P500]]></title>
            <link>https://espaceship.medium.com/map-the-chaos-in-s-p500-b51e67a800bc?source=rss-891c9427722------2</link>
            <guid isPermaLink="false">https://medium.com/p/b51e67a800bc</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[stock-market]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[trading]]></category>
            <dc:creator><![CDATA[EASON]]></dc:creator>
            <pubDate>Mon, 17 Jan 2022 13:43:10 GMT</pubDate>
            <atom:updated>2022-01-30T09:10:13.840Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jmTnxQM8drZ6eEVBP9AZug.png" /><figcaption>The outer product of the chaos scores (0–1) in S&amp;P 500 constituents</figcaption></figure><p>Many systems (e.g., weather, stock market) are governed by complex nonlinear differential equations. Given such a system, a small delta in the initial starting state, may cause a huge difference in how it evolves and where it ends up. This is the key idea of <strong>Chaos Theory</strong>, that is, some systems are very sensitive to initial conditions, so much so that we can not reliably predict the outcome of their simple dynamics. But whenever we have something unfathomable, there is value in studying it; our entire exercise of science is to establish orders in chaos, whether chaos is the nature of things or just our subjective experience.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F6z4qRhpBIyA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D6z4qRhpBIyA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F6z4qRhpBIyA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/863ecc4cf908d20bb4cd52f0097e7fda/href">https://medium.com/media/863ecc4cf908d20bb4cd52f0097e7fda/href</a></iframe><h3>A. Application of Chaos Theory</h3><p>The classic way to evaluate chaos from Chaos theory is <strong>Maximal Lyapunov Exponent</strong>, which quantifies the predictability of a dynamical system by its rate of separation from trajectories emerged from close initial states. In this article, we focus on the fact that we just have 1 trajectory, and we don’t have a simulator to sample from different starting points.</p><ul><li>One thing that Chaos Theory helps to answer is the question of <strong>the furthest point at which the prediction of future behavior is the most valid</strong>. In weather forecasting, for instance, this means assessing how many days into the future can we reliably predict weather using the same model.</li><li>Chaos Theory also helps us understand <strong>fractals</strong>, which are<strong> </strong>repeated nonlinear patterns that start from simple patterns to ultimately complex patterns. This allows us to <strong>create more powerful simulators using simple arithmetic</strong>.</li></ul><h3>B. Objectives</h3><p>Given a dynamical system whose behaviors are observed in terms of an ordinal discrete time series, our method will seek to answer the following questions:</p><ol><li><strong>What is the best range of time steps in which the time series (the system behavior) is most stable? </strong>This helps us to predict the stable points that capture the evolution of time series rather than noise.</li><li><strong>How chaotic a time series is compared to others?</strong> In the case of trading, this helps us to focus on what is more predictable (therefore more profitable) than what is valuable but maybe hard to predict (therefore more risks).</li></ol><h3>C. Method</h3><p>In general terms, we can say that an ordinal dynamical system demonstrates chaotic behavior if its sample trajectories diverge a lot from a small difference in the initial points. Conversely, a stable behavior follows the regression towards means pattern (what goes up must come down), such that the time series will be a subseries of “stable points” that best capture the evolution of the time series minus chaos, or noise.</p><p>Given this intuition, for a given ordinal time series, we will perform a Fourier Transform for different spans (a span is a number of sequential time steps) and different initial starting points on the time series.</p><ul><li><strong>To assess the most stable span of the time series</strong>, we evaluate all spans for each initial starting point of the time series, so each span will have a unique starting point and a number of time steps. We then look at the distribution of the decomposed frequencies and see how “normal” they are in order to identify the most stable span. Normality here signals “stability”, the idea of what goes up must come down. <strong>This stable span helps us assess the furthest point we can predict on a time series, before its patterns start to diverge (becoming chaotic).</strong></li><li><strong>To assess the overall stability of the time series</strong>, we look at the distribution of the best spans (based on absolute count) for all initial starting points. The more centralized the distribution, the less chaotic the time series is, and vice versa. We give this measurement of centralization a name — <strong>chaos score </strong>—<strong> </strong>a value between 0 and 1 with 1 indicating absolute stability. <strong>This score helps us compare between different time series data by their stability.</strong></li></ul><h3>D. Experiment</h3><h4>1. Data</h4><p>For the purpose of demonstration, here we use TWO time series: One stable and one chaotic. The stable time series is just a normal Sin Wave, the chaotic time series is the daily close price of Google (GOOG) stock price.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*sOIf_vzxIf5mgmoyjPOBew.png" /></figure><h4>2. Fitting</h4><p>During the fitting process, we see that the mass for Google prices keeps getting more “pointy”, this shows that our method is becoming more confident in what is the most stable span. Conversely, since Sin Wave doesn’t exhibit irregularity, its distribution won’t change after just 1 iteration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*j5Jfrzk-JC343rwkvs74sA.gif" /><figcaption>The figure shows the probability mass function of the cumulative chaos score for all spans.</figcaption></figure><h4>3. Results</h4><p>The chaos score for Sin Wave is <strong>1.00</strong> and for Google is around <strong>0.05</strong>. The score (0–1) measures the stability of the given time series, with 1 indicating absolute stability. The best span for Sin Wave is <strong>4</strong> and the best span for Google prices is <strong>3</strong>.</p><p><strong>Sin Wave: </strong>Below, we show that the stable series as defined by the calculated span forms a trend line that best cancels out the noise(the ups and downs).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*GAY4SSfcWx_1DYPM4yw29g.png" /></figure><p><strong>Google: </strong>The same effect applies to Google stock prices; a stable point is settled at every 3 time steps on the original time series, such that that stable series constitutes the trend line of the time series.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*yMSdwZphNRCHXWMT9zPQsg.png" /></figure><h3><strong>E. Summary</strong></h3><p>Some key takeaways from analyzing S&amp;P500 with our method:</p><ul><li><strong>Fifth Third Bank</strong> is the most stable contributor to S&amp;P 500 while <strong>Nike</strong> is the most unstable with ~ 2 times more irregularities than FT Bank.</li><li>For stocks, a stable regressive cycle according to an “unknown” mean tends to happen <strong>every 3 days</strong>.</li><li>We can visualize the chaos in S&amp;P 500 by computing the outer products of the chaos scores for all stocks; some clusters are clearly visible, as seen in the cover photo.</li></ul><h3>Discussion</h3><ul><li>Say we want to plot a trend line using <strong>n</strong> moving average, what is the most representative <strong>n</strong> to use?</li><li>For training a high-frequency predictor, how can we be sure we are not training the model on more noise than signal?</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b51e67a800bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Reinforcement Learning to rule over Algorithmic Trading]]></title>
            <link>https://espaceship.medium.com/use-reinforcement-learning-to-rule-over-algorithmic-trading-a32c891774?source=rss-891c9427722------2</link>
            <guid isPermaLink="false">https://medium.com/p/a32c891774</guid>
            <category><![CDATA[investing]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[deeplearing]]></category>
            <category><![CDATA[quantitative-finance]]></category>
            <dc:creator><![CDATA[EASON]]></dc:creator>
            <pubDate>Wed, 20 Jan 2021 13:39:56 GMT</pubDate>
            <atom:updated>2022-08-27T14:22:02.279Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Use Reinforcement Learning to do Algorithmic Trading</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yq2-CZA9IpArRmB-2VyZNw.png" /></figure><p><strong>Context</strong>: For the longest time, I’ve avoided offers in Quantitative Finance as I believe it does not address the heart of people’s problems; however, I do think that there is value in using Quantitative Finance as a problem to develop better utility that does just that. This is because working on the algorithmic trading problem can help us better harness machine creativity in coming up with strategy. Programs like AlphaGo &amp; AlphaGoZero are truly creative, not only because they could invent new moves, but also due to the fact that they can be modeled as Generative Models, allowing us to see strategizing as a creative task. Here, from a non-finance person’s vantage point, I’d like to articulate the merits of Deep Reinforcement Learning for algorithmic trading.</p><h3><strong>A Theory About Quantitative Trading:</strong></h3><p>Assuming people don’t cash out money in the financial market unless for abnormal situations like the market crash, what they do is just moving money from one asset to another, hoping for value increment. Therefore, based on this theory, all trading techniques ultimately are about computing a correlation matrix for all assets, because the money redrawn from one asset would go to another as reflected in their prices. If we have a portfolio with <strong>n</strong> assets, with just one feature for each asset, we will have a giant n by n matrix that is hard to swallow, that is why we may want to use an expressive function like Neural Network to compute the correlation matrix.</p><blockquote>“All trading techniques ultimately are about computing a <strong>correlation matrix</strong> for all assets.”</blockquote><h3><strong>Why Deep Reinforcement Learning:</strong></h3><p>Speed is an essential requirement in algorithmic trading. Quantum Finance offers a fresh computing paradigm, but we also need logics that make the trade decision. Ideally, we need a framework that releases the bottleneck in decision-making as much as possible. Currently, self-supervised learning carries a bright future in AI; it holds the superb performance of supervised methods as well as the “no-label-no-problem” of unsupervised methods. Self-supervised learning methods all have one thing in common, they themselves generate the learning targets which they will be trained on. Their learning process goes like this: The agent (1) first makes a prediction, (2) observes the actual occurrence, and then (3) checks the prediction for error, and finally (4) learns from that error. And yes, I have just described the essence of Reinforcement Learning. Knowing what Reinforcement Learning is, now let’s see why it works for algorithmic trading.</p><p><strong>1. Efficient Explore &amp; Exploit.</strong></p><p>For most domain-specific problems with well-defined objective functions, rather than trying hard to develop models, we should be concerned with developing a better representation of the environment to train the model. But even with an adequate representation, using it to derive a trading strategy is a rather difficult job for humans, for there are simply too many possibilities. Overtime, human traders tend to rely on only a few signals as their primary tools. Luckily, unlike other frameworks, reinforcement learning deals with both the prediction (e.g., stock prices) and control (e.g., portfolio allocation). With offline reinforcement learning, we can learn trading strategies offline, venturing into the uncharted territories. This massively reduce the execution latency needed for high-frequency trading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h6yQR4JmAw4mCylQ3zWJ8Q.jpeg" /><figcaption><strong>Contrary to Online Reinforcement Learning, Offline Reinforcement Learning trains the agent with a fixed dataset alone without any further incoming data. This makes learning more efficient and allow for policy “completeness” . In online learning, the current policy is dependent on a stochastic future, it’s therefore incomplete. Though the complete strategy of today may not apply to the future, if it’s a complete strategy, it tends to be more robust.</strong></figcaption></figure><p>In <strong>offline-reinforcement learning</strong>, the agent is trained on a fixed dataset of experiences “offline” rather than the experiences on the go (online). Normally,<strong> </strong>offline-Reinforcement Learning faces an existential problem: Given a dataset with fixed targets, if the agent acts too off the track, we wouldn’t know the targets of its actions. But in algorithmic trading, we can always compute the different targets with the prices, this saves us massive trouble in control.</p><blockquote>“…even with an adequate representation, using it to derive a trading strategy is a rather difficult job for humans for there are simply too many possibilities.”</blockquote><p><strong>2. Trade on the future, not the past.</strong></p><p>Although the past data is all we have, it is simply not an adequate predictor of the future for most non-stationary problems, particularly in financial markets where events are ever-changing. <strong>Model-based reinforcement learning</strong> has a unique philosophy, rather than trying to predict the future based on the past, the agent can vision all the possibilities of the future and plan ahead. For example, say, if you don’t want to do your homework, you could either (1) gamble on the possibility that your teacher will not bring it up, or (2) you can prepare a response for each of the 2 possibilities as your teacher may or may not bring it up. With the latter option, you will be in control of the situation regardless of what it is to come. When there are a lot of possibilities, preparing for the future (rather than predicting it) helps to lift the burden of uncertainty. By focusing on preparing for the major possibilities, we are now dealing with the problem of capacity rather than accuracy, which is a lot easier to command. In fact, as I’d like to believe, RL’s reliance of Markov Decision Process empathizes this unique take on tackling the problem of continuous predictive control, where we only use the current state as the latent space to vary the response to the future while discarding the past.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j1xH9ywr6Gdq3lBzrdAMgQ.jpeg" /><figcaption><strong>Markovian Reinforcement Learning model can be viewed as a GAN-like generative model where a generator (our policy) would act as a Bayes model to estimate a posterior (action) based on sample states drawn from a prior d(s). In single agent setting, the discriminator is fully trained to recognize d(s), so the model plays a reward-maximization game. In multi-agent setting, the discriminator (market) is affected by other players, so d(s) becomes non-stationary and so the agent becomes an Empirical Bayes involved in a MinMax game that converges at Nash equilibrium.</strong></figcaption></figure><p>Since the financial market is inherently non-stationary, a plug-in framework like Model-based Reinforcement Learning should be considered as a solution for an Empirical Bayes estimator. Regardless, we have to keep in mind that the state-action value prediction is wrong from time to time, so a decoupling of prediction and decision must be realized.</p><blockquote>“Although the past data is all we have, it is simply not an adequate predictor of the future for most non-stationary problems.”</blockquote><p><strong>3. Separation of prediction and decision.</strong></p><p>A long-established rhetoric in Inferential Statistics to separate prediction and decision. The reasoning is that “making a correct prediction at a given time doesn’t guarantee that the decision based on that prediction will be correct.” There are many possible reasons for this, to give one example, consider the following scenario where we have two targets following two different normal distributions. Though both left and right have the same expectation, standard deviation is a lot wider on the right, hence more uncertainty, in which case our actions should be different (e.g., seeking more diversification on RHS).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9K8clDyMbyNh5RC8ZR2Yzw.png" /><figcaption><strong>The Linear model on the LHS is more robust than the one on the RHS because it has lower variances. On the RHS, we may need extra information at every step to reduce the uncertainty.</strong></figcaption></figure><p>The rhetoric for separating prediction and decision should be strong in Algorithmic Trading because stochastic predictors (e.g., stock predictor) usually require computing the expectation of a target distribution. Reinforcement Learning currently employs the so-called <strong>Actor-critic methods</strong> where a model comprises a Critic (making prediction on the state-action value) and an Actor (making decisions based on, but not restricted by, the Critic’s prediction). Since both functions are trained concurrently and end-to-end, there is no need to worry about their alignments. However, the value function (Critic) should be regularized to account for the fact that the state distribution is non-stationary.</p><blockquote>“… making a correct prediction at a given time doesn’t guarantee that the decision based on that prediction will be correct.”</blockquote><h3><strong>Concluding remarks: The perfect game for one thing that is good at games.</strong></h3><p>For average people, trading is, but a game called the “Greater Fools”. Your goal is to find people who are more foolish than yourself so that you can sell them something of less value. If everyone knows an asset is going to fail, no one will be willing to make the trade; hence, the financial market is one of the few human inventions that spawns riches out of chaos, and if wining of any kind is about reducing the uncertainty of the environment, there will be no inherent win-win scenario to trading. In other words, trading financial assets is different from commodities, it is an adversarial game, and your only goal is to beat a stochastic opponent (the market, or another trading bot) who is under the same rules (hopefully) but with imperfect information. Better yet, this stochastic opponent is not one but many actors who you even team up with: Riding the trend is one of the benefits of teaming up to benefit all, but only temporally. And that’s all there is to it. It so happens that Reinforcement Learning is very exceptional at handling games with simple rules but a lot of probabilities. Like the game of Go, one can learn its rules under 60 mins, but the game has more broad configurations than the number of atoms in the Universe. If Reinforcement Learning can beat the game of Go, it can beat the market.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a32c891774" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>