Skip to content

Commit cb8b9af

Browse files
committed
feat: adiciona seasonality analyzer em tools/
- Análise de sazonalidade mensal com yfinance - Testes de significância estatística (t-test) - Ajuste automático por splits e dividendos - Interface Streamlit com visualizações Plotly
1 parent 5b74383 commit cb8b9af

6 files changed

Lines changed: 462 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
Mesa Quant is a personal quantitative trading platform (written in Portuguese) targeting American markets — stocks, options, futures, and crypto. The project is in early-stage development (Phase 1 — Infrastructure).
8+
9+
**Developer context:** Beginner in quantitative trading, intermediate Python developer. Prefers didactic code over premature optimization. Should be warned explicitly when implementations carry financial risk.
10+
11+
## Commands
12+
13+
```bash
14+
# Setup
15+
python3 -m venv venv
16+
source venv/bin/activate
17+
pip install -r requirements.txt
18+
19+
# Copy and edit config before running anything
20+
cp configs/config.example.yaml configs/config.yaml
21+
22+
# Tests
23+
pytest tests/ -v
24+
25+
# Run a single test file
26+
pytest tests/path/to/test_file.py -v
27+
```
28+
29+
## Architecture
30+
31+
Data flows top-to-bottom through three layers:
32+
33+
**Collection → Persistence → Analysis/Execution**
34+
35+
- **`src/collectors/`** — Data ingestion. `ib_connector.py` wraps `ib_insync` for Interactive Brokers (stocks, futures, historical bars). Crypto via `ccxt` is planned but not yet implemented.
36+
- **`src/utils/database.py`**`DatabaseManager` handles TimescaleDB/PostgreSQL via SQLAlchemy. OHLCV data is stored in hypertables for time-series efficiency.
37+
- **`src/risk/risk_manager.py`** — Portfolio-level guardrails: max position size (5%), max daily loss (2%), max drawdown (10%). Also computes Kelly-based position sizing.
38+
- **`src/backtest/`** and **`src/execution/`** — Currently empty placeholders; VectorBT is the intended backtesting library; `ib_insync` for order execution.
39+
- **`tools/`** — Auxiliary Streamlit tools for research (seasonality analysis, etc.)
40+
41+
Jupyter notebooks in `notebooks/` are for research and strategy development. Logs go to `logs/mesa_quant.log`.
42+
43+
## Configuration
44+
45+
All runtime config lives in `configs/config.yaml` (gitignored). Copy from `configs/config.example.yaml`.
46+
47+
Key sections:
48+
- `interactive_brokers`: TWS/Gateway connection (paper port 7497/4002, live 7496/4001)
49+
- `database`: PostgreSQL/TimescaleDB credentials
50+
- `crypto`: Binance API keys
51+
- `risk`: Position and drawdown limits
52+
- `logging`: Log level and file path
53+
54+
## Infrastructure Dependencies
55+
56+
The platform requires external services to function:
57+
- **TimescaleDB** (PostgreSQL extension) — see `docs/setup_server.md` for server setup
58+
- **IB TWS or IB Gateway** — must be running and API connections enabled before `IBConnector` will work; on headless servers, use Xvfb
59+
60+
## Risk Rules (non-negotiable)
61+
62+
These limits are hardcoded in `src/risk/risk_manager.py` and must NOT be relaxed without explicit review:
63+
- Max position size: **5%** of portfolio per trade
64+
- Max daily loss: **2%** of portfolio (daily stop)
65+
- Max drawdown: **10%** (global stop)
66+
- Every new strategy must pass paper trading before going live
67+
68+
## Git Workflow
69+
70+
- `main` branch for production-ready code
71+
- `develop` branch for integration
72+
- Feature branches from `develop`
73+
- Commit format: `feat:`, `fix:`, `docs:`, `refactor:`, `test:`
74+
75+
## Current Roadmap
76+
77+
- [x] Initial project structure
78+
- [ ] **Phase 1** — Ubuntu Server + TimescaleDB setup
79+
- [ ] **Phase 2** — Historical data ingestion (IB + CCXT)
80+
- [ ] **Phase 3** — First backtests with VectorBT
81+
- [ ] **Phase 4** — Paper Trading
82+
- [ ] **Phase 5** — Live Trading with small capital
83+
84+
## Language Note
85+
86+
Code comments, docstrings, variable names, and documentation are written in Portuguese. User-facing messages and interactions with the developer are in Portuguese (BR). Follow this convention when adding new code.

tools/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.venv/
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 📊 Market Seasonality Analyzer
2+
3+
Ferramenta de research para análise de padrões sazonais em mercados financeiros.
4+
5+
## Funcionalidades
6+
7+
- Retorno médio e mediano por mês
8+
- Win rate (probabilidade histórica de fechar em alta)
9+
- Volatilidade mensal (desvio padrão)
10+
- Teste de significância estatística (p-valor)
11+
- Dados ajustados por splits e dividendos
12+
13+
## Como rodar
14+
15+
```bash
16+
cd tools/seasonality_analyzer
17+
pip install -r requirements.txt
18+
streamlit run app.py
19+
```
20+
21+
## Fonte de dados
22+
23+
Yahoo Finance via biblioteca `yfinance`. Suporta tickers americanos
24+
(SPY, AAPL, etc.) e brasileiros com sufixo `.SA` (PETR4.SA, VALE3.SA).
25+
26+
## Disclaimer
27+
28+
Ferramenta de uso educacional e de research. Não constitui
29+
recomendação de investimento.

tools/seasonality_analyzer/escopo

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
market-seasonality-analyzer/ <-- Nome do Projeto
2+
├── .venv/ <-- Seu ambiente virtual
3+
├── data/ <-- Onde você guarda CSVs (se houver)
4+
├── notebooks/ <-- Seus testes e rascunhos (.ipynb)
5+
├── src/ <-- O código principal do app
6+
│ └── app.py <-- O arquivo do Streamlit
7+
├── requirements.txt <-- Lista das bibliotecas (pip freeze)
8+
└── README.md <-- A "capa" do seu projeto
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
streamlit>=1.30.0
2+
yfinance>=0.2.36
3+
pandas>=2.1.4
4+
numpy>=1.26.3
5+
plotly>=5.18.0
6+
scipy>=1.11.4
7+
python-dateutil>=2.8.2

0 commit comments

Comments
 (0)