Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BasisMind 🌾

CI Python 3.11+ Streamlit License: MIT

Basis (commodity trading term) + Mind (intelligence) β€” A decision support system for physical grain trading operations, transforming scattered market signals into consistent and auditable recommendations.

Overview

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.

Key Questions Answered

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.

Features

  • πŸ“Š 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

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                          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  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

Installation

# 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 .

Run the Dashboard

streamlit run dashboard/app.py
# or: python run_dashboard.py

Open http://localhost:8501 in your browser.

Run the Tests

pip install -e .[dev]
pytest

Score Components

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)

Override Rules

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

Project Structure

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

Usage Example

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

JSON Output

{
  "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)"
}

Limitations

The Decision Engine does NOT:

  • Predict future prices
  • Replace human judgment
  • Capture geopolitical events
  • Guarantee results

Tech Stack

  • Python 3.11+
  • Streamlit - Interactive dashboard
  • Plotly - Interactive charts
  • SQLite - Local storage
  • Pandas - Data manipulation

License

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

About

A decision support system for physical grain trading operations, transforming scattered market signals into consistent and auditable recommendations.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages