An Excel Integration for macroframe-forecast
Project description
mf-excel - An Excel Integration for macroframe-forecast
mf-excel provides Excel integration functionality for macroframe-forecast Python module developed by Ando et al., (2025).
It allows you to:
- Run constrained macroeconomic forecasts
- Control models and constraints from Excel
- Execute the engine via Flask (local or remote)
- Integrate seamlessly with xlwings
📦 Installation
pip install macroframe-excel
Windows Requirement (Important)
Excel and Python must have the same bitness:
| Excel | Python |
|---|---|
| 64-bit | 64-bit Python |
| 32-bit | 32-bit Python |
📊 Excel Integration (xlwings)
Install xlwings
pip install xlwings
Load the xlwings Add-in
- Open Excel
- Go to Developer → Excel Add-ins → Browse
- Select
xlwings.xlam - Restart Excel if prompted
Point the Python Interpreter and Work directory PATH to the xlwings
- Reopen Excel
- Click on the xlwings menu
- Locate the Interpreter space and paste the Python PATH e.g. (C:\Users\macro\Desktop\mf_excel.venv\Scripts\python.exe).
- Locate the PYTHONPATH space and paste the directory where your data for forecasting is stored.
- Save the Excel file as Macro-Enabled Worksheet (.xlsm)
Running the Forecast Backend
The backend is a Flask application that Excel communicates with over HTTP.
Option 1: Run from Command Line
macroframe-forecast
This starts the service at:
http://127.0.0.1:5001
Option 2: Run from Jupyter Notebook (Recommended)
This is the safest way to run Flask alongside Excel.
from mf_excel.backend.app import app
from mf_excel.backend.services.config import settings
import threading
def start_flask():
app.run(
host=settings.HOST,
port=settings.PORT,
debug=False,
use_reloader=False
)
threading.Thread(target=start_flask, daemon=True).start()
print("MacroFrame Forecast backend running")
⚠️ Always use use_reloader=False on Windows.
📊 Excel Workbook Structure
Your Excel workbook should contain the following sheets:
| Sheet Name | Purpose |
|---|---|
| Input | Time series data |
| Control | Run Forecast, View Models, Insert Charts, and Settings Buttons |
VBA Button Wiring
Create a VBA module in Excel (Alt + F11 → Insert → Module) and paste the following:
Sub RunMacroFrameForecast()
RunPython "import macroframe_excel.excel_client.addin as a; a.run_forecast_button()"
End Sub
Sub InsertMacroFrameCharts()
RunPython "import macroframe_excel.excel_client.addin as a; a.insert_charts_button()"
End Sub
Sub ViewMacroFrameModels()
RunPython "import macroframe_excel.excel_client.addin as a; a.view_models_button()"
End Sub
Sub OpenMacroFrameSettings()
RunPython "import macroframe_excel.excel_client.addin as a; a.settings_button()"
End Sub
Assigning Buttons in Excel Control Sheet
- Go to Insert → Shapes
- Draw a button and assign appropriate names (e.g., Run Forecast or View Models)
- Right-click → Assign Macro
- Choose one of:
RunMacroFrameForecast(for Run Forecast Button)InsertMacroFrameCharts(for Insert Charts Button)ViewMacroFrameModels(for View Models Button)OpenMacroFrameSettings(for Settings Button)
Note: The control sheet should have 4 buttons (Run Forecast, View Models, Insert Charts, Settings).
Input Data Format
Forecast input data must be in tabular form. See the example datasets 'test.csv' and 'test2.csv' on the Github.
Example:
| Year | GDP |
|---|---|
| 1960 | 0.54 |
| 1961 | 0.56 |
| 1962 | 0.60 |
| 1963 | 0.64 |
| 1964 | 0.69 |
| 1965 | 0.74 |
| 1966 | 0.81 |
| 1967 | 0.86 |
| 1968 | 0.94 |
| 1969 | 1.02 |
| ... | ... |
| 2024 | 29.2 |
| 2025 | |
| 2026 | |
| 2027 | |
| 2028 | |
| 2029 | |
| 2030 |
Rules:
- Time column must be one of: Year, Quarter, Month, Week, Day
- Leave forecast horizon rows blank
- Each variable must be numeric
Constraints
Input the constraints in the Constraints sheet. Constraints are optional and entered as expressions.
Examples
GDP_2030 = 1.04 * GDP_2029
These constraints are:
- Validated before model execution
- Applied during forecast optimization
- Compatible with Excel UI inputs
Making Forecast
- With the backend already running, click the 'Settings' Button in the Control sheet. It will add a new sheet named 'Settings' in the Excel.
- Click on the Settings sheet and specify the forecaster model and parameters to use in your forecast. You must be familiar with the original work of Ando et al., (2025) to understand the process.
- After selecting forecaster and parameters, return to the Control sheet and click 'Run Forecast' Button. It will return the outputs and diagnostics in separate sheets after a few seconds or minutes depending on the model selected.
License
MIT License - See LICENSE for details.
Support Notes
- Always start the backend before clicking Excel buttons
- Do not run Flask in debug mode on Windows
- Ensure Python and Excel bitness match
- Use Jupyter Notebook or VS Code for interactive workflows
Next Steps 🗺️
We will continue to monitor updates to the 'macroframe-forecast' and
References
Ando Sakai, Shuvam Das, and Sultan Orazbayev (2025). "A Python Package to Assist Macroframework Forecasting: Concepts and Examples", IMF Working Papers 2025, 172, accessed 28/12/2025, https://doi.org/10.5089/9798229023535.001
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mf_excel-0.1.0.tar.gz.
File metadata
- Download URL: mf_excel-0.1.0.tar.gz
- Upload date:
- Size: 31.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b97bdc796000f7c1b21f35d94b76acb356cf17eb34f3589793a943f154e44d4
|
|
| MD5 |
6b8575c2ccfb8ebec082a0156102e37e
|
|
| BLAKE2b-256 |
f8a66aa48d8dc06dc9719dca9ec1154245bfb52a49429657fdaa878d49c8ae20
|
File details
Details for the file mf_excel-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mf_excel-0.1.0-py3-none-any.whl
- Upload date:
- Size: 32.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
420fd35f72fbcc71ab1d8a457a390812cc251b4704049ef20cf01c1a426f5cec
|
|
| MD5 |
5215ecfdd4869b6615490cac679fefc2
|
|
| BLAKE2b-256 |
e0a9dd75b3b28551e6ac2bd05efc1d800f2a629a0ed55b9b00db531ad55e80d9
|