01Market data challenge
Free per-stock Casablanca history is fragmented. The current analytical panel contains 124,562 daily observations across 78 symbols from January 2015 to June 2026, with MASI history, delayed quotes, issuer references, and explicit source and verification labels.
02Data acquisition & web scraping
Python collectors built with Requests, Beautiful Soup, and Pandas retrieve delayed Casablanca Stock Exchange quotes and French/Arabic financial news from Casablanca Bourse, AMMC, Medias24, L'Economiste, Boursenews, Finances News Hebdo, and La Vie Eco. Source-specific adapters normalize inconsistent HTML into stable quote, issuer, article, timestamp, and provenance schemas.
03Reliable feed engineering
The quote collector can run every 30 minutes during market hours, respects robots.txt, caches raw HTML for traceability, skips overlapping runs with lock files, and preserves append-only quote history. Temporary outputs must pass required-column, row-count, and positive-price checks before atomic replacement; the last valid snapshot remains available if a refresh fails.
04News normalization & provenance
Cross-source deduplication groups normalized same-day headlines, selects the most reliable canonical source, and retains corroborating sources. Every item carries source type, verification status, reliability, confidence, language, collection time, and deterministic company, sector, theme, risk, and opportunity mappings.
05Data quality & freshness
Quote and news refreshes validate schemas, row counts, and numeric prices before atomic replacement. Feed status records attempts, successes, age, row counts, errors, and repeated failures so the interface can expose stale data honestly.
06Stock & market risk
The platform calculates annualised return and volatility, Sharpe ratio, maximum drawdown, beta to MASI, historical VaR, Expected Shortfall, relative-risk scores, market breadth, sector movement, correlation, and stock-level data-quality signals.
07Liquidity & investability
Amihud illiquidity, zero-return share, observation coverage, and security-master flags identify stale or difficult-to-trade names. These gates prevent low-quality or illiquid securities from entering portfolio and event-study conclusions without sufficient evidence.
08Forecasting & validation
GARCH forecasts volatility, HMM identifies market regimes, and Kupiec backtesting checks VaR exceedances. The objective is to forecast risk conditions rather than future prices.
09Portfolio construction
Equal weight, minimum variance, Hierarchical Risk Parity, and MASI buy-and-hold are compared using an investable universe and Ledoit-Wolf covariance shrinkage. Scorecards expose position weights, concentration, weighted volatility, beta, and downside exposure.
010Walk-forward evidence
Out-of-sample walk-forward tests use periodic rebalancing, transaction costs, survivorship-aware filtering, and saved historical weights. In the latest report, minimum variance produced about 11.0% annualised return, 11.5% volatility, and a 0.75 Sharpe versus approximately 5.4%, 13.3%, and 0.28 for MASI buy-and-hold.
011Monte Carlo risk distribution
A 10,000-path, 252-day HRP simulation reports the complete outcome distribution rather than one forecast. The latest run showed about a 35.7% probability of loss, 6.5% median return, a negative 19.8% fifth-percentile return, 41.2% ninety-fifth percentile, and a negative 14.9% median maximum drawdown.
012Event-level analysis
Market-model event studies calculate abnormal returns, CAR[-5,+5], CAR[0,+1], CAR[0,+5], abnormal-volume ratios, and sentiment/confidence context. Liquidity, observation, and event-count gates prevent weak data from being presented as a meaningful conclusion.
013French & Arabic news
Financial stories are collected from market, regulator, and media sources. Deterministic aliases and sector/theme dictionaries attach context, while multilingual processing and auditable tags describe risk or opportunity without issuing buy/sell signals.
014Analytical findings
The work highlights that domestic diversification can be limited by bank and telecom concentration, while the MASI's lower correlation with global indices may make Moroccan equities more relevant in an international diversification context.
015Decision support
Searchable market snapshots, stock risk profiles, risk rankings, news context, portfolio simulation, and virtual trading translate the analysis into an educational workflow with visible uncertainty and data limitations.
Technical implementation
How the solution was built.
Each layer connects an implementation choice to the decision or workflow it supports.
07 layers| Layer | Implementation | Operational purpose |
|---|
| Market collection | Requests, Beautiful Soup and source-specific adapters for delayed quotes and issuer data | Build a consistent local-market panel from fragmented public sources |
|---|
| News collection | French and Arabic financial-news scraping with normalized headlines, provenance and cross-source deduplication | Connect market analysis to traceable company, sector and macro context |
|---|
| Data reliability | robots.txt checks, raw-response caching, schema validation, lock files, scheduling and atomic writes | Preserve the last valid dataset and expose stale or failed refreshes honestly |
|---|
| Risk measurement | Volatility, beta, drawdown, historical VaR, Expected Shortfall, correlation and liquidity indicators | Compare stock and portfolio exposure with interpretable downside measures |
|---|
| Risk modelling | GARCH volatility forecasts, HMM regimes and Kupiec VaR backtesting | Estimate changing risk conditions and verify whether loss thresholds remain credible |
|---|
| Portfolio analysis | Minimum variance, Hierarchical Risk Parity, Ledoit-Wolf covariance and walk-forward testing | Compare allocations using out-of-sample evidence, costs and investability gates |
|---|
| Simulation and events | 10,000-path Monte Carlo distributions and market-model event studies | Quantify ranges of outcomes and examine abnormal behaviour around news events |
|---|