Skip to content

bruno-portfolio/BasisMind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

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

image image image image image image

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/YOUR_USERNAME/basismind.git
cd basismind

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or: venv\Scripts\activate  # Windows

# Install dependencies
pip install -r requirements.txt

Run the Dashboard

streamlit run dashboard/app.py

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

πŸ“Š 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/                      # Core engine (12 modules)
β”‚   β”œβ”€β”€ config.py             # Constants and thresholds
β”‚   β”œβ”€β”€ scoring.py            # Scoring engine
β”‚   β”œβ”€β”€ overrides.py          # Override rules
β”‚   β”œβ”€β”€ engine.py             # Main integrated engine
β”‚   └── ...
β”œβ”€β”€ dashboard/                # Streamlit dashboard
β”‚   β”œβ”€β”€ app.py                # Home page
β”‚   └── pages/                # Dashboard pages
β”‚       β”œβ”€β”€ 1_πŸ“Š_Dados_Mercado.py
β”‚       β”œβ”€β”€ 2_🎯_Motor_Decisao.py
β”‚       β”œβ”€β”€ 3_πŸ”„_Simulador.py
β”‚       β”œβ”€β”€ 4_πŸ“ˆ_Analise.py
β”‚       └── 5_πŸ“š_Documentacao.py
β”œβ”€β”€ data/
β”‚   └── mock_generator.py     # Synthetic data generator
β”œβ”€β”€ examples/
β”‚   └── demo.py               # CLI demonstration
└── notebooks/
    └── demo.ipynb            # Jupyter notebook

πŸ’» Usage Example

from datetime import date
from src 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, 5, 15),
    var_semanal_lineup=8.0,
    percentil_premium=72.0,
    spread_adjusted=5.0,
    z_pace=0.5,
    var_cambio_5d=-0.8,
    chicago_percentile=65.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']}")

πŸ“‹ JSON Output

{
  "data_referencia": "2024-05-15",
  "score_fisico": 68.5,
  "classificacao": "forte",
  "recomendacao_fisica": {
    "acao": "aumentar",
    "intensidade": "moderada",
    "sizing_pct": 15.0
  },
  "recomendacao_hedge": {
    "acao": "manter",
    "intensidade": "neutra",
    "delta_pp": 0.0
  },
  "componentes": {
    "lineup": {"score": 77.0, "var_semanal": 8.0},
    "premio": {"score": 72.0, "percentil": 72.0},
    "competitividade": {"score": 37.5, "spread": 5.0},
    "demanda": {"score": 66.7, "z_pace": 0.5},
    "cambio": {"score": 63.3, "var_5d": -0.8}
  },
  "overrides_ativos": [],
  "justificativa": "Strong physical (score 68) | Drivers: lineup strong, premium strong | ..."
}

⚠️ 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
  • 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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors