Modeling a Dynamic Trade War using Julia: Assumptions, Simulation, and Impacts on the US Economy
Julia Programming

Modeling a Dynamic Trade War using Julia: Assumptions, Simulation, and Impacts on the US Economy

Eric Torkia

Building a simple dynamic simulation in Julia

Share:

Print

Rate article:

No rating
Rate this article:
No rating
Modeling a Dynamic Trade War: Assumptions, Simulation, and Impacts on the US Economy

In today's interconnected global economy, trade wars and tariff policies can have far‐reaching impacts on domestic and international markets. This blog article is intended to foster a discussion and give fellow decision modelers and strategists (Decision Superheroes) a simple framework to understand the system dynamics of a trade war. The models were coded in Julia and all the files are available on Github.

Understanding Trade Wars

A trade war occurs when countries impose tariffs or other trade barriers on each other in response to perceived unfair trade practices or imbalances. Rather than negotiating, countries engage in tit-for-tat measures, which can escalate and hurt both economies by reducing international trade and increasing prices for consumers. In this context, these measures revolve mostly around tariffs, counter tariffs and export taxes.
Tariffs are taxes imposed on imported goods. They serve multiple purposes:

  • Revenue Generation: Governments collect money from imported goods.
  • Protectionism: Tariffs can help protect domestic industries by making imported goods more expensive compared to local products.
  • Political Leverage: Tariffs can be used as a tool in diplomatic or trade negotiations.

Counter tariffs (or retaliatory tariffs) are tariffs imposed in response to tariffs set by another country. When one nation raises tariffs on imports, the affected country might retaliate with its own tariffs, escalating into a trade war. Another approach is to use export taxes which are levied on goods leaving a country. Unlike tariffs, which are applied to imports, export taxes reduce the competitiveness of domestic goods abroad. They can be used to conserve valuable resources or ensure domestic supply but might also discourage exports.
Historically, many nations have used high tariffs as a way to protect emerging industries:

  • United States in the 19th Century: During the early years of industrialization, the U.S. maintained relatively high tariffs (sometimes over 40%) to shield its young manufacturing sector from established European competitors. This protection helped stimulate domestic industrial growth but also led to higher consumer prices.
  • Import Substitution Industrialization (ISI) in Latin America: In the mid-20th century, many Latin American countries imposed high tariffs to foster domestic industries by reducing reliance on imports. Although this strategy initially boosted local production, over time it sometimes resulted in inefficiencies, lower competitiveness, and economic stagnation due to a lack of innovation and exposure to global markets.

In contrast, countries with lower tariffs tend to experience more dynamic competition and integration into the global economy:

  • Post-World War II Europe: The establishment of the European Economic Community (EEC) and later the European Union (EU) led to a significant reduction in internal tariffs. This integration promoted increased trade, efficiency gains, and overall economic growth.
  • East Asian Economies: Countries like South Korea and Taiwan, after initially protecting some nascent industries, gradually reduced tariffs and opened up to international trade. This transition was accompanied by rapid industrialization, technological transfer, and export-led growth, which propelled them to high levels of economic development.

Model Overview and Starting Assumptions

In this post, we explore a simplified simulation model that uses a dynamic, game‐theoretic approach to analyze trade interactions between the United States and its major trading partners. Our model combines elements of the classic prisoner’s dilemma. The prisoner's dilemma is a classic game theory scenario where two players must independently choose to cooperate or defect without knowing what the other will do. If both cooperate, they receive a moderate benefit; if one defects while the other cooperates, the defector gains a high benefit while the cooperator gets little or nothing; and if both defect, both end up worse off than if they had cooperated.

This model is useful for understanding trade wars because countries face a similar decision. When two nations decide whether to impose tariffs (defect) or maintain free trade (cooperate), both can benefit from mutual cooperation. However, the temptation to impose tariffs in hopes of gaining short-term advantage can lead to retaliatory measures (counter tariffs) and a trade war, ultimately harming both economies. Thus, the prisoner's dilemma captures the inherent conflict between short-term self-interest and long-term mutual benefit in trade policies.

US Trading Partners in Tariff WarThe simulation focuses on five key trading partners of the US. The baseline bilateral trade data (in billions of dollars) between the US and a partner is defined as follows:

