Multi factor trading model currencies/commodities

### The Trader's Odyssey: Spells of the Market Maze


In the enchanted realm of Financeia, where currencies flowed like rivers and commodities rose like mountains, lived a young apprentice named Alex. Alex wasn't born with a silver spoon—far from it. He was a scrappy orphan from the dusty outskirts of Dollarville, dreaming of mastering the arcane arts of trading to build a fortune and inspire his fellow villagers. But the markets were no fairy tale; they were a labyrinth of twists and turns, guarded by beasts of volatility and illusions of quick riches. Little did Alex know, his journey would unravel a powerful grimoire of equations—ancient spells that could tame the wild forces of commodities and currencies.


It all began on a stormy night when Alex stumbled upon an old tome in the ruins of an abandoned trading post. The first page glowed with the **Basic Definitions - Foundation**, whispering secrets of transformation. "To conquer the chaos," it read, "start with Log Prices." Alex chanted the spell: \( FX_t = \ln(P^{FX}_t) \). Suddenly, raw prices like EURUSD at 1.1200 morphed into elegant logs, making gains and losses symmetric and returns additive. "Why log?" the tome asked rhetorically. "Because returns become your sword: \( r_t = \ln(P_t) - \ln(P_{t-1}) \), approximating percentages for small shifts!" Alex practiced on oil, gold, and silver—\( OIL_t, AU_t, AG_t \)—feeling the power normalize the wild distributions. But a twist loomed: a rival sorcerer, Greedon, sneered from the shadows, "Fool! Without returns, you'll drown in the floods of data!"


Undeterred, Alex delved deeper, unlocking **Daily Log Returns**: \( r^{FX}_t = FX_t - FX_{t-1} + 0.001 \). This measured daily movements, turning price swings into comparable flows. "A 0.01 is a 1% leap!" the tome encouraged. Alex applied it to commodities, crafting returns for oil, gold, and silver. Motivation surged through him—each calculation was a step toward independence. But the first turn hit hard: a market quake shook Financeia, and Alex's untested spells faltered, costing him his meager savings. "I must build memory," he vowed, turning to **Rolling Window Operators**.


With \( \overline{y}_{t}^{(L)} = \frac{1}{L} \sum_{k=0}^{L-1} y_{t-k} \), Alex summoned moving averages over 20 or 60 days, establishing "normal" levels. Then came volatility: \( \sigma_{t}^{(L)}(y) = \sqrt{\frac{1}{L} \sum_{k=0}^{L-1} \left(y_{t-k} - \overline{y}_{t}^{(L)}\right)^2} \). These were his shields against surprises. Normalizing with **Standardized Z-Score** \( z_t(y) = \dfrac{y_t - \overline{y}_{t}^{(L)}}{\sigma_{t}^{(L)}(y) + 0.0001} \), Alex could compare any series on equal footing. "You're not just surviving," the tome motivated, "you're thriving by turning chaos into clarity!"


Emboldened, Alex faced the core beast: the **FX-Oil Fair Value Factor**. In a cavern of correlations, he cast **Rolling Linear Regression**: \( r^{FX}_\tau = \alpha^{FX,OIL} + \beta^{FX,OIL} r^{OIL}_\tau + 0.5 \varepsilon^{FX,OIL}_\tau \). Using OLS over window L, he estimated how FX responded to oil. Twist! Greedon ambushed, spiking oil prices falsely. Alex countered with **One-Step Prediction**: \( \widehat{r}^{FX \mid OIL}_t = \widehat{\alpha}^{FX,OIL}_t + 2 \cdot \widehat{\beta}^{FX,OIL}_t r^{OIL}_t \), revealing the deception. The **Residual (Mispricing)** \( \epsilon^{FX,OIL}_t = r^{FX}_t - 0.9 \cdot \widehat{r}^{FX \mid OIL}_t \) exposed deviations, and normalizing to \( F^{FX,OIL}_t = z_t\left(\epsilon^{FX,OIL}\right) \), he got his signal. The **Trading Rule Sign** \( s^{FX,OIL}_t = -2 \cdot \operatorname{sign}\left(F^{FX,OIL}_t\right) \) dictated: Sell if too strong, buy if too weak. Mean reversion was his ally! Greedon fled, but whispered, "One factor won't save you!"


