Skip to content

Latest commit

 

History

182 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Financial Market Analysis: U.S. Military Interventions Impact Study

Datastory Market Miners

Project Overview

This project presents an exploratory and causal analysis of financial market behavior in response to U.S. military interventions. We analyze NASDAQ historical stock data in combination with the Military Intervention (MI) Project dataset to evaluate how different sectors of the U.S. economy react before, during, and after major U.S. military campaigns throughout history.

Motivation

U.S. military interventions represent significant geopolitical and fiscal shocks that can influence investor sentiment, government spending, and sectoral market dynamics. This project aims to uncover causal relationships between these interventions and changes in U.S. financial markets — identifying which sectors benefit, which suffer, and how long these effects persist.

By integrating detailed intervention timelines with sector-level financial data, we apply hypothesis-driven statistical testing to determine whether wartime dynamics produce systematic, measurable impacts on market performance.

Research Questions

  1. How do U.S. military interventions influence stock returns and volatility across economic sectors?

  2. How do the objectives and geographic targets of interventions influence stock market reactions?

  3. How does the intensity of military interventions influence stock market reactions?

Data Sources

1. NASDAQ Stock Market Dataset (via Kaggle)

  • Content: Daily price data (Open, High, Low, Close, Adjusted Close, Volume) for all NASDAQ-traded stocks
  • Coverage: Up to April 1, 2020
  • Structure: Individual ticker CSV files
  • Metadata: data/raw/symbols_valid_meta.csv
  • Purpose: Provide sector-level daily returns, volatility, and trading volume to measure market performance
  • Note on ETF Exclusion: ETFs are omitted as they represent mixed bundles of assets that would introduce confounding variables

2. Military Intervention (MI) Project Data

  • Source: Fletcher Center for Strategic Studies
  • Coverage: U.S. military interventions from 1776 to 2017
  • Fields: Start date, end date, location, operation type, conflict intensity metrics, duration, fatalities
  • Purpose: Align intervention periods with trading days to evaluate market responses before, during, and after conflicts

3. Sector and Industry Classification Data

  • Source: SEC Company Tickers API and financial data aggregators
  • Coverage: Real-time sector and industry mappings for publicly traded companies
  • Sectors: Technology, Healthcare, Financial Services, Energy, Consumer Cyclical/Defensive, Communication Services, Industrials, Real Estate, Utilities, Materials
  • Purpose: Enable sector-based analysis and cross-sector market behavior comparison

Methodology

This analysis follows a structured approach:

  1. Data Loading & Integration: Load and merge stock market data with sector/industry classifications
  2. Data Cleaning: Remove ETFs, handle missing values, and standardize data formats
  3. Military Intervention Data Processing: Clean and standardize intervention records
  4. Feature Engineering: Calculate returns, volatility, and abnormal returns using CAPM
  5. Event Study Analysis: Create event windows around interventions and measure market reactions
  6. Statistical Testing: Apply hypothesis-driven tests to determine causal relationships

Stock Data Processing

The stock data cleaning pipeline includes:

  1. Initial Data Merge: Standardize ticker symbols and merge OHLCV data with metadata
  2. Stock Universe Building: Combine multiple data sources to ensure reliable sector assignments
  3. Feature Selection: Focus on Adjusted Close (for returns) and Volume (for liquidity weighting)
  4. Data Cleaning: Remove invalid observations, handle missing values, and fix volume artifacts
  5. Returns Calculation: Compute daily returns with outlier detection and handling
  6. Volatility Computation: Calculate rolling 20-day volatility per stock
  7. Sector Aggregation: Create volume-weighted sector-level returns and volatility

Why Adjusted Close? Adjusted Close accounts for stock splits and dividends, making returns comparable over long horizons and reducing mechanical jumps that are not true economic price changes.

Why Sector Level? Stock-level analysis is too noisy, and industry-level labels are unreliable (>75% "Unknown"). Sector aggregation provides clearer and more interpretable market impacts.

