<?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 The Quant Economist on Medium]]></title>
        <description><![CDATA[Stories by The Quant Economist on Medium]]></description>
        <link>https://medium.com/@shajjouz?source=rss-91d14629fce9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7-kOjM0pyqVsAM_CVA_2eg.jpeg</url>
            <title>Stories by The Quant Economist on Medium</title>
            <link>https://medium.com/@shajjouz?source=rss-91d14629fce9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 12:02:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shajjouz/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[Automate Your Trading Strategy with GitHub Actions]]></title>
            <link>https://medium.com/@shajjouz/automate-your-trading-strategy-with-github-actions-36291fbcaf91?source=rss-91d14629fce9------2</link>
            <guid isPermaLink="false">https://medium.com/p/36291fbcaf91</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[stock-market]]></category>
            <category><![CDATA[portfolio-management]]></category>
            <category><![CDATA[algorithmic-trading]]></category>
            <category><![CDATA[trading]]></category>
            <dc:creator><![CDATA[The Quant Economist]]></dc:creator>
            <pubDate>Sun, 15 Sep 2024 13:56:42 GMT</pubDate>
            <atom:updated>2024-09-15T13:59:53.194Z</atom:updated>
            <content:encoded><![CDATA[<p>Many people enjoy trading, and even more appreciate a quantitative approach. However, everyone desires automated execution of their trading strategies. Yet, few non-professionals have demystified how to achieve this in practice without spending countless hours learning how to do it or potentially paying for cloud services like AWS, Google Cloud Platform, etc., for scheduled script execution.</p><p>Take, for example, a <a href="https://github.com/stefan-jansen/machine-learning-for-trading">popular book</a> on algorithmic trading. It will teach you everything—except what you might need to do in practice to actually implement your ideas. Executing trades, or more generally, performing routine tasks on a scheduled basis, is a prerequisite to validating the feasibility of your strategy (as retail trader you cannot simply be on top of your computer all the time). This applies not only to trading strategies but also to tasks like monitoring risks and timely assessing your portfolio’s performance.</p><p>In this blog post, I’ll introduce an idea of how to use a free and reliable method to automate your trading strategies (and not only) without relying on paid cloud services. I will start by exploring different ways to schedule Python scripts but then introduce you to how you can execute your trading strategy automatically using GitHub Actions to create a free solution for executing scripts on a schedule (e.g., daily at a specific time).</p><p>Most of the solutions out there never consider the use of Github Actions as an alternative workflow scheduler. Rather, focus on complicated and more conventional methods, trying to explain how to do it using cloud services, which might not necessarily be free or have some limitation that might not suit someone&#39;s purposes.</p><p>As an economist, I’m not interested in delving into complex software engineering details for a simple task. Like many others, you probably don’t need a highly complicated process to execute a trading strategy. My goal is to show how <a href="https://docs.github.com/en/actions">GitHub Actions</a> can be leveraged to also automate trades based on your Python script’s logic. I won’t share any specific trading script, as the internal details aren’t essential for understanding the scheduling process.</p><p>To keep this post concise, I’ll make a few assumptions:</p><ul><li>You are familiar with Python, GitHub, and how to create repositories. Although Python is not essential to setting up a Github Action.</li><li>You are using a trading platform that allows you to communicate with APIs, place orders, and monitor your positions (or portfolio) programmatically (e.g., OANDA, IBKR etc.).</li></ul><p><strong>Why Schedule Python Scripts?</strong></p><p>Scheduling Python scripts can offer significant advantages for automating various tasks. One of the most compelling benefits is the ability to automate repetitive, time-consuming tasks. This not only saves time and effort but also ensures consistent execution and accuracy, reducing human error. In essence, it’s a productivity booster and an effective real-time monitoring system.</p><p>So scheduling the execution of trades is a simple application of such ideas. Beyond automated trading, scheduling Python scripts can be invaluable for other portfolio management tasks. For example, you can automatically collect data upon data releases, systematically monitor portfolio performance with minimal effort, and more. Additionally, if you use forecasting models, automating the production of forecasts can be a valuable thing to do. Therefore, don’t let the title deter you from exploring the potential benefits of scheduling your scripts for other (portfolio management) tasks.</p><p><strong>Simple Local Methods to Schedule Scripts</strong></p><p>As a Mac user, when I first explored how to run my scripts on a scheduled basis, I came across cron. It’s worth pointing out this solution first, as it can be useful for experimental purposes. For users on Linux or macOS, cron is a built-in utility that allows you to schedule tasks to run at specified times. This is ideal for running scripts locally, such as a Python trading script that fetches data and places trades.</p><p>At first glance, setting this up might seem complicated, but in practice, it’s actually very simple and straightforward. Here are the steps:</p><ol><li>Open your terminal and type this command: ``crontab -e``</li><li>Then hit the letter: &quot;i&quot; (for insert)</li><li>Specify the frequency and time (in cron’s syntax) for the scheduled task, followed by the local path of the environment where your Python script runs and the local path to your Python script. For example, you might enter this command in the terminal:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*lGZMXvggjlHgvXUJHKQy3A.png" /></figure><ul><li>0 0 * * * means the script will run every day at 00:00 (midnight in UCT time zone). <strong>More on this later.</strong></li><li>Replace/path/to/your/python/environment/bin/python with the (local) path to your specific Python environment.</li><li>Replace/path/to/your/script.py with the (local) path to your Python script.</li><li>And do not forget to leave spaces in between.</li></ul><p>4. Save and exit the crontab editor by hitting: &quot;:wq&quot;</p><p>You can repeat this process to add more scheduled tasks for different scripts. To verify that a schedule is set up, use the crontab -l command in the terminal. To delete a task, repeat steps 1-2, locate the task, remove it, and then save and exit as in step 4. For Windows users, there is the Windows Task Scheduler. But as I mentioned, I am not using Windows. So I leave this to the readers to explore.</p><p>Local scheduling methods like `cron` and Windows Task Scheduler are easy to set up, but they have a significant limitation: <em>your machine must be turned on for the scripts to run</em>. So, is the case with some nice Python libraries like <a href="https://pypi.org/project/scheduler/">Scheduler</a>. This can be a problem for tasks like automated trading, where missing an opportunity because your computer is off could be costly. This is where solutions like <strong>GitHub Actions</strong> come into play.</p><h3><strong>Automating Python Scripts with GitHub Actions</strong></h3><p>GitHub Actions is a powerful tool for automating workflows directly from your GitHub repository. It allows you to schedule Python scripts to run at specific times, even if your local machine is off. Best of all, GitHub Actions is free for public repositories and offers generous limits for private ones.</p><p>Let’s look at how you can leverage GitHub Actions to schedule and execute Python scripts in the cloud, making it a perfect solution for automating tasks like placing trades.</p><p><strong>Why Use GitHub Actions for Automated Trading (or other portfolio management routine tasks)?</strong></p><ul><li>Free and cloud-based: GitHub Actions runs entirely in the cloud, so you don’t need to keep your computer on.</li><li>Easy scheduling: Using cron syntax, you can schedule your Python script to run at any time of day.</li><li>Environment management: Easily install dependencies or manage virtual environments.</li><li>Custom workflows: Create highly customizeable workflows based on triggers like time, commits, or external events.</li></ul><p><strong>Setting Up GitHub Actions for Scheduled Python Scripts</strong></p><p>In this example, we’ll walk through scheduling a Python script using GitHub Actions. This script could be designed to fetch data, generate signals, and place trades. In this case, it assumed that this script would implement your trading strategy and would communicate with a trading platform to place orders. But as mentioned before, could be any script that you want to schedule.</p><p>To set up your workflow using Github Actions you basically needs steps.</p><ol><li><strong>Step 1</strong>: Create the GitHub Repository</li></ol><p>First, make sure you have a GitHub repository where your Python script is stored. If you don’t have one, create a new repository and store it in Github. This repo should also host your script that you wish to run on a scheduled basis.</p><p>2. <strong>Step 2</strong>: Create a Workflow File</p><p>In your GitHub repository, create a directory called.github/workflows/. This is where you&#39;ll place the workflow configuration file that tells GitHub Actions how to schedule and run your script. In the.github/workflows/ folder, create a YAML file named, for example,scheduled_script.yml (or any name you prefer) with the following basic content:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*1sLF83ddDWT-jCJKhGHzpw.png" /></figure><p>The YAML script above defines a GitHub Actions workflow named “Scheduled Python Script”. Here’s a breakdown of what each section does:</p><p><strong>name:</strong></p><p>This defines the name of the workflow, which will be displayed in the GitHub Actions interface. In this case, it’s “Scheduled Python Script”.</p><p><strong>on:</strong></p><p>This section defines when the workflow will be triggered. Here, it has two options:</p><ul><li><strong>schedule:</strong> This triggers the workflow on a specific schedule defined using a cron expression.</li><li>cron: &#39;30 21 * * *&#39; specifies the following schedule:</li><li>Runs every 30th minute (30)</li><li>At 9:30 PM (21) in UCT time zone (indicated by asterisk *)</li><li>On any day of the month (*)</li><li>In any month (*)</li><li>On any day of the week (*)</li><li><strong>workflow_dispatch:</strong> This allows the workflow to be triggered manually from the Actions tab in your repository. For instance you can see in your Github repo this:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i_gkyomOn9ebh29AWrXmVw.png" /></figure><p><strong>jobs:</strong></p><p>This section defines the jobs within the workflow. Here, you have only one job named “run-script”.</p><p><strong>jobs.run-script:</strong></p><p>This defines the details of the “run-script” job:</p><ul><li><strong>runs-on:</strong> This specifies the runner environment where the job will be executed. In this case, it runs on an Ubuntu virtual machine with the latest version (ubuntu-latest).</li><li><strong>steps:</strong> This defines the sequential steps that will be executed within the job:</li></ul><ol><li><strong>Check out repository:</strong> This step uses the actions/checkout@v3 action to download the code from your GitHub repository.</li><li><strong>Set up Python:</strong> This step uses the actions/setup-python@v4 action to install and configure the specified Python version (3.8 in this case) on the runner.</li><li><strong>Install dependencies:</strong> This step executes shell commands using run. The script first upgrades pip (the Python package manager) and then installs the dependencies listed in a file named requirements.txt. This file likely contains a list of Python libraries needed for your trading script.</li><li><strong>List installed packages:</strong> This step uses pip list to display a list of all currently installed Python packages in the runner environment. This can be helpful for debugging purposes.</li><li><strong>Run script:</strong> This final step uses python to execute your trading script named trading_script.py. Here the script expect the path in your Github. (Github has the option to copy and paste the path of any item in your repo).</li></ol><p>This workflow essentially automates running your Python trading script on a scheduled basis (every day at 9:30 PM UCT) and allows for manual triggering from the Actions tab as well.</p><p>The above yml script most likely should work for most use cases. Just ensure that yourrequirements.txt file is clean and your environment doesn&#39;t include any local packages (I will try to create a new post how to handle this, but I cannot promise). To generate this file, activate the environment where your script runs and type pip freeze &gt; requirements.txt in your terminal. This would create a requirements.txt in the root of your repo (it is important to place it in the root of your repo!). This file should have all required packages, one per line and hence it is used to manage dependencies. The contents for example should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*L2Kd8FF9DArvNGNB8oy82Q.png" /></figure><p>Here is, for example, the structure of my repo and PyCharm Project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*XSC_pUI_J1LyUtPjVRTkAQ.png" /></figure><h3>Understanding GitHub Actions Schedules</h3><p>As mentioned before, GitHub Actions uses UTC for its cron syntax. The cron expression &#39;0 1 * * *&#39; means &quot;run at 1:00 AM UTC every day&quot;. To adjust for your local time zone, you&#39;ll need to convert your desired run time to UTC.</p><p>For example:</p><ul><li>New York (EST, UTC-5): To run at 9:00 PM EST, use &#39;0 2 * * *&#39; (2:00 AM UTC next day)</li><li>Los Angeles (PST, UTC-8): To run at 6:00 PM PST, use &#39;0 2 * * *&#39; (2:00 AM UTC next day)</li><li>London (GMT, UTC+0 or BST, UTC+1): To run at 9:00 AM GMT, use &#39;0 9 * * *&#39; (9:00 AM UTC, same time)</li><li>Tokyo (JST, UTC+9): To run at 10:00 AM JST, use &#39;0 1 * * *&#39; (1:00 AM UTC, same day)</li></ul><p>Remember to account for daylight saving time if applicable in your region. For alternative scheduled tasks, explore <a href="https://crontab.guru/">this page</a>.</p><p><strong>Conclusions</strong></p><p>GitHub Actions provides a powerful way to automate your Python scripts. By following this guide, I hope you can set up a workflow that runs your scripts on a schedule, manages dependencies, and handles outputs. Best of of luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36291fbcaf91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How different are the 70s from today?]]></title>
            <link>https://medium.com/@shajjouz/how-different-are-the-70s-from-today-b4760cea6f60?source=rss-91d14629fce9------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4760cea6f60</guid>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[macroeconomics]]></category>
            <category><![CDATA[inflation]]></category>
            <category><![CDATA[investing]]></category>
            <dc:creator><![CDATA[The Quant Economist]]></dc:creator>
            <pubDate>Thu, 24 Mar 2022 08:08:19 GMT</pubDate>
            <atom:updated>2022-03-24T08:09:38.300Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*KGSSeCf70pNwVP6E5Wk6Iw.jpeg" /></figure><p>The war in Ukraine has raised significantly the odds of a recession in the near term, but also the likelihood to move into a new inflation regime as in the 70s. How real this risk is depends on the key differentiating factors between now and then.</p><p>In a nutshell, textbooks would tell that a sequence of oil crises (rooted, like now, in geopolitical factors) permanently increased the cost of production for firms and, by extension, the cost of goods and services. This subsequently triggered a wage-price spiral (as households were trying to catch up with rising prices) which led to ever-increasing inflation. Such past experience places a material probability that a similar mechanism triggered by the same factors (oil shock and high inflation) might re-emerge with the Fed or all other major central banks unable to control inflation.</p><p>A closer look, however, at the underlying factors that underpinned the mechanism behind this wage-price spiral would suggest that this time is different. <strong>In short, the structurally weaker bargaining power of workers and its dependency on the economic cycle is effectively putting an upper limit to any catch-up of wages with extreme inflation. The direct implication of this key differentiating factor alone is that a) any wage-price spiral is likely to be short-lived relative to the 70s, especially when growth would start to slow down and b) the cost-push shocks are unlikely to turn into permanent supply shocks as then.</strong></p><p>In the rest of this post, I will mostly focus on discussing this argument in more detail, along with a few other, more known, key dissimilarities between then and now. In my mind, I have mostly the US economy, but some of the arguments are relevant for other countries, too.</p><p><strong>The 70s and now</strong></p><p>One obvious difference between now and then, is that this wage-price spiral that unfolded during the 70s was heavily relying on the structurally strong bargaining power of workers that is absent today. Workers at the time were unionised and their bargaining power did not necessarily depend on the tightness of the labor market or the state of the economy as now. Currently, a recession or a slow down in economic activity (either due to monetary policy tightening or a negative shock such as now with oil prices) is almost automatically reducing the bargaining power of most workers, and this in a fashion that nominal wages might not necessarily catch-up with inflation without legislation.</p><p>An exception here might be the high-income high-skilled households who nevertheless tend to consume less energy-intensive products (with declining overtime cost of production due to technological advancements) while their high marginal propensity to save diminishes the strength of aggregate demand on prices (formally flattening of the Philips Curve). This also highlights that in the absence of trade unions the degree of (wage or income) inequalities is another confounding factor that stops wages from catching up with inflation and implies that, on the aggregate, real wages most likely would fall. This effect in turn can help offset the (often reversible) production costs due to higher energy prices and help prevent the cost-push shocks to turn permanent.</p><p>Put more simply, the structurally weaker bargaining position of workers in effect implies that any temporary cost-push shocks are less likely to manifest themselves into the permanent supply shock of the 70s, especially since oil is now a less important input to the production compared to the past.</p><p>New modes of work arrangements and the ability of multinationals to either outsource or reallocate abroad (expensive) labour-intensive functions are two other factors that can reduce the persistence of cost-push shocks. For example, competition might force firms to contain their labour costs and among the available options they have is to offer indefinite work-from-home arrangements. This new mode of working could lift some of the pressure for workers to catch up with inflation when they are given the option to indefinitely move to less expensive regions. On the other hand, multinationals might choose to react more aggressively if they think their profitability is severely distressed. For example, they could choose to outsource some of their labour intensive high-skill functions or reallocate their workers abroad. Given their size in the economy and the limited availability of quality jobs for high-skilled workers in advanced economies, this might further reduce the bargaining power of workers when economic growth slows down.</p><p><strong>Excess saving, secular stagnation, low-interest rate and all that</strong></p><p>Secondly, the world now is structurally very different from the 70s. We live in a world where the global economy (perhaps the first time in its history) is producing an excess amount of savings with record low real investments. With governments around the world having not really solved this problem it is extremely unlikely to see any change of this structural issue in the foreseeable future. This dearth of investments contains, therefore, a very strong deflationary process that was totally absent during the 70s.</p><p>The forced coordination across countries in transitioning to net-zero or now the accidental coordination to increase defence spending (with little to no influence on r*, natural interest rate) is unlikely to outweigh the strong incentives to save from demographics, higher inequalities, structurally weaker labour markets in combination with a weaker welfare state, and governmental or private market schemes, such as private pension schemes or other unfunded social security programmes — that typically raise the incentives to save but at the cost of depressed returns on capital and higher financial risk, hence further reinforcing the incentive to save to reach target wealth levels by retirement which further depress returns and so on (``savings trap”). By now, we know by experience that in this world financial markets have a stronger incentive to keep most of the liquidity in the financial system (in search of yield) rather than finance real investments that depend on a very weak long-term growth outlook.</p><p><strong>Other key differences</strong></p><p>There are a few other more nuanced differentiating factors that are worth highlighting here. First, the degree of financialisation together with the prevalence of idiosyncratic financial risks to households unveil other strong deflationary forces.</p><p>For households, is safe to assume that it is more challenging now to insure against the risk of employment, career and job displacement risks, health shocks etc. So, the most important insurance mechanism against bad outcomes is to build up buffers of savings and more wealth. Such a precautionary savings motive might be stronger today than in the past for a number of reasons:</p><ol><li>Much weaker welfare states and employment protection that increase the severity of possible negative income shocks (which academic economists showed also explain the skewness of, much more uneven today, wealth distribution )</li><li>More leveraged households are extremely susceptible to negative wealth shocks mainly due to the housing market</li><li>More individualistic societies that make people rely more on their own feet than expect the help of others.</li></ol><p>Having money and building up wealth becomes then a high order priority for most households to survive any adverse outcome or to increase their quality of life.</p><p>Second, the degree of financialisation, as is captured by what economists might call market incompleteness, has increased since the 70s due to the liberalisation of capital flows and the availability of more hedging instruments. Now, the degree by which investors can hedge against risks is substantially greater today than before. In a world in which liquidity is abundant, this reinforces the incentives of the financial system to allocate more money into (risky) financial assets rather finance real investments (which as said before rely on a weak long-term growth outlook).</p><p><strong>Final thoughts</strong></p><p>Although this analysis is anything but comprehensive and the future is always uncertain, I highlighted here a few crucial differentiating factors that play a dominant role in most economies today and are important for the inflation regime. The deflationary forces from the structurally weaker labour force not only is putting an upper limit to the wage-price spiral (that is central to many peoples’ arguments for inflation to go out of hand) but also limits the extent by which a cost-push shock can turn into a permanent supply shock. This, together with the legacies from the “excess savings world”, unleash a strong deflationary process that can only be reversed by either a serious escalation in the war in Ukraine (a largely unpredictable factor) or by some serious policy mistake from now on.</p><p>The Fed in particular still has the inflation under control, albeit at the cost of a recession or a slow down in the near term economic growth. Here it is quite likely that a soft landing scenario might materialise a hybrid regime which, on the one hand, inherits some of the functional characteristics of the 70s with a permanently higher inflation, but on the other hand might be ultimately functioning like the “excess savings world”.</p><p>Finally, the structural characteristics in the labour markets also imply that the deflationary process might be asymmetric and more unsynchronised across countries (i.e. the opposite case with the existing inflation dynamics). For Eurozone countries, which also inherit critical similarities with the 70s such as the “fixed exchange rate” regime, rising public debt, and current account imbalances, as well as they feature higher sensitivity to oil prices, inflation might become a source of a new political conflict due to ECB’s hawkish turn. This adds a greater uncertainty in Eurozone countries around the long-term inflation outlook and does not rule out the possibility that some countries might indeed experience a relatively long stagflationary period given the asymmetric (recessionary) implications of the ECB and the lack of political and fiscal union.</p><p><em>(the views expressed here are my own)</em></p><p>Want to connect? <a href="https://www.linkedin.com/in/moustafa-chatzouz-9081811b/">https://www.linkedin.com/in/moustafa-chatzouz-9081811b/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4760cea6f60" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inflation Regimes: What Basic Clustering Methods are saying?]]></title>
            <link>https://wire.insiderfinance.io/inflation-regimes-what-basic-clustering-methods-are-saying-5eec29bf58bf?source=rss-91d14629fce9------2</link>
            <guid isPermaLink="false">https://medium.com/p/5eec29bf58bf</guid>
            <category><![CDATA[macroeconomics]]></category>
            <category><![CDATA[investing]]></category>
            <category><![CDATA[inflation]]></category>
            <category><![CDATA[timeseries]]></category>
            <category><![CDATA[clustering]]></category>
            <dc:creator><![CDATA[The Quant Economist]]></dc:creator>
            <pubDate>Sun, 26 Sep 2021 09:34:07 GMT</pubDate>
            <atom:updated>2022-07-21T07:04:21.875Z</atom:updated>
            <content:encoded><![CDATA[<p>Writing about inflation is not an easy task. Definitely not now, where all you hear in the financial press is whether inflation is here to stay or is a matter of time to return to more normal levels. Investors, governments, and central bankers alike are trying to evaluate whether inflation is transitory or permanent. Investors care about this distinction to position their portfolios accordingly, governments to re-assess their budgetary policy, and central banks to evaluate their next move.</p><p>This article will go through a simple statistical analysis that aims to cluster inflation dynamics into different regimes <a href="https://www.wikiwand.com/en/Dynamic_time_warping">using the Dynamic Time Wrapping approach </a>— a basic time-series clustering method in machine learning (ML). This technique has been used to cluster different series, but in this article what I want to show is how to use the very same approach to find similar periods across time for one series only.</p><p>Another motivation for writing this article is to help promote use cases of ML tools in macroeconomics. At the end of the article, I will also post a link to my repo where I am hosting the Python script that replicates this analysis.</p><p>I will focus on the US and the CPI index and repeat the analysis with and without energy and food prices. I will first start with some basic exploration of the raw series, and then I will move on to the clustering exercise. I will use monthly data as I believe this gives a better sense of the inflation dynamics. The series are seasonally adjusted from the source (Fed St. Louis). The sample uses the latest available information (the series end Aug 2021 when I did it). The scope is to find similar to each other periods based on the underlying trend in inflation. From the economics point of view, the objective is to check which period in the past is the most similar to the current inflation dynamics. But instead of using human judgment would let the machine tell me.</p><p>But before I go to the analysis, I think it is good to briefly discuss the meaning of the terms &quot;transitory&quot; and &quot;permanent&quot; as I don&#39;t feel that everybody is on the same page. It also helps to understand better the methodology taken here.</p><p>My gut feeling says that if you ask ten different people the meaning of `transitory&#39;, it is quite likely to hear eleven different answers. I remember a well-respected Chief Economist, who works for a top asset manager, saying that central banks will change the definition of transitory inflation to extend from a few months (say three) to a little longer (say nine months). Although FED&#39;s communication may not be the best, I don&#39;t think central banks ever changed any definition.</p><p>On this issue, I have noticed two types of people. Those who use the term transitory to refer to the duration of the cycle and those who use the term transitory to refer to the type of economic shock. These are not necessarily the same concepts. In this article, the use of transitory refers to the type of economic shock.</p><p>In general, <a href="https://www.oxfordreference.com/view/10.1093/acref/9780198759430.001.0001/acref-9780198759430-e-2847?rskey=MVuBTf&amp;result=2994">there are two types of shocks</a>, Transitory and Permanent. A transitory shock is expected to disappear after some point, as happens with business cycles like recessions. However, this indeed creates some ambiguity because of the unknown duration of such a cycle. A typical business cycle may last up to 2 years, for example. Of course, from the practical point of view the duration of such a cycle matters. That’s a related, worth considering, type of question. But to keep things simple, I will not cover it here though you should know that transitory does not mean that is necessarily short-lived.</p><p>Because transitory shocks typically trigger much weaker market responses, this explains to some great extent why the yields or gold haven&#39;t moved much <strong><em>relative to the size</em></strong> of the current inflation shock. That&#39;s simply because markets themselves think of it as a shock that progressively would be fading, in other words, they think of it as a transitory shock.</p><p>Another sloppy analysis sometimes done by a few economists, strategists, or journalists is mixing things up between inflation and price levels. A transitory inflation shock implies a <strong><em>permanent</em></strong> increase in <strong>price levels</strong>. Inflation is the growth rate of prices, so even if you have a one-off shock to the growth rate you get a permanent change in the levels. So, don’t make statements like this one that I read in the news: ``the recent rise in consumer prices will be transitory or more permanent’’. Are not very meaningful.</p><p>On the other hand, a permanent shock is something that you expect to endure far ahead in the future. A regime shift in other words. In this case that would mean a shift in the underlying inflation trend that depends on the fundamentals, like the natural rate of unemployment or the (de-)anchoring of the inflation expectations. Fundamentals also include the policy regime, that is preferences of governments and central banks about inflation. For a change in inflation regime, what really matters is the so-called π* (pi star), that is the rate of inflation that prevails when the economy is back to potential output or to use more jargon the rate of inflation consistent with the natural rate of unemployment. It is in this case that there is a serious chance that the inflation regime might change. The problem here is that π* is unobservable and so an ideal experiment would require estimating π*. For a medium article, this is too much for a simple illustration of a clustering technique.</p><p>To proxy this case, however, in the analysis I have removed the cyclical component of the raw statistics and focused on the underlying trend. I did this using economists&#39; favourite <a href="https://www.wikiwand.com/en/Hodrick%E2%80%93Prescott_filter">HP filter</a>. But you can apply any other filtering method you want or you think is more appropriate such as the Kalman Filter. Good data scientists usually smooth the raw series because they know is better for the time-series clustering algorithms. It also makes nicer interpretations when you are using time-series data. But here is the difference between &quot;doing the right thing&quot; vs &quot;doing things right&quot;.</p><p>What my &quot;ML research assistant&quot; told me is that the regime for the <strong><em>core</em></strong> inflation (i.e. ex-food and energy prices) hasn&#39;t changed. However, adding to this picture the food and energy sectors — which I like to think of them as representing the supply side of the economy — and we are back to the record high inflation regime of the 70s.</p><p><strong>Combining these signals, it looks that what matters is the supply-side factors</strong>. For example, do you believe that the semi-conductor shortages are equivalent to the &quot;toilet-paper&quot; crisis? Then it is a matter of time for supply to meet demand and be back to normal (maybe we need to be a bit more patient this time). On the other hand, do you believe that there is a significant re-organization on the supply side? Οr that a ship stuck in a Chinese port is re-shaping trading networks? Then we might already be in a new inflation regime similar to the one in the 70s, and so is a matter of time for the <strong>core</strong> inflation to change regime too. The more weight you put on the latter scenarios, the more likely is for the Fed to start thinking about raising interest rates.</p><p><strong>Inflation over time and the New “Bretton Woods&quot;</strong></p><p>Before I go to the details of the results, I think is useful to go through a brief history of inflation. Figure 1 below shows how the inflation rate (annualized) evolved over the last 70 years. The blue and orange lines are rolling averages that remove the big cycles and the noise from monthly data to see the series better. The green and red lines are the underlying trends of the headline and core inflation, respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*r2h2cd2uI-ZCePYQgZxbtw.png" /><figcaption><strong>Figure 1</strong></figcaption></figure><p>In general, inflation has gone through two broad periods. The first one begins with the so-called Golen Age of Capitalism (roughly from the &#39;50s to early &#39;70s) and ends late &#39;70s to early &#39;80s. After crisis upon crisis (the collapse of the Bretton Woods system, oil crisis, a few political crises etc.), we then decided to bring a &quot;better&quot; version of capitalism where the only &quot;serious&quot; argument you hear is that now people have (a tiny) chance to get rich by exploiting opportunities that few can have. Political manifestos aside, the second broad phase for inflation begins in the early &#39;80s when inflation started declining and then stayed relatively low and stable until recently.</p><p>Suppose now that you are an investor standing at the peak of the inflation rate in the late &#39;60s and then you saw this subsequent big dive in the early &#39;70s that seems to have lasted about two years. By the equivalent standards that many people currently think this <em>decline</em> in inflation rate might have signalled to you a <em>permanent</em> shock (fall) to inflation — after all two years of falling inflation ain&#39;t enough permanent situation for you?</p><p>You might have already shorted gold, resisted investing in commodities, and so ended up losing a lot of money based on how history unfolded. We move forwards, and as we are approaching the end of that decade, inflation scores new highs. You now think that this time you have it right and repeat the same mistakes losing money again. If you are a man, chances that your wife might have broken up with you were high, as while baby boomers were building fortunes, you ended up broke.</p><p>You start blaming Keynes for your miserable life because he taught you that everything was demand-driven, and so you were looking at the unemployment numbers. Later, you found some solace in some smart economists who agreed with you that Keynes was to blame on this occasion. These economists also picked up that you also got a little smarter by not looking too much at the past when you think about the future and taught new tricks to central banks and politicians — who by that time got a bitter divorce after a decade of remorse.</p><p>Heartbroken central bankers found your new forward-looking thinking charming and made you a marriage proposal which you happily accepted. The agreement is that whatever central banks want to do will do and will tell you in advance (or at least close the eye), so your whims or mood would not destabilize the economy much when you hear bad news. The fact that central banks stayed away from their ex- ( i.e. politicians) helped make the agreement credible and the marriage prosperous. Managing aggregate demand was never easier for central banks.</p><p>Such forward guidance and the anchoring of expectations contributed to creating a relatively stable environment where inflation was declining at a steady pace. In fact, between 1980–2007, things were so boring compared to the past that economists decided to troll us and call this period the &quot;Great Moderation&quot;. The Global Financial Crisis and the period that followed, <a href="http://www.princeton.edu/~markus/misc/Lucas2003.pdf">except that ridiculed Nobel Prize winners and the intellectual originators of the Great Moderation</a>, did not shake this relationship. Maybe it made the (modern version of) Philips curve more irrelevant and inflation expectations more dominant for stabilizing inflation, but no real drama.</p><p>Now you are wondering, am I standing in the same peak where it all began? Effectively, what you are asking here is if the new &quot;Bretton Woods&quot; system, where everybody in the last few decades got used to the idea that inflation expectations remain anchored (within bands), would collapse. That&#39;s a question that some smart Global Macro funds might have been waiting for decades to answer.</p><p><strong>Inflation Regimes</strong></p><p>I told you before what signals I got from applying the basics of a basic ML tool. So, let me now show you the analysis. I will not write anything extensive here, beyond going through a few pictures and some talk. Perhaps not as entertaining as before.</p><p>Figure 2 shows the different clusters (regimes) according to the <a href="https://www.wikiwand.com/en/Dynamic_time_warping">DWT clustering technique</a> (twisted for my purpose here). This basic analysis suggested that there are three regimes when looking at core inflation. For the record, I used the elbow method to determine the optimal clusters. One can also try other metrics like the Silhouette. For those not familiar, what this means is that I did not pick the number of regimes myself but let the machine suggest this to me. Each regime has its own colour in Figure 2. The interesting bit is to check if the current regime has changed or not.</p><p>According to the results, everything after 1990 (and before 1970) belongs to the same inflation regime (dark purple line). We have the case where core inflation was either trending upwards or downwards but with a few bumps (cycles) in between (green line). The third regime — the &quot;outlier&quot; — covers most of the stagflation era and its turning phase, which begins roughly at the time of the third oil shock in 1979 (yellow line).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*VyvBWVgW2-v9tB_IgOYfMA.png" /><figcaption>Figure 2</figcaption></figure><p>For headline inflation, the machine again suggested three regimes. However, what has changed is that the current regime seems similar to the 70s (Figure 3, yellow line). The difference is that headline inflation includes the food and energy sectors. I am assuming that these sectors are good proxies in picking up the developments on the supply side. So, the current regime looks more like the early stages of stagflation. My &quot;ML research assistant&quot; seems to be reasonable.</p><p>(I implicitly assume a &quot;Markovian property&quot; consistent with time series. That is, if we begin from the &quot;dark purple&quot; regime in figure 3, the next possible regime is necessarily the &quot;yellow&quot; one where inflation would be trending upwards. So, one could then model the switch in the inflation regime through a Markov model.).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*FtSor4mT-Fwqetnv5Q9kYA.png" /><figcaption>Figure 3</figcaption></figure><p>At face value, and in line with what many people are saying or what we already know, the supply side of the economy seems to be the differentiating factor here. And, supply factors aren&#39;t easily controlled by central banks. I let you place your own judgment and make your own conclusions. Have already placed my quick thoughts before, but you can expand with yours. Keep also in mind that the analysis does not have the most up-to-date information of the last month (Sept 2021).</p><p>There is also more serious stuff that you can do, like model the switch in the inflation regime or think about the more serious scenario in which the Fed might lose control in managing inflation expectations. You might of course crunch your own ML clustering methods and extend them to understand the underlying factors that explain the differences in the regimes. Also, you can just simply repeat the same analysis by looking at different inflation metrics ( there are many ) and combining insights.</p><p>Here is the <a href="https://github.com/msh855/Medium_repo/blob/main/Inflation_Regimes.ipynb">link</a> to the repo.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5eec29bf58bf" width="1" height="1" alt=""><hr><p><a href="https://wire.insiderfinance.io/inflation-regimes-what-basic-clustering-methods-are-saying-5eec29bf58bf">Inflation Regimes: What Basic Clustering Methods are saying?</a> was originally published in <a href="https://wire.insiderfinance.io/">InsiderFinance Wire</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>