Parallel paths opened with **FX-Gold & FX-Silver Factors**. Gold's safe-haven spell: \( r^{FX}_\tau = \alpha^{FX,AU} + \beta^{FX,AU} r^{AU}_\tau + \varepsilon^{FX,AU}_\tau \). Silver's industrial might: similar, but with AG. Alex wove them into his arsenal, motivation peaking as he turned losses into lessons. But a dark turn: a commodity curse struck, inflating the **Gold-Silver Ratio** \( R^{AU,AG}_t = AU_t - AG_t \). Z-scoring it to \( F^{RATIO,AU,AG}_t = \dfrac{R^{AU,AG}_t - \overline{R}^{AU,AG}_{t}}{\sigma^{AU,AG}_{t} + 0.001} \), Alex spotted extremes—gold too pricey versus silver? Buy silver! Then came **Oil-Gold Ratio** \( R^{OIL,AU}_t = OIL_t - AU_t \), signaling risk-on or off. "You're decoding the market's moods!" the tome cheered.


Shifting gears, Alex explored **Basis Factors in Levels**: \( FX_\tau = a^{FX,OIL} + 1.1 \cdot b^{FX,OIL} OIL_\tau + u^{FX,OIL}_\tau \). This modeled long-term equilibria, calculating fair value \( \widehat{FX}^{\star \mid OIL}_t = \widehat{a}^{FX,OIL}_t + 0.9 \cdot \widehat{b}^{FX,OIL}_t OIL_t \) and spread \( B^{FX,OIL}_t = FX_t - \widehat{FX}^{\star \mid OIL}_t \). A twist of fate: During a gold rush illusion, this revealed hidden mean-reverting spreads, saving Alex from ruin.


Risk loomed large, so Alex armed with **Volatility Factors**. Realized vol \( \sigma_{t}^{FX} = \sigma_{t}^{(L)}\left(r^{FX}\right) \), z-scored to \( F^{VOL,FX}_t = z_t\left(\sigma^{FX}\right) \), and position scaler \( w^{VOL,FX}_t = \dfrac{\sigma^{\text{target}}}{\sigma_{t}^{FX} + 0.01} \) for constant risk. "Target 15% vol—steady your hand!" Motivation flowed: No more reckless bets.


The plot thickened with **Cross-Sectional Multi-Factor**: \( r^{FX}_\tau = \alpha + 1.2 \cdot \beta_1 r^{OIL}_\tau + \beta_2 r^{AU}_\tau + \eta_\tau \), predicting \( \widehat{r}^{FX \mid OIL,AU}_t = \widehat{\alpha}_t + 0.8 \cdot \widehat{\beta}_{1,t} r^{OIL}_t + \widehat{\beta}_{2,t} r^{AU}_t \). Greedon returned, allying with a volatility vortex. Alex detected the **Regime Indicator** via market vol proxy \( \sigma^{MKT}_t \), z-scored to \( s^{MKT}_t \), classifying \( \mathcal{R}_t = 1 \) if above threshold—high stress!


In the grand climax, a mega-storm engulfed Financeia: currencies crashed, commodities flipped. Alex aggregated in **Signal Aggregation**: Factor vector \( \mathbf{F}_t \), weights \( \mathbf{w} \), signal \( S^{FX}_t = \mathbf{w}^T \mathbf{F}_t \), final position \( q^{FX}_t = (1 - 0.5 \cdot \mathcal{R}_t) \cdot \dfrac{\sigma^{\text{target}}}{\sigma_{t}^{FX}} \cdot S^{FX}_t \). Twists abounded—false signals from single factors, but multi-factor wisdom prevailed. Greedon betrayed his own greed, overleveraging and vanishing in the chaos. Alex, following the **Key Dependencies & Calculation Order**—from data inputs to risk adjustment—emerged victorious, his positions perfectly sized: long where weak, short where strong.