const trade_data = Dict( 
    "Canada" => TradeData(250.0, 300.0),
    "Mexico" => TradeData(200.0, 350.0),
    "China" => TradeData(130.0, 450.0),
    "Japan" => TradeData(60.0, 140.0),
    "European Union" => TradeData(376.0, 545.0)
)
  

In this example, the US exports 250 billion dollars to Canada while importing 300 billion dollars. Similar trade figures are provided for Mexico, China, Japan, and the European Union.

Tariff Rate Assumptions

To model the uncertainty and variability of tariff policies, the simulation uses a triangular distribution for effective tariff rates:

tri_dist = TriangularDist(5.0, 50.0, 25.0)
  

This distribution is defined as a triangular distribution with a minimum of 5%, a maximum of 50%, and a most likely (mode) value of 25%. In each round, if a party defects (i.e. imposes tariffs), the effective tariff rate is randomly sampled from this distribution.The triangular distribution is especially useful in low-information settings because it allows us to incorporate expert judgment—by specifying a minimum, maximum, and most likely value—into the model. On the otherhand, if you are ot willing to make a guess at the most likely value,a uniform distribution assumes all outcomes are equally likely, it does not capture a preferred or most likely outcome, which can be critical in reflecting real-world scenarios.

GDP Data

The model also accounts for the economic size of each country by incorporating GDP data (in billions of dollars) from datacommons.org:

const gdp_data = Dict(
    "US" => 27700.0,
    "Canada" => 2200.0,
    "Mexico" => 1790.0,
    "China" => 17800.0,
    "Japan" => 4200.0,
    "European Union" => 18600.0
)
  

These figures help us translate the simulation's "payoffs" into impacts on each country's economy as a percentage of GDP.

Simulation Approach

At its core, our simulation models bilateral trade interactions as a repeated game resembling the prisoner’s dilemma. For example in this round, you can see the previous strategy and how each party decided to act given past decisions:

--- Round 4 --- Partner: Mexico Previous actions: US = cooperate, Mexico = cooperate Chosen strategies: US -> cooperate, Mexico -> cooperate Effective tariff rates this round: US faces 0.0% from Mexico, Mexico faces 0.0% from US Round payoff: US = 10.5, Mexico = 10.5 Cumulative totals for Mexico: US = 38.5, Mexico = 38.5 Partner: China Previous actions: US = defect, China = cooperate Chosen strategies: US -> cooperate, China -> cooperate Effective tariff rates this round: US faces 0.0% from China, China faces 0.0% from US Round payoff: US = 13.5, China = 13.5 Cumulative totals for China: US = 58.5, China = 36.0 Partner: European Union Previous actions: US = cooperate, European Union = defect Chosen strategies: US -> defect, European Union -> cooperate Effective tariff rates this round: US faces 0.0% from European Union, European Union faces 43.79% from US Round payoff: US = 27.25, European Union = 0.0 Cumulative totals for European Union: US = 70.85, European Union = 43.6 Partner: Canada Previous actions: US = defect, Canada = cooperate Chosen strategies: US -> cooperate, Canada -> cooperate Effective tariff rates this round: US faces 0.0% from Canada, Canada faces 0.0% from US Round payoff: US = 9.0, Canada = 9.0 Cumulative totals for Canada: US = 42.0, Canada = 27.0 Partner: Japan Previous actions: US = defect, Japan = cooperate Chosen strategies: US -> cooperate, Japan -> defect Effective tariff rates this round: US faces 28.38% from Japan, Japan faces 0.0% from US Round payoff: US = 0.0, Japan = 7.0 Cumulative totals for Japan: US = 15.4, Japan = 15.4

After running five rounds, each round accounting for the previous action, we obtain the following outcomes.

After 5 rounds (with normalization factor = 100.0):
Overall US cumulative payoff (normalized, 'billion-dollar units'): 208.1

US cumulative payoff by country:
- Mexico: 49.0
- China: 36.0
- European Union: 76.3
- Canada: 30.0
- Japan: 16.8
Total US cumulative payoff (sum over all partners): 208.1

Partner cumulative payoff:
- Mexico: 31.5
- China: 58.5
- European Union: 49.05
- Canada: 45.0
- Japan: 9.8
Total partner cumulative payoff (sum over all partners): 193.85

