|
| 1 | +# QuantResearchStarter |
| 2 | + |
| 3 | +[](https://www.python.org/) |
| 4 | +[](LICENSE) |
| 5 | +[](https://github.com/username/QuantResearchStarter/actions) |
| 6 | + |
| 7 | +A modular, open-source quantitative research and backtesting framework built for clarity, reproducibility, and extensibility. Ideal for researchers, students, and engineers building and testing systematic strategies. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Why this project |
| 12 | + |
| 13 | +QuantResearchStarter aims to provide a clean, well-documented starting point for quantitative research and backtesting. It focuses on: |
| 14 | + |
| 15 | +* **Readability**: idiomatic Python, type hints, and small modules you can read and change quickly. |
| 16 | +* **Testability**: deterministic vectorized backtests with unit tests and CI. |
| 17 | +* **Extensibility**: plug-in friendly factor & data adapters so you can try new ideas fast. |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Key features |
| 22 | + |
| 23 | +* **Data management** — download market data or generate synthetic price series for experiments. |
| 24 | +* **Factor library** — example implementations of momentum, value, size, and volatility factors. |
| 25 | +* **Vectorized backtesting engine** — supports transaction costs, slippage, portfolio constraints, and configurable rebalancing frequencies (daily, weekly, monthly). |
| 26 | +* **Risk & performance analytics** — returns, drawdowns, Sharpe, turnover, and other risk metrics. |
| 27 | +* **CLI & scripts** — small tools to generate data, compute factors, and run backtests from the terminal. |
| 28 | +* **Production-ready utilities** — type hints, tests, continuous integration, and documentation scaffolding. |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Quick start |
| 33 | + |
| 34 | +### Requirements |
| 35 | + |
| 36 | +* Python 3.10+ |
| 37 | +* pip |
| 38 | + |
| 39 | +### Install locally |
| 40 | + |
| 41 | +```bash |
| 42 | +# Clone the repository |
| 43 | +git clone https://github.com/username/QuantResearchStarter.git |
| 44 | +cd QuantResearchStarter |
| 45 | + |
| 46 | +# Install package in development mode |
| 47 | +pip install -e . |
| 48 | + |
| 49 | +# Install development dependencies (tests, linters, docs) |
| 50 | +pip install -e ".[dev]" |
| 51 | + |
| 52 | +# Optional UI dependencies |
| 53 | +pip install streamlit plotly |
| 54 | +``` |
| 55 | + |
| 56 | +### Quick CLI Usage |
| 57 | + |
| 58 | +After installation, you can use the CLI in two ways: |
| 59 | + |
| 60 | +**Option 1: Direct command (if PATH is configured)** |
| 61 | +```bash |
| 62 | +qrs --help |
| 63 | +# generate synthetic sample price series |
| 64 | +qrs generate-data -o data_sample/sample_prices.csv -s 5 -d 365 |
| 65 | +# compute example factors |
| 66 | +qrs compute-factors -d data_sample/sample_prices.csv -f momentum -f value -o output/factors.csv |
| 67 | +# run a backtest |
| 68 | +qrs backtest -d data_sample/sample_prices.csv -s output/factors.csv -o output/backtest_results.json |
| 69 | +``` |
| 70 | + |
| 71 | +**Option 2: Python module (always works)** |
| 72 | +```bash |
| 73 | +python -m quant_research_starter.cli --help |
| 74 | +python -m quant_research_starter.cli generate-data -o data_sample/sample_prices.csv -s 5 -d 365 |
| 75 | +python -m quant_research_starter.cli compute-factors -d data_sample/sample_prices.csv -f momentum -f value |
| 76 | +python -m quant_research_starter.cli backtest -d data_sample/sample_prices.csv -s output/factors.csv -o output/backtest_results.json |
| 77 | +``` |
| 78 | + |
| 79 | +### Demo (one-line) |
| 80 | + |
| 81 | +```bash |
| 82 | +make demo |
| 83 | +``` |
| 84 | + |
| 85 | +### Step-by-step demo |
| 86 | + |
| 87 | +```bash |
| 88 | +# generate synthetic sample price series |
| 89 | +python -m quant_research_starter.cli generate-data -o data_sample/sample_prices.csv -s 5 -d 365 |
| 90 | + |
| 91 | +# compute example factors |
| 92 | +python -m quant_research_starter.cli compute-factors -d data_sample/sample_prices.csv -f momentum -f value -o output/factors.csv |
| 93 | + |
| 94 | +# run a backtest |
| 95 | +python -m quant_research_starter.cli backtest -d data_sample/sample_prices.csv -s output/factors.csv -o output/backtest_results.json |
| 96 | + |
| 97 | +# DISCLAIMER: OLD VERSION |
| 98 | +# optional: start the Streamlit dashboard, if on main stream |
| 99 | +streamlit run src/quant_research_starter/dashboard/streamlit_app.py |
| 100 | +# NEW VERSION: if streamlit is in legacy folder |
| 101 | +streamlit run legacy/streamlit/streamlit_app.py |
| 102 | +``` |
| 103 | + |
| 104 | +--- |
| 105 | + |
| 106 | +## Example: small strategy (concept) |
| 107 | + |
| 108 | +```python |
| 109 | +from quant_research_starter.backtest import Backtester |
| 110 | +from quant_research_starter.data import load_prices |
| 111 | +from quant_research_starter.factors import Momentum |
| 112 | + |
| 113 | +prices = load_prices("data_sample/sample_prices.csv") |
| 114 | +factor = Momentum(window=63) |
| 115 | +scores = factor.compute(prices) |
| 116 | + |
| 117 | +bt = Backtester(prices, signals=scores, capital=1_000_000) |
| 118 | +results = bt.run() |
| 119 | +print(results.performance.summary()) |
| 120 | +``` |
| 121 | + |
| 122 | +### Rebalancing Frequency |
| 123 | + |
| 124 | +The backtester supports different rebalancing frequencies to match your strategy needs: |
| 125 | + |
| 126 | +```python |
| 127 | +from quant_research_starter.backtest import VectorizedBacktest |
| 128 | +# Daily rebalancing (default) |
| 129 | +bt_daily = VectorizedBacktest(prices, signals, rebalance_freq="D") |
| 130 | + |
| 131 | +# Weekly rebalancing (reduces turnover and transaction costs) |
| 132 | +bt_weekly = VectorizedBacktest(prices, signals, rebalance_freq="W") |
| 133 | + |
| 134 | +# Monthly rebalancing (lowest turnover) |
| 135 | +bt_monthly = VectorizedBacktest(prices, signals, rebalance_freq="M") |
| 136 | + |
| 137 | +results = bt_monthly.run() |
| 138 | +``` |
| 139 | + |
| 140 | +Supported frequencies: |
| 141 | +- `"D"`: Daily rebalancing (default) |
| 142 | +- `"W"`: Weekly rebalancing (rebalances when the week changes) |
| 143 | +- `"M"`: Monthly rebalancing (rebalances when the month changes) |
| 144 | + |
| 145 | +> The code above is illustrative—see `examples/` for fully working notebooks and scripts. |
| 146 | +
|
| 147 | +--- |
| 148 | + |
| 149 | +## CLI reference |
| 150 | + |
| 151 | +Run `python -m quant_research_starter.cli --help` or `python -m quant_research_starter.cli <command> --help` for full usage. Main commands include: |
| 152 | + |
| 153 | +* `python -m quant_research_starter.cli generate-data` — create synthetic price series or download data from adapters |
| 154 | +* `python -m quant_research_starter.cli compute-factors` — calculate and export factor scores |
| 155 | +* `python -m quant_research_starter.cli backtest` — run the vectorized backtest and export results |
| 156 | + |
| 157 | +**Note:** If you have the `qrs` command in your PATH, you can use `qrs` instead of `python -m quant_research_starter.cli`. |
| 158 | + |
| 159 | +--- |
| 160 | + |
| 161 | +## Project structure (overview) |
| 162 | + |
| 163 | +``` |
| 164 | +QuantResearchStarter/ |
| 165 | +├─ src/quant_research_starter/ |
| 166 | +│ ├─ data/ # data loaders & adapters |
| 167 | +│ ├─ factors/ # factor implementations |
| 168 | +│ ├─ backtest/ # backtester & portfolio logic |
| 169 | +│ ├─ analytics/ # performance and risk metrics |
| 170 | +│ ├─ cli/ # command line entry points |
| 171 | +│ └─ dashboard/ # optional Streamlit dashboard |
| 172 | +├─ examples/ # runnable notebooks & example strategies |
| 173 | +├─ tests/ # unit + integration tests |
| 174 | +└─ docs/ # documentation source |
| 175 | +``` |
| 176 | + |
| 177 | +--- |
| 178 | + |
| 179 | +## Tests & CI |
| 180 | + |
| 181 | +We include unit tests and a CI workflow (GitHub Actions). Run tests locally with: |
| 182 | + |
| 183 | +```bash |
| 184 | +pytest -q |
| 185 | +``` |
| 186 | + |
| 187 | +The CI pipeline runs linting, unit tests, and builds docs on push/PR. |
| 188 | + |
| 189 | +--- |
| 190 | + |
| 191 | +## Contributing |
| 192 | + |
| 193 | +Contributions are very welcome. Please follow these steps: |
| 194 | + |
| 195 | +1. Fork the repository |
| 196 | +2. Create a feature branch |
| 197 | +3. Add tests for new behavior |
| 198 | +4. Open a pull request with a clear description and rationale |
| 199 | + |
| 200 | +Please review `CONTRIBUTING.md` and the `CODE_OF_CONDUCT.md` before submitting. |
| 201 | + |
| 202 | +--- |
| 203 | + |
| 204 | +## AI policy — short & practical |
| 205 | + |
| 206 | +**Yes — you are allowed to use AI tools** (ChatGPT, Copilot, Codeium, etc.) to help develop, prototype, or document code in this repository. |
| 207 | + |
| 208 | +A few friendly guidelines: |
| 209 | + |
| 210 | +* **Be transparent** when a contribution is substantially generated by an AI assistant — add a short note in the PR or commit message (e.g., "Generated with ChatGPT; reviewed and adapted by <your-name>"). |
| 211 | +* **Review and test** all AI-generated code. Treat it as a helpful draft, not final production-quality code. |
| 212 | +* **Follow licensing** and attribution rules for any external snippets the AI suggests. Don’t paste large verbatim copyrighted material. |
| 213 | +* **Security & correctness**: double-check numerical logic, data handling, and anything that affects trading decisions. |
| 214 | + |
| 215 | +This policy is intentionally permissive: we want the community to move fast while keeping quality and safety in mind. |
| 216 | + |
| 217 | +--- |
| 218 | + |
| 219 | +## License |
| 220 | + |
| 221 | +This project is licensed under the MIT License — see the `LICENSE` file for details. |
| 222 | + |
| 223 | +--- |
| 224 | + |
| 225 | +## Acknowledgements |
| 226 | + |
| 227 | +Built with inspiration from open-source quant libraries and the research community. If you use this project in papers or public work, a short citation or mention is appreciated. |
0 commit comments