This project implements a novel data science approach combining Causal Inference and Meta-Reinforcement Learning (Meta-RL) to analyze highly non-stationary time series data.
The core goal is to move beyond simple prediction and achieve dynamic causal inference: measuring how the causal influence between market factors changes over time due to shifting market regimes (non-stationarity).
| Component | Role | Novelty |
|---|---|---|
| Causal Model | Vector Autoregression (VAR(2)) | Used to calculate the time-lagged causal scores (Granger Causality). |
| Learning Algorithm | Model-Agnostic Meta-Learning (MAML) | Meta-learns the optimal starting point ( |
| Key Output | Time-Varying Causal Coefficients | Provides empirical evidence of how market rules evolve across different historical periods. |
We use real-world daily financial data for Apple Inc. (AAPL) spanning over four decades (1980–2022). The raw data is transformed into three key time series variables (
| Variable | Symbol | Source/Calculation | Interpretation |
|---|---|---|---|
| Returns |
|
Log Return of Adjusted Close | Outcome: The percentage price change we seek to explain. |
| Volume |
|
Log of Trading Volume | Cause 1: Measures market activity/liquidity. |
| Volatility |
|
Log(High/Low) Range | Cause 2: Measures market risk/uncertainty. |
Financial markets are non-stationary; the effect of volume on price during a pre-internet market (1980s) is fundamentally different from a high-frequency trading market (2020s). A traditional model would fail by averaging these effects.
The entire 40-year time series is segmented into sequential Tasks (
-
Inner Loop (Adaptation): The VAR(2) model quickly adjusts its causal coefficients (
$\phi$ ) using a small Support Set of data from the current task, reflecting the current market rule. -
Outer Loop (Meta-Learning): The MAML algorithm optimizes the model's initialization (
$\Theta^*$ ) across all tasks, ensuring the model is always initialized to the most adaptable starting point for any future market shift.
The core finding is contained in the Causal Coefficient Matrix (
This matrix represents the Meta-Learned Master Strategy—the average week-to-week influence one variable has on another across the entire dataset.
| Coefficient | Value (Example) | Interpretation (Granger Causality) |
|---|---|---|
| +0.377 | STRONG POSITIVE CAUSAL SCORE: On average, higher trading volume last week significantly contributes to higher returns this week. | |
| -0.228 | NEGATIVE EFFECT: Past price increases lead to slight downward pressure (mean-reversion) this week. |
The causal_track_df.csv file contains the dynamic coefficients. By plotting these, we show the causal score for the
- Create Environment: Ensure you have Python and PyCharm/VS Code.
- Install Dependencies: Run the following command using the
requirements.txtfile:pip install -r requirements.txt
- Data Placement: Place your
AAPL.csvfile in the main project directory. - Training: Run the training script to optimize the MAML model and generate results. A fixed seed is used for reproducibility.
python maml_trainer.py
- Visualization: Launch the Streamlit dashboard to view the dynamic results.
streamlit run app_dashboard.py
The project successfully delivered a working MAML-VAR(2) framework that achieves stable meta-learning convergence on non-stationary financial data.
theta_star.pt: Saved optimized initial parameters.causal_track_df.csv: Time series data of the evolving causal coefficients.- Streamlit Dashboard: Interactive visualization of the dynamic causal scores, proving the existence of non-stationary causal regimes.
The Meta-RL Causal Inference framework developed here is highly generalizable and can be applied to other complex, evolving systems:
- Public Health: Tracking the time-varying effect of vaccination rates on disease transmission as the virus mutates.
- Climate Science: Inferring the evolving causal relationship between greenhouse gas concentrations and extreme weather events.
- Policy Economics: Measuring how the effectiveness of a fiscal stimulus policy changes as consumers and markets adapt over time.