Estimated percentage impact on GDP per country:
- US impact (with Mexico): 0.1769% of US GDP
- Mexico impact (with US): 1.7598% of Mexico GDP
- US impact (with China): 0.13% of US GDP
- China impact (with US): 0.3287% of China GDP
- US impact (with European Union): 0.2755% of US GDP
- European Union impact (with US): 0.2637% of European Union GDP
- US impact (with Canada): 0.1083% of US GDP
- Canada impact (with US): 2.0455% of Canada GDP
- US impact (with Japan): 0.0606% of US GDP
- Japan impact (with US): 0.2333% of Japan GDP

Total US impact across all partners: 0.7513% of US GDP

Average effective tariff rates per round:
- US facing Mexico: 13.66% per round on average
- Mexico facing US: 14.74% per round on average
- US facing China: 14.07% per round on average
- China facing US: 10.8% per round on average
- US facing European Union: 10.43% per round on average
- European Union facing US: 20.13% per round on average
- US facing Canada: 20.26% per round on average
- Canada facing US: 11.22% per round on average
- US facing Japan: 17.7% per round on average
- Japan facing US: 22.33% per round on average

julia>

  • Strategy Choice: Both the US and its partner choose between cooperating (no tariffs) or defecting (imposing tariffs). The decision is influenced by the opponent’s previous action. For example, if the opponent defected in the last round, there is an 80% chance to retaliate with defection; if they cooperated, there is only a 20% chance of defection.
  • Payoff Calculation: Payoffs are computed based on a simple payoff matrix: mutual cooperation yields 3x the normalized trade volume; defection when the opponent cooperates yields 5x; and mutual defection results in 1x. The trade volume is normalized by dividing by 100, so the raw trade data remains comparable to GDP.
  • Tariff Application: When a party defects, a tariff rate is sampled from the triangular distribution defined above. These effective tariffs are accumulated over simulation rounds to compute average tariff rates.
  • Economic Impact: The cumulative payoffs are interpreted as economic gains or losses. Dividing these by the country's GDP gives us an estimate of the impact on the overall economy.

Simulation Results

Now let's take this to the next level by simulating 5 tariff rounds for all 5 trading blocks 1000 times using Monte Carlo simulation. We obtained the following summary statistics for key US metrics:

Overall US Cumulative Payoff

  • Mean: 223.75 (normalized billion-dollar units)
  • Median: 225.20
  • Minimum: 129.35
  • Maximum: 291.50

These figures represent the aggregated payoff the US receives from all bilateral interactions over the simulation period.

Simulation of US Payoff using Julia 

Simulation: CDF of US Payoff using Julia 

Overall US Average Tariff Rate

  • Mean: 9.56%
  • Median: 9.31%
  • Minimum: 0.00%
  • Maximum: 22.27%

This metric is the average effective tariff rate the US faces across all its trading partners.

Simulation: PDF of US Average Tariff sing Julia 

Simulation: CDF of US Average Tariffusing Julia 

Overall US Impact on GDP

  • Mean: 0.81%
  • Median: 0.81%
  • Minimum: 0.47%
  • Maximum: 1.05%

The overall impact on US GDP is calculated by comparing the cumulative payoff to the US GDP (27,700 billion dollars), indicating a modest short-term effect.

Simulation: PDF of US GDP Impact using Julia 

Simulation: CDF of US GDP Impact using Julia 

Discussion and Limitations

Although our simulation indicates that imposing tariffs might yield short-term gains for the US, several limitations must be considered:

Simplistic Assumptions:
The model uses a basic payoff matrix and a probability-based strategy selection mechanism that simplifies decision-making into binary outcomes (cooperate or defect). In the real world, trade dynamics are influenced by many more factors. Supply chain integration, regulatory frameworks, political pressures, and long-term strategic shifts all play critical roles. For example, a country might choose to impose tariffs not only for immediate protection but also to achieve longer-term geopolitical objectives. Such complexities are not captured by our simplified model, meaning that while the simulation can offer insights into short-term behaviors, it does not fully reflect the multifaceted nature of international trade.

Market Substitution Effects:
Our simulation assumes that if tariffs are imposed, the trade relationships remain constant. However, in practice, when tariffs make certain goods more expensive, trading partners often respond by finding alternative markets or suppliers. This market substitution can significantly alter trade flows over time. For instance, if the US imposes tariffs on steel imports, its trading partners may pivot to selling that steel to other countries or investing in domestic production alternatives. The model’s failure to account for these substitution effects means it likely underestimates the long-term negative impacts of a trade war—loss of market share and the erosion of established trade relationships can lead to more severe economic consequences than the short-term gains would suggest.