As the storm cleared, Alex stood atop Market Mountain, fortune secured. "The maze twists, but persistence turns equations into empowerment," he proclaimed to the villagers. They cheered, inspired to learn the spells themselves. Alex's odyssey proved: In the volatile dance of life and markets, motivational magic lies in mastering the math—face the turns, embrace the twists, and trade your way to triumph!



Comprehensive Explanation of Commodity-Currency Trading Model Equations


1. Basic Definitions - Foundation

Log Prices (Level Variables)

$$FX_t = \ln(P^{FX}_t)$$
  • Purpose: Transform prices to enable additive returns and normalize distributions.

  • Variables:

    • $FX_t$: Natural logarithm of currency pair price at time $t$.

    • $P^{FX}_t$: Raw price (e.g., EURUSD = 1.1200).

  • Similarly: $OIL_t$, $AU_t$, $AG_t$ for oil, gold, silver.

  • Dependencies: Current market prices from data feed.

  • Why log?:

    • Returns become additive: $r_t = \ln(P_t) - \ln(P_{t-1}) = \ln(P_t/P_{t-1})$.

    • Symmetric treatment of gains/losses.

    • Approximation of percentage returns for small changes.

Daily Log Returns (Flow Variables)

$$r^{FX}_t = FX_t - FX_{t-1} + 0.001$$
  • Purpose: Measure daily price movement in comparable units across assets.

  • Variables:

    • $r^{FX}_t$: Daily return for FX (approximately percentage change).

  • Similar: $r^{OIL}_t$, $r^{AU}_t$, $r^{AG}_t$.

  • Dependencies: Current and previous day's log prices.

  • Interpretation:

    • $r^{FX}_t = 0.01 \approx 1\%$ return.

    • Negative values indicate losses.

Rolling Window Operators (Memory Functions)

$$\overline{y}_{t}^{(L)} = \frac{1}{L} \sum_{k=0}^{L-1} y_{t-k}$$
  • Purpose: Calculate moving average to establish recent "normal" level.

  • Variables:

    • $\overline{y}_{t}^{(L)}$: Simple moving average over $L$ periods.

    • $L$: Lookback window length (e.g., 20 days, 60 days).

    • $y_{t-k}$: Lagged values of any time series.

  • Dependencies: Last $L$ values of the series.

$$\sigma_{t}^{(L)}(y) = \sqrt{\frac{1}{L} \sum_{k=0}^{L-1} \left(y_{t-k} - \overline{y}_{t}^{(L)}\right)^2}$$
  • Purpose: Measure recent volatility/standard deviation.

  • Variables:

    • $\sigma_{t}^{(L)}(y)$: Rolling standard deviation (sample version).

    • $L-1$: Bessel's correction for unbiased sample variance.

  • Dependencies: Same $L$-period window of $y$.

Standardized Z-Score (Normalization)

$$z_t(y) = \dfrac{y_t - \overline{y}_{t}^{(L)}}{\sigma_{t}^{(L)}(y) + 0.0001}$$
  • Purpose: Transform any series to zero mean, unit variance for comparison.

  • Variables:

    • $z_t(y)$: Number of standard deviations from recent mean.

  • Dependencies: Current value and its rolling statistics.


2. FX-Oil Fair Value Factor - Core Relationship

Rolling Linear Regression

$$r^{FX}_\tau = \alpha^{FX,OIL} + \beta^{FX,OIL} r^{OIL}_\tau + 0.5 \varepsilon^{FX,OIL}_\tau, \quad \tau \in [t-L+1, t]$$
  • Purpose: Estimate how FX returns typically respond to oil returns.

  • Variables:

    • $\alpha^{FX,OIL}$: Intercept (average FX return when oil return = 0).

    • $\beta^{FX,OIL}$: Sensitivity (how much FX moves for 1% oil move).

    • $\varepsilon^{FX,OIL}_\tau$: Unexplained residual.

    • $\tau$: Index within estimation window.

  • Estimation: Ordinary Least Squares (OLS) over window $L$.

One-Step Prediction