Military Intervention Data Processing

The MIP cleaning pipeline includes:

  1. Date Handling: Impute missing day components (use 15th when month is known), drop interventions with invalid dates
  2. Data Validation: Remove flagged cases, ensure start ≤ end dates, recompute duration
  3. Fatalities Cleaning: Extract numeric values from text fields
  4. Country Mapping: Convert 3-letter codes to full country names
  5. Objective Standardization: Map multiple objectives to canonical categories (ECONOMIC_PROTECTION, PROTECT_OWN_MIL_DIP, ACQUIRE_DEFEND_TERRITORY, REMOVE_REGIME, MAINTAIN_BUILD_REGIME, SOCIAL_HUMANITARIAN)
  6. Data Type Optimization: Convert to stable types and listify multi-value fields

PCA-Based Intensity Index

Interventions differ in duration, hostility/escalation, and lethality. To compare them consistently, we build a single intensity score per intervention using Principal Component Analysis (PCA).

Intensity Sub-scores

We construct three numeric subscores:

  • Duration: log(1+days)
  • Escalation: average of MIP hostility/activity indicators
  • Lethality: log(1+fatalities)

Instead of arbitrary weights, we use PCA to find the linear combination that captures the most variation. We take the first principal component (PC1) as the overall intensity index, enforce its direction so higher lethality ⇒ higher intensity, and rescale to [0, 1].

This produces a continuous, interpretable measure of intervention severity for heterogeneity analysis and overlap resolution.

Event Windows and Overlap Handling

Pre/Post Windows

War start and end dates rarely capture the full moment when markets react. Investors often price in information before the official start and effects can persist after the end. We add pre and post windows around each intervention:

  • Pre: baseline market behavior just before the intervention
  • During: market behavior while the intervention is ongoing
  • Post: short-term adjustment after the intervention ends

Window length: w = min(20, duration) so short interventions don't get oversized context windows.

This structure helps measure abnormal changes relative to a local baseline and check anticipation vs persistence.

Handling Overlapping Interventions

Many U.S. military interventions overlap in time. To avoid attribution problems, we build a non-overlapping subset using a greedy rule:

  1. Rank interventions by PCA-based intensity index
  2. Keep the most intense intervention first
  3. Keep additional interventions only if their effective window (pre_start → post_end) does not overlap with already kept interventions
  4. Drop overlapping weaker interventions and label them overlaps_stronger_war

This ensures each event window can be interpreted cleanly with a unique geopolitical shock and no contamination from other interventions.

Date Range Restriction

We restrict analysis to interventions whose effective start falls within the stock-market sample period [1962-01-30, 2020-04-01]. For conflicts extending beyond the last available price date, we only observe their early phase—estimates should be interpreted as short-run market reactions around intervention onset, not full long-run effects.

Daily MIP Panel and Event-Window Approach

Stock data is recorded daily, so we convert each intervention from a single [start, end] interval into a day-by-day panel. For every intervention, we create one row per day from pre_start to post_end, labeling each day as pre, during, or post. Days with no active intervention are labeled normal.

This daily structure provides a clean date key that merges directly with stock market data, allowing computation of returns and volatility by phase around each intervention.

CAPM-Based Abnormal Returns

To isolate war-driven market reactions from general market movements, we use a CAPM framework:

Market Benchmark

We compute a daily market return as a volume-weighted average across sectors. This serves as the benchmark factor.

Normal Period Estimation

For each sector, we estimate its normal relationship to the market using only "normal" days (no active military intervention):

R_{s,t} = α_s + β_s R_{m,t} + ε_{s,t}

This provides:

  • β_s: sector sensitivity to market moves
  • α_s: sector baseline return not explained by market

Abnormal Returns

We compute the counterfactual expected return on any day:

R̂_{s,t} = α_s + β_s R_{m,t}

The abnormal return is:

AR_{s,t} = R_{s,t} - R̂_{s,t}

This captures the part of a sector's return not explained by general market movements. We analyze these abnormal returns within pre/during/post windows to measure short-run market reactions to military interventions.

Key Findings

Sector-Specific Reactions

The overall market impact is negative, with aggregate prices falling by around 7% after interventions. However, sector responses are highly heterogeneous:

  • Most Affected (Negative): Industrials, Real Estate, Consumer Staples show the largest declines
  • Resilient/Positive: Health Care, Technology, Telecommunications, Utilities exhibit positive post-intervention performance

Volatility and Risk

Sectors display strong differences in downside risk:

  • Defensive Sectors: Utilities and Financial Services show milder drawdowns (−62% to −66%)
  • Cyclical/Growth Sectors: Energy, Health Care, Consumer Staples, Technology experience deep drawdowns close to −90%

Trading Volume Patterns

Abnormal trading volume (AVOL) analysis reveals:

  • Volume is elevated before intervention dates, suggesting market anticipation
  • No sharp spike at t=0, indicating events are largely expected
  • AVOL remains above baseline after interventions, reflecting sustained portfolio adjustments

Intervention Characteristics

  • Most Common Objectives: Protect Own Military/Diplomatic Interests (17.8%), Economic Protection (16.1%)
  • Duration: Highly right-skewed distribution (median 54 days, mean 377 days)
  • Geographic Concentration: China (41), Russia (28), North Korea (17), Mexico (17), Cuba (16) most frequently targeted
  • Return Distribution: Leptokurtic structure (sharply peaked with heavy tails) across all sectors, with Energy, Basic Materials, and Consumer Cyclical showing highest volatility

Repository Structure

├── data/
│   ├── all_us_stocks_company_info.csv          # Company information data
│   ├── df_event_panel.csv                      # Event panel data
│   ├── df_event_panel_full.csv                 # Full event panel data
│   ├── df_event_panel_return_capm.csv          # CAPM return analysis
│   ├── df_event_panel_volatility_capm.csv      # CAPM volatility analysis
│   ├── df_mapping_cleaned.csv                  # Cleaned symbol mappings
│   ├── df_mip_cleaned.csv                      # Cleaned MIP data
│   ├── event_panel_summary.txt                 # Summary statistics
│   ├── raw_stock_market_data_kaggle_stocks_only.csv  # Raw stock data
│   ├── us_stock_metrics_filtered.csv           # Filtered stock metrics
│   └── *.png                                   # Visualization outputs
├── frontend/                                   # Web interface
│   ├── assets/
│   │   ├── data/                               # Visualization data as JSON
│   │   ├── dist/                               # Bootstrap CSS/JS setup
│   │   └── navbarHeight.js                     # Navbar utility
│   ├── imgs/                                   # Web images
│   ├── plots/                                  # Interactive plot HTML files
│   ├── style/                                  # CSS style setups
│   ├── conclusion.html                         # Conclusion page
│   ├── globe.html                              # Globe visualization page
│   ├── index.html                              # Frontend homepage
│   ├── rq1.html                                # Research Question 1 page
│   ├── rq2.html                                # Research Question 2 page
│   └── rq3.html                                # Research Question 3 page
├── src/
│   ├── data/
│   │   ├── MIP-Dataset_2022.xlsx               # Military intervention data
│   │   ├── nasdaq_screener_1762031373231.csv   # Nasdaq screener data
│   │   └── symbols_valid_meta.csv              # Stock market meta data
│   ├── models/
│   │   ├── event_study.py                      # Event study models
│   │   ├── features.py                         # Feature engineering
│   │   └── intensity.py                        # PCA intensity index
│   ├── scripts/
│   │   ├── cleaning.py                         # Data cleaning
│   │   ├── country_and_objective_analysis.py   # Country/objective analysis
│   │   ├── loaders.py                          # Data loading
│   │   ├── mapping.py                          # Symbol/sector mapping
│   │   ├── mip_period.py                       # MIP daily panel
│   │   ├── outlier_detection.py                # Outlier detection
│   │   ├── overlaps.py                         # Overlap handling
│   │   ├── panel.py                            # Event panel creation
│   │   ├── sector_analysis.py                  # Sector aggregation
│   │   └── windows.py                          # Event window construction
│   └── utils/                                  # Analysis utility functions
│       ├── case_study_plots.py                 # Case study visualizations
│       ├── causal_plots.py                     # Causal analysis plots
│       └── visualizer.py                       # General visualization utilities
├── tests/                                      # Unit tests
│   ├── test_abnormal_volatility.py
│   ├── test_data_cleaning.py
│   ├── test_data_loader.py
│   ├── test_event_window_analysis.py
│   ├── test_intensity_pca.py
│   ├── test_symbol_mapping.py
│   └── test_visualizer.py
├── index.html                                  # Project website redirect
├── results.ipynb                               # Main analysis notebook
├── pip_requirements.txt                        # Python dependencies
└── README.md                                   # This document