Static Trade Data:
In our simulation, the baseline trade figures and GDP data are fixed inputs. This static approach does not reflect the dynamic nature of real economies, where trade volumes, market shares, and GDP figures evolve over time in response to technological innovations, policy changes, and shifting consumer preferences. Over a prolonged period, these evolving factors can dramatically alter the balance of trade, meaning that a model based on static data may not accurately predict long-term outcomes.

Short-Term Focus:
Finally, the simulation captures a snapshot of interactions over a limited number of rounds. This short-term focus may reveal immediate benefits from imposing tariffs, such as increased revenue or temporary protection for domestic industries. However, it neglects the long-term consequences that can accumulate over time. Long-term outcomes might include lost markets, reduced global competitiveness, and the costly need to reconfigure supply chains. These effects are typically much more damaging than the initial gains observed in a short-term scenario.

In summary, while the simulation offers a valuable framework for understanding the immediate trade-offs in a tariff war, its simplistic assumptions, lack of market substitution dynamics, static data inputs, and short-term focus mean that the long-term consequences could be far more severe than the model suggests.

In conclusion...

Our dynamic trade war simulation offers a simplified framework to understand the potential effects of tariff policies on bilateral trade and the broader economy. While short-term gains might appear to justify tariff impositions, our model suggests that the long-term impacts, especially when accounting for market substitution and lost trade opportunities, could be considerably more damaging.

Future work could expand on this model by incorporating adaptive strategies, dynamic trade and GDP data, and substitution effects to provide a more comprehensive picture of the long-term outcomes of trade wars.

This post serves as an initial exploration of trade war dynamics using a primitive simulation model, and further research is needed to fully capture the complex interactions in global trade.


Comments

Collapse Expand Comments (0)
You don't have permission to post comments.

Oracle Crystal Ball Spreadsheet Functions For Use in Microsoft Excel Models

Oracle Crystal Ball has a complete set of functions that allows a modeler to extract information from both inputs (assumptions) and outputs (forecast). Used the right way, these special Crystal Ball functions can enable a whole new level of analytics that can feed other models (or subcomponents of the major model).

Understanding these is a must for anybody who is looking to use the developer kit.

Why are analytics so important for the virtual organization? Read these quotes.

Jun 26 2013
6
0

Since the mid-1990s academics and business leaders have been striving to focus their businesses on what is profitable and either partnering or outsourcing the rest. I have assembled a long list of quotes that define what a virtual organization is and why it's different than conventional organizations. The point of looking at these quotes is to demonstrate that none of these models or definitions can adequately be achieved without some heavy analytics and integration of both IT (the wire, the boxes and now the cloud's virtual machines) and IS - Information Systems (Applications) with other stakeholder systems and processes. Up till recently it could be argued that these things can and could be done because we had the technology. But the reality is, unless you were an Amazon, e-Bay or Dell, most firms did not necessarily have the money or the know-how to invest in these types of inovations.

With the proliferation of cloud services, we are finding new and cheaper ways to do things that put these strategies in the reach of more managers and smaller organizations. Everything is game... even the phone system can be handled by the cloud. Ok, I digress, Check out the following quotes and imagine being able to pull these off without analytics.

The next posts will treat some of the tools and technologies that are available to make these business strategies viable.

Multi-Dimensional Portfolio Optimization with @RISK

Jun 28 2012
16
0

Many speak of organizational alignment, but how many tell you how to do it? Others present only the financial aspects of portfolio optimization but abstract from how this enables the organization to meets its business objectives.  We are going to present a practical method that enables organizations to quickly build and optimize a portfolio of initiatives based on multiple quantitative and qualitative dimensions: Revenue Potential, Value of Information, Financial & Operational Viability and Strategic Fit. 
                  
This webinar is going to present these approaches and how they can be combined to improve both tactical and strategic decision making. We will also cover how this approach can dramatically improve organizational focus and overall business performance.

We will discuss these topics as well as present practical models and applications using @RISK.

Reducing Project Costs and Risks with Oracle Primavera Risk Analysis

.It is a well-known fact that many projects fail to meet some or all of their objectives because some risks were either: underestimated, not quantified or unaccounted for. It is the objective of every project manager and risk analysis to ensure that the project that is delivered is the one that was expected. With the right know-how and the right tools, this can easily be achieved on projects of almost any size. We are going to present a quick primer on project risk analysis and how it can positively impact the bottom line. We are also going to show you how Primavera Risk Analysis can quickly identify risks and performance drivers that if managed correctly will enable organizations to meet or exceed project delivery expectations.

.

 

Modeling Time-Series Forecasts with @RISK


Making decisions for the future is becoming harder and harder because of the ever increasing sources and rate of uncertainty that can impact the final outcome of a project or investment. Several tools have proven instrumental in assisting managers and decision makers tackle this: Time Series Forecasting, Judgmental Forecasting and Simulation.  

This webinar is going to present these approaches and how they can be combined to improve both tactical and strategic decision making. We will also cover the role of analytics in the organization and how it has evolved over time to give participants strategies to mobilize analytics talent within the firm.  

We will discuss these topics as well as present practical models and applications using @RISK.

The Need for Speed: A performance comparison of Crystal Ball, ModelRisk, @RISK and Risk Solver


Need for SpeedA detailed comparison of the top Monte-Carlo Simulation Tools for Microsoft Excel

There are very few performance comparisons available when considering the acquisition of an Excel-based Monte Carlo solution. It is with this in mind and a bit of intellectual curiosity that we decided to evaluate Oracle Crystal Ball, Palisade @Risk, Vose ModelRisk and Frontline Risk Solver in terms of speed, accuracy and precision. We ran over 20 individual tests and 64 million trials to prepare comprehensive comparison of the top Monte-Carlo Tools.

 

Excel Simulation Show-Down Part 3: Correlating Distributions

Escel Simulation Showdown Part 3: Correlating DistributionsModeling in Excel or with any other tool for that matter is defined as the visual and/or mathematical representation of a set of relationships. Correlation is about defining the strength of a relationship. Between a model and correlation analysis, we are able to come much closer in replicating the true behavior and potential outcomes of the problem / question we are analyzing. Correlation is the bread and butter of any serious analyst seeking to analyze risk or gain insight into the future.

Given that correlation has such a big impact on the answers and analysis we are conducting, it therefore makes a lot of sense to cover how to apply correlation in the various simulation tools. Correlation is also a key tenement of time series forecasting…but that is another story.

In this article, we are going to build a simple correlated returns model using our usual suspects (Oracle Crystal Ball, Palisade @RISK , Vose ModelRisk and RiskSolver). The objective of the correlated returns model is to take into account the relationship (correlation) of how the selected asset classes move together. Does asset B go up or down when asset A goes up – and by how much? At the end of the day, correlating variables ensures your model will behave correctly and within the realm of the possible.

Copulas Vs. Correlation

Copulas and Rank Order Correlation are two ways to model and/or explain the dependence between 2 or more variables. Historically used in biology and epidemiology, copulas have gained acceptance and prominence in the financial services sector.

In this article we are going to untangle what correlation and copulas are and how they relate to each other. In order to prepare a summary overview, I had to read painfully dry material… but the results is a practical guide to understanding copulas and when you should consider them. I lay no claim to being a stats expert or mathematician… just a risk analysis professional. So my approach to this will be pragmatic. Tools used for the article and demo models are Oracle Crystal Ball 11.1.2.1. and ModelRisk Industrial 4.0

Excel Simulation Show-Down Part 2: Distribution Fitting

 

One of the cool things about professional Monte-Carlo Simulation tools is that they offer the ability to fit data. Fitting enables a modeler to condensate large data sets into representative distributions by estimating the parameters and shape of the data as well as suggest which distributions (using these estimated parameters) replicates the data set best.

Fitting data is a delicate and very math intensive process, especially when you get into larger data sets. As usual, the presence of automation has made us drop our guard on the seriousness of the process and the implications of a poorly executed fitting process/decision. The other consequence of automating distribution fitting is that the importance of sound judgment when validating and selecting fit recommendations (using the Goodness-of-fit statistics) is forsaken for blind trust in the results of a fitting tool.

Now that I have given you the caveat emptor regarding fitting, we are going to see how each tools offers the support for modelers to make the right decisions. For this reason, we have created a series of videos showing comparing how each tool is used to fit historical data to a model / spreadsheet. Our focus will be on :

The goal of this comparison is to see how each tool handles this critical modeling feature.  We have not concerned ourselves with the relative precision of fitting engines because that would lead us down a rabbit hole very quickly – particularly when you want to be empirically fair.

RESEARCH ARTICLES | RISK + CRYSTAL BALL + ANALYTICS