End-to-End Asset Allocation Platform with FastAPI + React (TypeScript)
This project is a full-stack quantitative asset allocation system that combines:
- ๐ Python-based portfolio & momentum backtesting
- โ๏ธ FastAPI backend API
- ๐ฅ๏ธ React + TypeScript frontend
- ๐ฆ Rate-limited endpoints
- ๐ค CSV export for results
- ๐ Extensible architecture for future models
The system allows users to run asset allocation strategies via a REST API and visualize results through a modern web UI.
- Momentum-based asset allocation
- Moving-average crossover strategies
- Portfolio performance metrics (Sharpe, volatility)
- Separation of quant logic from API and UI
- REST API for running allocation/backtests
- Modular Python architecture
- Rate-limited endpoints (API abuse protection)
- CSV export of transactions & portfolio results
- Clean request/response schemas (Pydantic)
๐ Database SchemaThe application uses PostgreSQL to persist backtest results. The schema is automatically managed by SQLAlchemy.
| id | symbol | sharpe | volatility | final_value | created_at |
|---|---|---|---|---|---|
| 1 | GOOGL | 2.37 | 0.251 | $178,033.04 | 2026-01-07 10:00:00 |
| 2 | NVDA | 1.04 | 0.228 | $125,781.71 | 2026-01-07 10:05:30 |
| 3 | MSFT | 0.56 | 0.120 | $108,203.76 | 2026-01-07 10:10:15 |
Getting Started
-
Environment SetupCreate a .env file in the root directory.
-
Code snippetDATABASE_URL
postgresql://postgres:postgres@db:5432/postgres- Run with DockerThis will launch the Postgres database, the FastAPI backend, and the React frontend simultaneously:
docker-compose up --build - Modern Vite-based React app
- Component-based UI (Header, Footer, Pages)
- API service abstraction
- Extensible for charts & dashboards
- Clean separation of concerns
- Recharts to visualize backtest
-
Historical price data via
yfinance -
Momentum strategy with:
- Short/long moving averages
- Market regime filter (ACWI)
-
Backtest engine with:
- Transaction tracking
- Sharpe ratio
- Volatility
-
CSV export for offline analysis
algoallocationbot/
โ
โโโ backend/
โ โโโ app/
โ โ โโโ main.py # FastAPI entry point
โ โ โโโ assetbot.py # Core backtest & allocation logic
โ โ โโโ schemas.py # Request/response models
โ โ โโโ rate_limit.py # API rate limiting
| | |โโ database.py # database
| | |โโ models.py # for database models
โ โ โโโ __init__.py
โ โโโ requirements.txt
โ
โโโ frontend/
โ โโโ asset-ui/
โ โโโ src/
โ โ โโโ components/ # Header, Footer, UI components
โ โ โโโ pages/ # Home, future views
โ โ โโโ services/ # API calls
โ โ โโโ App.tsx
โ โ โโโ main.tsx
โ โโโ package.json
โ
โโโ README.md
|โโ docker-compose.yml #postgres database in docker
โโโ .gitignore
- Python 3.9+
- FastAPI
- Pydantic
- yfinance
- pandas / numpy
- Uvicorn
- React
- TypeScript
- Vite
- Axios / Fetch API
- Yahoo Finance (market data)
- CSV exports
- PostgreSQL
git clone https://github.com/your-username/algoallocationbot.git
cd algoallocationbotcd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtStart the API:
uvicorn app.main:app --reloadAPI docs available at:
http://localhost:8000/docs
cd frontend/asset-ui
npm install
npm run devFrontend runs at:
http://localhost:5173
This project uses Recharts to visualize historical stock prices and backtest results.Recharts is a React-based charting library built on SVG. It is lightweight, composable, and works well with responsive dashboards.
<ResponsiveContainer width="100%" aspect={3}>
<LineChart data={data}>
<Line dataKey="price" />
</LineChart>
</ResponsiveContainer>Runs an asset allocation/backtest.
Request
{
"symbol": "AAPL",
"initial_money": 100000
}Response
{
"symbol": "AAPL",
"sharpe": 1.42,
"volatility": 0.18,
"final_account_value": 132450,
"transactions": {...}
}-
Portfolio transactions can be exported as CSV
-
Useful for:
- Excel analysis
- Research notebooks
- Auditing strategies
- API endpoints are rate-limited
- Prevents abuse and accidental overload
- Ready for production hardening
-
Feature branches (
feature/ui-fastapi-react) -
Pull Requests with code reviews
-
Clean separation between:
- Quant logic
- API layer
- UI layer
- PostgreSQL integration
- Multi-asset portfolios
- User authentication
- Async backtests
- Caching (Redis)
- Strategy parameter controls
- Risk parity
- CVaR optimization
- BlackโLitterman
- Reinforcement learning allocation
Contributions are welcome!
- Fork the repo
- Create a feature branch
- Commit with clear messages
- Open a Pull Request with context
MIT License โ free to use, modify, and distribute.
If you want, next I can:
- โจ Add badges (FastAPI, React, License)
- ๐ Add architecture diagram
- ๐งช Add example API calls
- ๐ Shorten it for recruiters
- ๐ง Make a technical deep-dive README