How to Run

# Clone project
git clone <project-link>
cd <project-repo>

# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate       # Linux/Mac
venv\Scripts\activate          # Windows

# Install dependencies
pip install -r pip_requirements.txt

# Run tests
pytest tests/

# Open main analysis
jupyter notebook results.ipynb

The results.ipynb notebook runs the end-to-end pipeline:

  1. Data loading and integration
  2. Stock and MIP data cleaning
  3. Intensity index computation
  4. Event window construction and overlap resolution
  5. Sector aggregation and CAPM estimation
  6. Abnormal return analysis
  7. Visualization and statistical testing

Exploratory Data Analysis Highlights

Trading Days and Data Quality

The vast majority of gaps in trading data are 1 day, with some 3-day gaps (weekends/holidays), indicating a standard trading calendar with minimal missing data.

Sector Distribution

  • Financial Services is the largest sector (25.4%)
  • Health Care (17.3%) and Technology (11.2%) are also significant
  • Industry labels are largely unreliable (75.8% fall into "Other"), justifying sector-level analysis

Military Intervention Patterns

  • Objectives: Most interventions aim to protect military/diplomatic interests (17.8%) or economic interests (16.1%)
  • Duration: Median 54 days, but mean 377 days due to long-tail distribution
  • Geography: Highly concentrated in China (41), Russia (28), North Korea (17), Mexico (17), Cuba (16)
  • Total: 94 countries targeted at least once

Market Behavior Around Interventions

  • Aggregate Impact: ~7% decline in adjusted close prices post-intervention
  • Sector Heterogeneity: Industrials, Real Estate, Consumer Staples most affected negatively; Health Care, Technology, Utilities show resilience
  • Anticipation Effect: Abnormal volume elevated before intervention dates
  • Persistence: AVOL remains above baseline after interventions

Return Characteristics

  • Distribution: Leptokurtic (sharply peaked with heavy tails) across all sectors
  • Volatility Leaders: Energy, Basic Materials, Consumer Cyclical show widest return ranges
  • Stable Sectors: Financial Services, Health Care exhibit tighter distributions
  • Drawdown Risk: Cyclical sectors experience drawdowns near −90%, while defensive sectors (Utilities, Financial Services) show milder −62% to −66% drawdowns

Team Contributions

  • Oussama Ghali: Objectives clustering, Sector Mapping, Intensity index PCA, Stock outlier diagnostics, README, Event window construction, Website development, Data Story
  • Melek Fendri: Overlap handling, Returns and volatility analysis, Event-panel creation, Stock dataframe processing
  • Houssein Chebaane: Visualizer development, Country and objective impact analysis
  • Matthew Volpatti: Causality proof
  • Basti: Visualizations, data story, website development

About

ada-2025-project-market-miners created by GitHub Classroom

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages