Skip to content

Forecast factory is an interactive AI-powered forecasting and simulation tool built with Python, Streamlit, Prophet, and SQL. It enables analysts to forecast business metrics, run what-if scenarios, and visualize results in real time, transforming predictive analytics into actionable strategic simulations.

License

Notifications You must be signed in to change notification settings

AmirhosseinHonardoust/Forecast-Factory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ForecastFactory, AI-Driven Scenario Simulator

ForecastFactory is an advanced AI-powered forecasting and simulation platform built with Python, Streamlit, Prophet, and SQLAlchemy. It enables analysts, data scientists, and business strategists to simulate business outcomes under different β€œwhat-if” scenarios, allowing organizations not just to predict, but to plan and adapt intelligently.


Project Overview

ForecastFactory bridges the gap between data-driven forecasting and strategic scenario planning. Traditional forecasting tools answer β€œwhat will happen,” while ForecastFactory explores β€œwhat could happen” under changing conditions like pricing shifts, ad budget changes, or supply constraints.

Core Purpose: Empower teams to simulate future outcomes, test assumptions, and quantify the effect of strategic decisions in real time.


Business Goal

Most organizations rely on static forecasts that can’t adapt to real-world changes. ForecastFactory empowers them to:

  • Quantify trade-offs: What if ad spend rises by 20%?
  • Stress-test assumptions: How sensitive is revenue to a price increase?
  • Prepare for volatility: What if demand drops due to supply shortages?

It transforms forecasting from passive prediction into active decision simulation.


Key Features

  • AI Forecasting: Prophet-based trend, holiday, and seasonality modeling.
  • Scenario Engine: Interactive β€œwhat-if” analysis with domain-driven adjustments.
  • Elasticity Modeling: Realistic impact simulation via custom elasticity coefficients.
  • SQL-Integrated Pipeline: Seamlessly fetch data via SQLAlchemy.
  • Dynamic Visualization: Real-time Plotly and Streamlit dashboards.
  • Explainability: Automated narrative summaries for business interpretation.
  • Exportable Outputs: Save data as CSV or Markdown reports.

Architecture Overview

flowchart LR
A["SQL / CSV Data Source"] --> B["ETL + Feature Engineering"]
B --> C["Forecast Model (Prophet + Baseline)"]
C --> D["Scenario Engine (Elasticity Adjustments)"]
D --> E["Explainability Layer (Attribution + Narrative)"]
E --> F["Visualization (Streamlit + Plotly)"]
F --> G["Exports: CSV / Model / Insights"]
Loading

Design Philosophy

The system is modular and extensible, enabling analysts to plug in new models or connect it to MLOps pipelines for continuous retraining.


Technical Architecture

1. Data & SQL Layer

  • SQLite used for quick prototyping, extensible to PostgreSQL or Snowflake.
  • SQLAlchemy ORM provides seamless connection and schema management.
  • Data cleaned and aggregated via Pandas ETL transformations.

2. Forecast Engine

  • Powered by Prophet, modeling seasonality, trend, and holiday effects.
  • Fallback to Moving Average for baseline comparison.
  • Backtesting pipeline validates performance via MAE, RMSE, and SMAPE.

3. Scenario Engine

  • Defines relationships such as:

    • Ξ”Q/Q = Ξ΅ Γ— Ξ”P/P (Price elasticity)
    • Uplift = Ξ± Γ— log(1 + Ξ² Γ— AdSpend) (Media response)
    • Q' = Q Γ— (1 + Ξ³ Γ— PromoFlag) (Promotion effects)
  • Produces differential forecasts showing net impact vs baseline.

4. Visualization Layer

  • Streamlit powers the interactive UI.
  • Plotly renders visual insights with interactivity and real-time updates.
  • Exports available in CSV format for further analysis.

5. Explainability Module

  • Integrates Prophet component decomposition and SHAP-like narratives.
  • Generates business-oriented insights: β€œIncreased ad spend drove +7.8% uplift over baseline between July-August.”

Screenshots

ForecastFactory Home

Screenshot 2025-11-07 at 13-37-21 ForecastFactory Scenario Simulator

Define the data source, KPI, and forecast horizon.


Baseline Forecast

Screenshot 2025-11-07 at 13-37-33 ForecastFactory Scenario Simulator

Displays Prophet-based forecasts with confidence intervals.


Scenario Builder

Screenshot 2025-11-07 at 13-37-52 ForecastFactory Scenario Simulator

Interactively tweak ad spend, pricing, or promotions to simulate impact.


Delta Analysis

Screenshot 2025-11-07 at 13-38-08 ForecastFactory Scenario Simulator

Visualize baseline vs simulated outcomes, with quantified uplift metrics.


Case Study, E-commerce Demand Simulation

Objective: Forecast 90 days of revenue while simulating increased ad spend and promotions.

  1. Baseline: Prophet trained on 2 years of revenue data.

  2. Scenario: +15% ad spend, 10% promotion activation.

  3. Elasticity Equations:

    • Ad response = 0.3 Γ— log(1 + 0.001 Γ— spend)
    • Promo uplift = +6%
  4. Result: +8.7% projected uplift vs baseline; Β±2.3% confidence margin.

  5. Insight: The simulator suggested that moderate ad increases yield diminishing returns after 15% budget growth.


Directory Structure

forecastfactory/
β”‚
β”œβ”€β”€ app.py                   # Streamlit main interface         
β”œβ”€β”€ db/
β”‚   β”œβ”€β”€ schema.sql           # Database schema
β”‚   └── seed.sql             # Sample data
β”œβ”€β”€ forecastfactory
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ elasticity.py
β”‚   β”œβ”€β”€ explain.py
β”‚   β”œβ”€β”€ features.py
β”‚   β”œβ”€β”€ io_sql.py
β”‚   β”œβ”€β”€ models.py 
β”‚   β”œβ”€β”€ scenario.py
β”‚   └── viz.py
β”œβ”€β”€ config.yaml              # Configuration
└── requirements.txt         # Dependencies


Technical Appendix

Forecasting Metrics

Metric Formula Description
MAE Ξ£ yβˆ’Ε·
RMSE √Σ(yβˆ’Ε·)Β² / n Penalizes larger errors
SMAPE (200/n) Ξ£ yβˆ’Ε·

Elasticity Equations

  • Price Elasticity: Ξ”Q/Q = Ξ΅ Γ— Ξ”P/P
  • Media Response: Uplift = Ξ± Γ— log(1 + Ξ² Γ— AdSpend)
  • Promo Effect: Q’ = Q Γ— (1 + Ξ³ Γ— PromoFlag)

Database Schema

Table Description
fact_kpi_daily KPI value by day
fact_drivers_daily Drivers (price, ad spend, promo)
dim_calendar Holidays and day-of-week metadata

Setup Instructions

git clone https://github.com/AmirhosseinHonardoust/Forecast-Factory.git
cd ForecastFactory
pip install -r requirements.txt
streamlit run app.py

If Prophet is missing:

pip install prophet pystan==2.19.1.1

Database initialization:

python -m forecastfactory.cli init

Business Applications

Sector Example Use Case
E-commerce Predict sales under different promo policies
Marketing Simulate ROI of ad budget increases
Finance Stress-test revenue against macroeconomic shocks
Retail Optimize stock levels under demand uncertainty
Operations Forecast capacity or workforce requirements

Future Enhancements

  • Integrate XGBoost and LSTM for hybrid forecasting.
  • Introduce AutoML model selection and backtesting reports.
  • Add multi-scenario comparison (budget vs promo vs combined).
  • Implement role-based dashboards with Streamlit authentication.
  • Export results to Power BI or Google Data Studio.
  • Connect to real-time APIs for adaptive forecasting.

References & Attributions


Conclusion

Forecast-Factory transforms forecasting into a dynamic, interactive experience that merges machine learning, simulation, and human insight. It’s a platform where analysts don’t just observe the future, they shape it through data-driven experimentation.

About

Forecast factory is an interactive AI-powered forecasting and simulation tool built with Python, Streamlit, Prophet, and SQL. It enables analysts to forecast business metrics, run what-if scenarios, and visualize results in real time, transforming predictive analytics into actionable strategic simulations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages