Basis (commodity trading term) + Mind (intelligence) β A decision support system for physical grain trading operations, transforming scattered market signals into consistent and auditable recommendations.
The Decision Engine standardizes market reading and reduces subjective bias in commodity trading decisions. It formalizes into explicit rules the logic that experienced professionals apply intuitively.
| Axis | Question |
|---|---|
| Physical | Accelerate sales, hold position, or reduce exposure? |
| Hedge | Increase Chicago hedge, hold, or reduce? |
Every recommendation includes a traceable justification showing which signals drove the decision.
- π Weighted Scoring - Combines 5 market indicators into a single [0-100] score
- β‘ Override Rules - 5 rules that dominate scoring in critical market situations
- π Book Modulation - Adjusts recommendations based on current exposure limits
- π Full Traceability - Every decision includes detailed justification
- ποΈ Interactive Simulator - Test any scenario in real-time
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MARKET INPUTS β
β Premium β Lineup β Competitiveness β FX Rate β Demand β Chicago β
βββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SCORING ENGINE β
β ββββββββββ ββββββββββ ββββββββββ ββββββββββ ββββββββββ β
β β Lineup β βPremium β β Compet β β Demand β β FX β β
β β 30% β β 25% β β 20% β β 15% β β 10% β β
β βββββ¬βββββ βββββ¬βββββ βββββ¬βββββ βββββ¬βββββ βββββ¬βββββ β
β ββββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββ β
β Aggregated Score [0-100] β
βββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β OVERRIDE RULES β
β Logistics β Joint Drop β Premium Trap β Competitiveness β Spike β
βββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BOOK MODULATION β
β Exposure Limits β Hedge Target β Effective Sizing β
βββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DECISION OUTPUT β
β Physical Recommendation β Hedge Recommendation β Justification β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Clone the repository
git clone https://github.com/bruno-portfolio/BasisMind.git
cd BasisMind
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# or: venv\Scripts\activate # Windows
# Install the package
pip install -e .streamlit run dashboard/app.py
# or: python run_dashboard.pyOpen http://localhost:8501 in your browser.
pip install -e .[dev]
pytest| Component | Weight | Description |
|---|---|---|
| Lineup | 30% | Real demand: scheduled vessels for shipment |
| Premium | 25% | Price level vs historical (by crop/off-season regime) |
| Competitiveness | 20% | Brazil vs US Gulf FOB spread |
| Demand | 15% | Export pace vs 5-year average |
| FX Rate | 10% | USD/BRL variation (margin modulator) |
Overrides dominate the score when triggered:
| Priority | Override | Condition | Action |
|---|---|---|---|
| 1 | Logistics | Port congestion, strikes | Sell urgently |
| 2 | Joint Drop | Lineup β AND Premium β | Reduce exposure |
| 3 | Premium Trap | Premium β AND Lineup β | Capture via sale |
| 4 | Competitiveness | Spread > +15 USD/ton | Sell |
| 5 | Chicago Spike | >5% rise without fundamentals | Hedge, don't buy |
BasisMind/
βββ src/basismind/ # Core engine (installable package)
β βββ config.py # Constants and thresholds
β βββ scoring.py # Scoring engine
β βββ overrides.py # Override rules
β βββ book.py # Book modulation
β βββ engine.py # Main integrated engine
β βββ mock_generator.py # Synthetic data generator
β βββ ...
βββ dashboard/ # Streamlit dashboard
β βββ app.py # Entrypoint (navigation + theme)
β βββ ui.py # Design system: palette, charts, cards
β βββ data.py # Mock data β real signal metrics β MarketInputs
β βββ views/ # home Β· engine Β· simulator Β· market Β· analysis Β· docs
βββ tests/ # Behavior tests for the decision logic
βββ examples/
β βββ demo.py # CLI demonstration
βββ notebooks/
βββ demo.ipynb # Jupyter notebook
from datetime import date
from basismind import DecisionEngine, MarketInputs, BookState
# Initialize engine with book state
book = BookState(
exposicao_fisica_pct=30.0,
limite_long_pct=80.0,
limite_short_pct=-50.0,
hedge_atual_pct=45.0,
hedge_meta_pct=60.0,
)
engine = DecisionEngine(book)
# Prepare market inputs
inputs = MarketInputs(
dt=date(2024, 6, 1),
var_semanal_lineup=15.0,
percentil_premium=82.0,
spread_adjusted=-18.0,
z_pace=1.2,
var_cambio_5d=-2.0,
chicago_percentile=70.0,
chicago_is_spike=False,
logistics_flag_active=False,
logistics_reason=None,
)
# Run engine
report = engine.run(inputs)
print(f"Score: {report.score_fisico:.1f}")
print(f"Physical: {report.recomendacao_fisica['acao']}")
print(f"Hedge: {report.recomendacao_hedge['acao']}")
# Score: 91.3
# Physical: aumentar_forte
# Hedge: aumentar{
"data_referencia": "2024-06-01",
"score_fisico": 91.3,
"classificacao": "muito_forte",
"recomendacao_fisica": {
"acao": "aumentar_forte",
"intensidade": "forte",
"sizing_pct": 25.0
},
"recomendacao_hedge": {
"acao": "aumentar",
"intensidade": "moderada",
"delta_pp": 10.0
},
"componentes": {
"lineup": {"score": 100.0, "var_semanal": 15.0},
"premio": {"score": 82.0, "percentil": 82.0},
"competitividade": {"score": 95.0, "spread": -18.0},
"demanda": {"score": 90.0, "z_pace": 1.2},
"cambio": {"score": 83.3, "var_5d": -2.0}
},
"overrides_ativos": [],
"override_dominante": null,
"modulacao_aplicada": false,
"modulacao_razao": null,
"justificativa": "Fisico muito_forte (score 91) | Drivers: lineup forte, competitividade forte | Recomendacao: aumentar_forte (fisica), aumentar (hedge)"
}The Decision Engine does NOT:
- Predict future prices
- Replace human judgment
- Capture geopolitical events
- Guarantee results
- Python 3.11+
- Streamlit - Interactive dashboard
- Plotly - Interactive charts
- SQLite - Local storage
- Pandas - Data manipulation
MIT License - see LICENSE for details.
Built as a portfolio project demonstrating skills in:
Python β’ Data Engineering β’ Trading Systems β’ Decision Support β’ Streamlit
Quick Start β’ Features β’ Architecture β’ Usage