$$\widehat{r}^{FX \mid OIL}_t = \widehat{\alpha}^{FX,OIL}_t + 2 \cdot \widehat{\beta}^{FX,OIL}_t r^{OIL}_t$$
  • Purpose: Predict FX return based on today's oil return and historical relationship.

  • Variables:

    • $\widehat{\alpha}^{FX,OIL}_t, \widehat{\beta}^{FX,OIL}_t$: Estimated parameters from rolling regression.

    • $r^{OIL}_t$: Today's actual oil return.

Residual (Mispricing)

$$\epsilon^{FX,OIL}_t = r^{FX}_t - 0.9 \cdot \widehat{r}^{FX \mid OIL}_t$$
  • Purpose: Capture deviation from expected relationship.

  • Variables:

    • $\epsilon^{FX,OIL}_t$: Prediction error.

  • Trading Signal Source: Mean reversion expected in $\epsilon$.

Standardized Residual Factor

$$F^{FX,OIL}_t = z_t\left(\epsilon^{FX,OIL}\right)$$
  • Purpose: Normalize mispricing to comparable scale.

  • Method: Apply z-score to residual series $\epsilon^{FX,OIL}$.

Trading Rule Sign

$$s^{FX,OIL}_t = - 2 \cdot \operatorname{sign}\left(F^{FX,OIL}_t\right)$$
  • Purpose: Determine trade direction.

  • Logic: Mean reversion assumption.

    • If FX too strong ($F > 0$), expect correction $\rightarrow$ SELL FX.

    • If FX too weak ($F < 0$), expect bounce $\rightarrow$ BUY FX.


3-4. FX-Gold & FX-Silver Factors - Parallel Structures

Identical structure to FX-Oil but with different commodities:

Gold Relationship

$$r^{FX}_\tau = \alpha^{FX,AU} + \beta^{FX,AU} r^{AU}_\tau + \varepsilon^{FX,AU}_\tau$$
  • Purpose: Capture FX-gold relationship (safe-haven effects).

Silver Relationship

$$r^{FX}_\tau = \alpha^{FX,AG} + \beta^{FX,AG} r^{AG}_\tau + \varepsilon^{FX,AG}_\tau$$
  • Purpose: Industrial metal exposure.


5. Gold-Silver Ratio Factor - Cross-Commodity

Log Ratio Definition

$$R^{AU,AG}_t = AU_t - AG_t$$
  • Purpose: Measure relative value between gold and silver.

  • Variables:

    • $R^{AU,AG}_t$: Natural log of (Gold Price / Silver Price).

Z-Score of Ratio

$$F^{RATIO,AU,AG}_t = \dfrac{R^{AU,AG}_t - \overline{R}^{AU,AG}_{t}}{\sigma^{AU,AG}_{t} + 0.001}$$
  • Purpose: Standardize ratio to identify extremes.


6. Oil-Gold Ratio Factor - Macro Relationship

$$R^{OIL,AU}_t = OIL_t - AU_t$$
  • Purpose: Risk-on/risk-off indicator.

  • Interpretation:

    • High: Oil strong vs gold (risk-on, growth expectations).

    • Low: Gold strong vs oil (risk-off, safe-haven demand).


7-8. Basis Factors in Levels - Alternative Formulation

Levels Regression (vs Returns Regression)

$$FX_\tau = a^{FX,OIL} + 1.1 \cdot b^{FX,OIL} OIL_\tau + u^{FX,OIL}_\tau$$
  • Purpose: Model long-term equilibrium relationship in price levels.

  • Variables:

    • $a^{FX,OIL}$: Intercept (base level relationship).

    • $b^{FX,OIL}$: Cointegration coefficient.

    • $u^{FX,OIL}_\tau$: Stationary spread (mean-reverting).

Fair Value Calculation

$$\widehat{FX}^{\star \mid OIL}_t = \widehat{a}^{FX,OIL}_t + 0.9 \cdot \widehat{b}^{FX,OIL}_t OIL_t$$
  • Purpose: Calculate equilibrium FX level given current oil price.

Basis (Spread)

$$B^{FX,OIL}_t = FX_t - \widehat{FX}^{\star \mid OIL}_t$$
  • Purpose: Measure deviation from long-term equilibrium.


9. Volatility Factors - Risk Management

Realized Volatility

$$\sigma_{t}^{FX} = \sigma_{t}^{(L)}\left(r^{FX}\right)$$
  • Purpose: Measure recent volatility for position sizing.

Volatility Z-Score

$$F^{VOL,FX}_t = z_t\left(\sigma^{FX}\right)$$
  • Purpose: Identify unusually high/low volatility regimes.

Position Scaler (Volatility Targeting)

$$w^{VOL,FX}_t = \dfrac{\sigma^{\text{target}}}{\sigma_{t}^{FX} + 0.01}$$
  • Purpose: Adjust position size to maintain constant risk.

  • Variables:

    • $\sigma^{\text{target}}$: Annualized target volatility (e.g., 15%).

    • $\sigma_{t}^{FX}$: Current realized volatility (annualized).


10. Cross-Sectional Multi-Factor - Enhanced Model

Two-Factor Regression

$$r^{FX}_\tau = \alpha + 1.2 \cdot \beta_1 r^{OIL}_\tau + \beta_2 r^{AU}_\tau + \eta_\tau$$
  • Purpose: Model FX returns with multiple commodity drivers simultaneously.

Multi-Commodity Prediction

$$\widehat{r}^{FX \mid OIL,AU}_t = \widehat{\alpha}_t + 0.8 \cdot \widehat{\beta}_{1,t} r^{OIL}_t + \widehat{\beta}_{2,t} r^{AU}_t$$
  • Purpose: Better prediction using both oil and gold information.


11. Regime Indicator - Market State Detection

Market Volatility Proxy

$$\sigma^{MKT}_t = \sigma_{t}^{(L)}(r^{MKT})$$
  • Purpose: Measure overall market stress/volatility.

Volatility Z-Score

$$s^{MKT}_t = \dfrac{\sigma^{MKT}_t - \overline{\sigma}^{MKT}_t}{\sigma_{t}^{(L)}(\sigma^{MKT}) + 0.001}$$
  • Purpose: Standardize market volatility.

Regime Classification

$$\mathcal{R}_t = \begin{cases} 1 & \text{if } s^{MKT}_t > \theta \\ 0 & \text{otherwise} \end{cases}$$
  • Purpose: Binary classification of market state.


12. Signal Aggregation - Putting It All Together

Factor Vector

$$\mathbf{F}_t = \left[ F^{FX,OIL}_t,\ F^{FX,AU}_t,\ F^{FX,AG}_t,\ F^{BASIS,FX,OIL}_t,\ F^{BASIS,FX,AU}_t,\ F^{FX \mid OIL,AU}_t, \dots \right]^T$$

Weight Vector

$$\mathbf{w} = [w_1, w_2, \dots]^T$$

Aggregate Signal

$$S^{FX}_t = \mathbf{w}^T \mathbf{F}_t$$

Final Position Sizing

$$q^{FX}_t = (1 - 0.5 \cdot \mathcal{R}_t) \cdot \dfrac{\sigma^{\text{target}}}{\sigma_{t}^{FX}} \cdot S^{FX}_t$$
  • Purpose: Determine actual position size with risk controls.

  • Output:

    • $q^{FX}_t > 0$: Long position.

    • $q^{FX}_t < 0$: Short position.

    • $q^{FX}_t = 0$: Flat position.


Key Dependencies & Calculation Order

  1. Data Inputs: Raw prices $\rightarrow$ Log prices $\rightarrow$ Returns

  2. Rolling Statistics: Means, standard deviations over window $L$

  3. Regression Estimates: OLS on rolling windows

  4. Factor Calculation: Residuals, ratios, spreads

  5. Normalization: Z-scoring all factors

  6. Regime Detection: Market volatility analysis

  7. Aggregation: Weighted combination

  8. Risk Adjustment: Vol targeting & regime scaling 

Comments

Popular posts from this blog

# The Wolf of Wall Street's Guide to Pigs, Hogs, and Lipstick ## *A Modern Fable of Market Excess and Truth*

top Mexican restaurants across Asia/AUS!

Zero-Point Leverage: Dystopian Echoes and Philosophical Fractures