This guide will help you set up and run FARP (Financial Analytics & Risk Pipeline) on your local machine.
Before you begin, ensure you have the following installed:
| Requirement | Version | Purpose |
|---|---|---|
| Python | 3.11+ | Core runtime |
| Docker | Latest | PostgreSQL container |
| Docker Compose | Latest | Container orchestration |
| Git | Latest | Version control |
git clone <repository-url>
cd farpWindows:
python -m venv venv
venv\Scripts\activateLinux/macOS:
python -m venv venv
source venv/bin/activatepip install -r requirements.txtCopy the example environment file and customize as needed:
Windows:
copy .env.example .envLinux/macOS:
cp .env.example .envEdit .env to configure:
- Database credentials
- API settings
- Risk parameters
See Configuration Reference for all options.
Using Docker Compose:
docker-compose up -dThis starts:
- PostgreSQL 15 on port
5432 - pgAdmin on port
5050(optional, use--profile tools)
docker-compose psEnsure the farp_postgres container is running and healthy.
python scripts/init_db.pyThis creates all required tables in the database.
To populate the database with sample data for testing:
python scripts/seed_data.pyThis creates:
- 13 demo instruments (equities, crypto, FX)
- 30 days of price history
- 30 days of FX rates
- ~100 sample trades
uvicorn src.api.main:app --reload --port 8000The API will be available at:
- API Base: http://localhost:8000
- Swagger Docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
In a separate terminal:
streamlit run dashboard/app.py --server.port 8501The dashboard will be available at: http://localhost:8501
For automated background jobs:
python -m src.scheduler.runnerThis enables:
- Price updates every 5 minutes
- FX rate updates every 15 minutes
- Position snapshots every 30 minutes
- End-of-day processing at market close
curl http://localhost:8000/healthExpected response:
{
"status": "healthy",
"database": "connected",
"timestamp": "2024-01-15T12:00:00Z"
}curl http://localhost:8000/Expected response:
{
"name": "FARP - Financial Analytics & Risk Pipeline",
"version": "0.1.0",
"docs": "/docs",
"health": "/health"
}curl -X POST http://localhost:8000/api/v1/trades \
-H "Content-Type: application/json" \
-d '{
"external_id": "TEST001",
"symbol": "AAPL",
"side": "BUY",
"quantity": 100,
"price": 185.50,
"currency": "USD"
}'Here's a complete Python example to get you started:
import requests
API_BASE = "http://localhost:8000/api/v1"
# 1. Submit a trade
trade = {
"external_id": "TRADE001",
"symbol": "AAPL",
"side": "BUY",
"quantity": 100,
"price": 185.50,
"currency": "USD"
}
response = requests.post(f"{API_BASE}/trades", json=trade)
print("Trade submitted:", response.json())
# 2. Get positions
positions = requests.get(f"{API_BASE}/positions")
print("Current positions:", positions.json())
# 3. Get portfolio summary
summary = requests.get(f"{API_BASE}/positions/summary")
print("Portfolio summary:", summary.json())
# 4. Get PnL
pnl = requests.get(f"{API_BASE}/positions/pnl/summary")
print("PnL summary:", pnl.json())
# 5. Get risk metrics
risk = requests.get(f"{API_BASE}/risk/metrics")
print("Risk metrics:", risk.json())- Ensure Docker is running
- Check if PostgreSQL container is healthy:
docker-compose ps - Verify
.envdatabase settings matchdocker-compose.yml
Change the port in your command:
uvicorn src.api.main:app --reload --port 8001
streamlit run dashboard/app.py --server.port 8502Ensure you're in the project root and virtual environment is activated:
cd farp
venv\Scripts\activate # Windows
source venv/bin/activate # Linux/macOS- Architecture Overview - Understand the system design
- API Reference - Explore all API endpoints
- Configuration - Customize FARP settings
- Dashboard Guide - Learn the dashboard features