Close Menu
    Trending
    • Cuba’s Energy Crisis: A Systemic Breakdown
    • AI Startup TML From Ex-OpenAI Exec Mira Murati Pays $500,000
    • STOP Building Useless ML Projects – What Actually Works
    • Credit Risk Scoring for BNPL Customers at Bati Bank | by Sumeya sirmula | Jul, 2025
    • The New Career Crisis: AI Is Breaking the Entry-Level Path for Gen Z
    • Musk’s X appoints ‘king of virality’ in bid to boost growth
    • Why Entrepreneurs Should Stop Obsessing Over Growth
    • Implementing IBCS rules in Power BI
    AIBS News
    • Home
    • Artificial Intelligence
    • Machine Learning
    • AI Technology
    • Data Science
    • More
      • Technology
      • Business
    AIBS News
    Home»Machine Learning»Predicting the US — Mexico Currency Market with Mixture Density Networks | by Arturo Avalos | May, 2025
    Machine Learning

    Predicting the US — Mexico Currency Market with Mixture Density Networks | by Arturo Avalos | May, 2025

    Team_AIBS NewsBy Team_AIBS NewsMay 12, 2025No Comments10 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    Overseas alternate markets are notoriously unpredictable.

    Geopolitical tensions, oil value shocks, rate of interest shifts — a thousand shifting elements collide day-after-day to find out whether or not a foreign money strengthens or collapses.

    Conventional fashions typically attempt to predict a single quantity for tomorrow’s value.

    However monetary markets don’t work like that.

    Markets are unsure. Dangerous. Nonlinear.

    What we’d like isn’t only a level estimate — it’s a probabilistic understanding of what might occur subsequent.

    On this mission, I got down to reply a easy however profound query:

    Can deep studying not simply predict — however simulate — the long run paths of the USD/MXN alternate charge?

    To do that, I educated a Combination Density Community (MDN) — a particular kind of neural community designed to not predict a single consequence, however a full likelihood distribution over doable outcomes.

    As an alternative of claiming “the peso will transfer by +0.1% tomorrow,” the MDN says, “there’s a 30% probability it’s going to go up 0.1%, a 20% probability it’s going to drop 0.2%, a 50% probability it’s going to keep flat.”

    On this put up, I’ll stroll you thru:

    • How I gathered and engineered significant macroeconomic options,
    • How I educated a deep probabilistic mannequin on real-world information,
    • How I used the mannequin to simulate 1000’s of potential future paths,
    • And the way shut (or far!) these simulations had been from actuality.

    Alongside the best way, I’ll share classes I discovered about modeling uncertainty, capturing market habits, and the stunning energy of deep studying whenever you assume probabilistically — not deterministically.

    Able to dive into the stochastic way forward for foreign money markets?

    Let’s get began.

    Monetary markets thrive on uncertainty — however nowhere is that this extra apparent than in overseas alternate (FX).

    Currencies just like the Mexican Peso (MXN) and the US Greenback (USD) don’t transfer based mostly on a single power.

    Their costs shift each day based mostly on an entangled internet of things:

    • Rate of interest choices by central banks,
    • Oil value fluctuations,
    • Investor danger urge for food,
    • Inventory market sentiment,
    • Political occasions and financial bulletins.

    Whereas some fashions attempt to predict the following transfer by merely previous costs, the reality is messier.

    Returns are noisy, typically fat-tailed, and uneven.

    A easy neural community that tries to foretell “the following value” would seemingly overfit — capturing noise as an alternative of true sign.

    To essentially forecast FX habits, we’d like a mannequin that:

    • Understands that a number of outcomes are doable,
    • Can seize uncommon however impactful occasions (like foreign money crashes),
    • And produces not only a prediction, however a distribution of potentialities.

    That’s the place Combination Density Networks (MDNs) are available in.

    A Combination Density Community flips the usual deep studying strategy on its head.

    As an alternative of outputting a single prediction like:

    “Tomorrow’s return = +0.12%”

    an MDN outputs:

    “There’s a 30% probability of +0.1%, a 20% probability of -0.2%, and a 50% probability of hovering round zero.”

    It fashions outcomes as a combination of Gaussians (therefore the identify):

    • Every Gaussian represents a doable situation (average achieve, sharp loss, flat market, and so on).
    • The mannequin learns to foretell how seemingly every situation is.

    This probabilistic view isn’t simply mathematically elegant — it’s way more real looking for monetary markets, the place no single future is assured.

    To make this concept work, I wanted information — and never simply value information.

    I engineered a dataset that blended collectively:

    • USD/MXN Alternate Charge each day open, excessive, low, and shut costs,
    • 2-12 months Bond Spreads for short-term charge divergence,
    • WTI Crude Oil Costs — given Mexico’s dependence on oil exports,
    • S&P 500 Closing Costs — as a measure of world danger urge for food,
    • BMV IPC Index (Mexican inventory market) — for native financial sentiment,
    • VIX Index — the so-called “concern gauge” of the market.

    Every day within the dataset was thus represented by a wealthy tapestry of macroeconomic indicators — not simply yesterday’s FX return, however the state of the world round it.

    I began easy.

    At first, I educated my Combination Density Community utilizing solely the previous 10 days of alternate charge returns.

    The thought was to see whether or not latest momentum alone might predict future actions — no oil costs, no bonds, no inventory indices.

    The mannequin structure was comparatively easy:

    • 3 hidden layers,
    • 256 hidden items,
    • 5 Gaussian parts (mixtures),
    • Normal MDN loss (adverse log-likelihood).
    class MDN(nn.Module):
    def __init__(self, input_dim, hidden_dim, num_mixtures):
    tremendous(MDN, self).__init__()
    self.num_mixtures = num_mixtures

    self.internet = nn.Sequential(
    nn.Linear(input_dim, hidden_dim),
    nn.BatchNorm1d(hidden_dim),
    nn.ReLU(),
    nn.Dropout(0.2),
    nn.Linear(hidden_dim, hidden_dim),
    nn.BatchNorm1d(hidden_dim),
    nn.ReLU(),
    nn.Dropout(0.2),
    nn.Linear(hidden_dim, hidden_dim),
    nn.BatchNorm1d(hidden_dim),
    nn.ReLU(),
    )

    self.pi_layer = nn.Linear(hidden_dim, num_mixtures)
    self.sigma_layer = nn.Linear(hidden_dim, num_mixtures)
    self.mu_layer = nn.Linear(hidden_dim, num_mixtures)

    def ahead(self, x):
    x = self.internet(x)
    pi = F.softmax(self.pi_layer(x), dim=1)
    sigma = torch.exp(self.sigma_layer(x)) + 1e-6
    mu = self.mu_layer(x)
    return pi, sigma, mu

    Coaching went easily — the mannequin shortly discovered a tough understanding of return habits.

    However after I examined it by producing future return paths, it turned clear:

    • The normal volatility was there,
    • Main crashes and sudden spikes had been typically underestimated,
    • Tail dangers (excessive outcomes) weren’t absolutely captured.

    Even after simulating 1000 doable future paths, the bottom fact returns typically fell exterior the mannequin’s predicted unfold.

    Lesson:

    Previous returns alone don’t inform the entire story in FX markets.

    We would have liked to offer the mannequin a richer understanding of the financial context.

    The subsequent logical step was to feed the mannequin higher info — not simply extra information, however higher information.

    I expanded the enter to incorporate:

    • 10-day home windows of oil costs,
    • 2-year bond yield spreads between Mexico and the US,
    • S&P 500 and BMV IPC inventory index closings,
    • VIX index ranges (international concern sentiment).

    Every day’s enter vector exploded from simply 10 numbers (returns) to 60 numbers — a full historic snapshot of market circumstances.

    I additionally upgraded the MDN itself:

    • Elevated hidden items to 512,
    • Added a fourth hidden layer,
    • Expanded the variety of Gaussian mixtures to 7,
    • Dropped the training charge for finer convergence.
    class UpgradedMDN(nn.Module):
    def __init__(self, input_dim, hidden_dim, num_mixtures):
    tremendous(UpgradedMDN, self).__init__()
    self.num_mixtures = num_mixtures

    self.internet = nn.Sequential(
    nn.Linear(input_dim, hidden_dim),
    nn.BatchNorm1d(hidden_dim),
    nn.ReLU(),
    nn.Dropout(0.2),
    nn.Linear(hidden_dim, hidden_dim),
    nn.BatchNorm1d(hidden_dim),
    nn.ReLU(),
    nn.Dropout(0.2),
    nn.Linear(hidden_dim, hidden_dim),
    nn.BatchNorm1d(hidden_dim),
    nn.ReLU(),
    nn.Dropout(0.2), # ADDITIONAL LAYER
    nn.Linear(hidden_dim, hidden_dim),
    nn.BatchNorm1d(hidden_dim),
    nn.ReLU()
    )

    self.pi_layer = nn.Linear(hidden_dim, num_mixtures)
    self.sigma_layer = nn.Linear(hidden_dim, num_mixtures)
    self.mu_layer = nn.Linear(hidden_dim, num_mixtures)

    def ahead(self, x):
    x = self.internet(x)
    pi = nn.practical.softmax(self.pi_layer(x), dim=1)
    sigma = torch.exp(self.sigma_layer(x)) + 1e-6
    mu = self.mu_layer(x)
    return pi, sigma, mu

    The outcomes had been instant and dramatic:

    • MSE dropped by 17%.
    • MAE dropped by 21%.
    • Floor fact returns fell throughout the simulated unfold extra regularly.
    • Excessive actions had been captured higher — each beneficial properties and sharp losses.

    Now, the mannequin didn’t simply know the way the Peso had moved yesterday — it felt the ripples of oil costs, rate of interest divergences, and market concern flowing by way of the foreign money markets.

    As soon as the upgraded MDN was educated, it was time for the enjoyable half:

    Simulation.

    In contrast to conventional fashions that spit out a single predicted quantity,

    an MDN enables you to pattern from the likelihood distribution it predicts at every timestep.

    Right here’s how I used it:

    • Begin with the final identified 10-day window of returns and macroeconomic options,
    • At every future day, pattern a random consequence from the mannequin’s combination distribution,
    • Replace the function window (pushing the newly sampled return ahead),
    • Repeat for 30 days into the long run,
    • Repeat the entire course of 1000 occasions to generate 1000 doable future paths.

    The consequence?

    A cloud of doable futures, each barely totally different — some optimistic, some catastrophic, most someplace in between.

    Visually, it appeared one thing like this:

    Every grey line represents a special doable future.

    The unfold widens over time — uncertainty accumulates, simply because it does in actual monetary markets.

    In fact, producing fairly simulations is one factor.

    The actual take a look at is: how shut had been they to what really occurred?

    I in contrast the simulated future paths towards the precise USD/MXN returns over the following 26 days.

    I didn’t simply eyeball it — I measured it rigorously:

    • MSE (Imply Squared Error) between simulated imply and precise returns,
    • MAE (Imply Absolute Error) to seize typical deviation,
    • Quantile Evaluation: for every day, I measured the place the actual return fell throughout the simulated distribution.

    Right here’s what I discovered:

    Mannequin Analysis Metrics:

    • Imply Squared Error (MSE): 0.1196
    • Imply Absolute Error (MAE): 0.1734
    • Median Quantile: 0.386
    • Proportion inside 90% Confidence Interval: 65.4%

    And visually:

    Some days, the actual return hugged the middle of the simulated unfold.

    Different days, it danced close to the perimeters — exhibiting that even with higher macro inputs, markets are inherently wild and messy.

    However general, the mannequin captured each the volatility and the fat-tailed nature of foreign money returns higher than any easy mannequin might have.

    • The mannequin realistically captured the vary of outcomes, not simply the middle.
    • Fats tails (excessive occasions) had been higher represented after the improve.
    • Uncertainty elevated over time, mimicking real-world monetary habits.

    In a world obsessive about level forecasts,

    this mission jogged my memory that modeling distributions — not simply predictions — is the way you survive the chaos of

    This mission began with a easy purpose:

    Predict the place the peso-dollar alternate charge would possibly go subsequent.

    However alongside the best way, it turned one thing a lot deeper.

    I discovered that:

    When folks consider neural networks, they typically think about a single output:

    “Tomorrow’s value can be 18.37 MXN.”

    However Combination Density Networks (MDNs) taught me that deep studying can do extra:

    • Mannequin complete likelihood distributions, not simply averages.
    • Acknowledge that a number of futures are doable.
    • Quantify uncertainty — one thing conventional ML typically ignores.

    This mindset shift was big:

    I wasn’t simply predicting — I used to be modeling risk.

    Even in deep studying, information is king.

    When the mannequin was educated solely on previous returns, it struggled to seize sudden crashes or booms.

    As soon as I added macroeconomic options — oil costs, bond spreads, inventory indices — the mannequin felt the market higher.

    Lesson:

    Extra information isn’t higher. Higher information is best.

    Selecting economically significant alerts made all of the distinction.

    Regardless of all of the enhancements, my mannequin nonetheless sometimes missed excessive strikes.

    Generally the real-world return would slip exterior even the 90% simulation envelope.

    That’s okay.

    Monetary markets have a means of unusual even the most effective fashions.

    The purpose isn’t to completely predict each crash or rally —

    it’s to construct fashions that respect uncertainty, anticipate danger, and put together for surprises.

    In that sense, this MDN mission wasn’t nearly forecasting pesos and {dollars}.

    It was about constructing humility into machine studying —

    acknowledging what we will mannequin, and what we will’t.

    Predicting monetary markets is usually framed as a recreation of precision —

    Who can guess tomorrow’s value most precisely?

    However this mission taught me one thing extra vital:

    The actual talent isn’t in predicting the long run. It’s in making ready for its uncertainty.

    By constructing a Combination Density Community to simulate doable futures for the USD/MXN alternate charge,

    I wasn’t simply guessing.

    I used to be mapping potentialities — and accepting that volatility, surprises, and fat-tailed occasions are the rule, not the exception.

    In fact, there’s at all times extra work to do.

    If I had been to proceed constructing on this mission, I might discover:

    • Including exterior occasion indicators (Fed conferences, elections, oil provide shocks) to higher predict regime shifts,
    • Experimenting with different probabilistic fashions like Normalizing Flows or Variational Autoencoders,
    • Modeling volatility itself as a separate goal,
    • Constructing a danger administration dashboard based mostly on the simulation outputs — together with Worth at Danger (VaR) estimates and confidence bands.

    In a world that more and more leans on machine studying for monetary decision-making,

    there’s one thing refreshing a few mannequin that admits:

    “I don’t know precisely what is going to occur — however listed here are the probabilities. Right here’s the chance. Right here’s the uncertainty.”

    And typically, understanding what you don’t know is probably the most highly effective prediction of all.

    In the event you loved this put up, be at liberty to:

    • Join with me on LinkedIn ,
    • Observe me for future posts on machine studying, finance, and uncertainty modeling,
    • Or share your personal ideas — I’d love to listen to the way you assume we will higher mannequin real-world dangers.

    Till subsequent time — maintain embracing the uncertainty. 🚀



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleA manager’s guide to helping grieving employees
    Next Article Trump abruptly stopped paying farmers to feed in-need Californians—so they fought back
    Team_AIBS News
    • Website

    Related Posts

    Machine Learning

    Credit Risk Scoring for BNPL Customers at Bati Bank | by Sumeya sirmula | Jul, 2025

    July 1, 2025
    Machine Learning

    Why PDF Extraction Still Feels LikeHack

    July 1, 2025
    Machine Learning

    🚗 Predicting Car Purchase Amounts with Neural Networks in Keras (with Code & Dataset) | by Smruti Ranjan Nayak | Jul, 2025

    July 1, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Cuba’s Energy Crisis: A Systemic Breakdown

    July 1, 2025

    I Tried Buying a Car Through Amazon: Here Are the Pros, Cons

    December 10, 2024

    Amazon and eBay to pay ‘fair share’ for e-waste recycling

    December 10, 2024

    Artificial Intelligence Concerns & Predictions For 2025

    December 10, 2024

    Barbara Corcoran: Entrepreneurs Must ‘Embrace Change’

    December 10, 2024
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    Most Popular

    Meet H. Stan Thompson, the Man Who Coined the Term “Hydrail”

    December 28, 2024

    I Scaled a 500-Person Company on Hustle — But Wellness Made It Sustainable (and More Profitable)

    June 4, 2025

    How AI and Machine Learning Are Revolutionizing Video Streaming Platforms | by Fathima Parvin | Feb, 2025

    February 26, 2025
    Our Picks

    Cuba’s Energy Crisis: A Systemic Breakdown

    July 1, 2025

    AI Startup TML From Ex-OpenAI Exec Mira Murati Pays $500,000

    July 1, 2025

    STOP Building Useless ML Projects – What Actually Works

    July 1, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2024 Aibsnews.comAll Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.