Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9f99632
feat: optimize idiosyncratic volatility factor using vectorized covar…
adityacosmos24 Oct 26, 2025
af12d1a
feat: Reorder imports in benchmark_factors.py
adityacosmos24 Oct 26, 2025
327c549
feat: refactor volatility factors for production readiness
adityacosmos24 Oct 26, 2025
18fe964
remove unused import of warnings module
adityacosmos24 Oct 26, 2025
a4fecd2
feat: fixed errors
adityacosmos24 Oct 26, 2025
e6456f6
Merge branch 'aditya' of https://github.com/adityacosmos24/QuantResea…
adityacosmos24 Oct 26, 2025
33626dc
remove unused import in volatility.py
adityacosmos24 Oct 26, 2025
e0436fb
errors
adityacosmos24 Oct 26, 2025
485151d
Merge branch 'aditya' of https://github.com/adityacosmos24/QuantResea…
adityacosmos24 Oct 26, 2025
8c54477
errors
adityacosmos24 Oct 26, 2025
7dbdd60
fix: sort imports with Ruff
adityacosmos24 Oct 26, 2025
b70d514
format code with black
adityacosmos24 Oct 26, 2025
83f8e31
feat: added setuptools poetry entrypoint
adityacosmos24 Oct 27, 2025
badb979
chore: update readme with new command syntax and paths
adityacosmos24 Oct 27, 2025
c8c5596
Merge branch 'main' into aditya
adityacosmos24 Oct 27, 2025
50f717d
chore: updated gitignore
adityacosmos24 Oct 27, 2025
cfe2ec9
Merge branch 'aditya' of https://github.com/adityacosmos24/QuantResea…
adityacosmos24 Oct 27, 2025
dd8b845
docs: duplicates removed
ayushkrtiwari Oct 27, 2025
77b56b6
docs: fix typo error
ayushkrtiwari Oct 27, 2025
e140970
docs: added description
ayushkrtiwari Oct 27, 2025
2f2bf84
docs: fixed path issue
ayushkrtiwari Oct 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ pip install -e ".[dev]"
pip install streamlit plotly
```

### Quick CLI Usage

After installation, you can use the CLI in two ways:

**Option 1: Direct command (if PATH is configured)**
```bash
qrs --help
qrs generate-data -o data/sample.csv -s 5 -d 365
qrs compute-factors -d data/sample.csv -f momentum -f value
qrs backtest -d data/sample.csv -s output/factors.csv
```

**Option 2: Python module (always works)**
```bash
python -m quant_research_starter.cli --help
python -m quant_research_starter.cli generate-data -o data/sample.csv -s 5 -d 365
python -m quant_research_starter.cli compute-factors -d data/sample.csv -f momentum -f value
python -m quant_research_starter.cli backtest -d data/sample.csv -s output/factors.csv
```

### Demo (one-line)

```bash
Expand All @@ -63,13 +83,13 @@ make demo

```bash
# generate synthetic sample price series
qrs generate-data -o data_sample/sample_prices.csv -s 5 -d 365
python -m quant_research_starter.cli generate-data -o data_sample/sample_prices.csv -s 5 -d 365

# compute example factors
qrs compute-factors -d data_sample/sample_prices.csv -f momentum -f value -o output/factors.csv
python -m quant_research_starter.cli compute-factors -d data_sample/sample_prices.csv -f momentum -f value -o output/factors.csv

# run a backtest
qrs backtest -d data_sample/sample_prices.csv -s output/factors.csv -o output/backtest_results.json
python -m quant_research_starter.cli backtest -d data_sample/sample_prices.csv -s output/factors.csv -o output/backtest_results.json

# optional: start the Streamlit dashboard
streamlit run src/quant_research_starter/dashboard/streamlit_app.py
Expand Down Expand Up @@ -99,11 +119,13 @@ print(results.performance.summary())

## CLI reference

Run `qrs --help` or `qrs <command> --help` for full usage. Main commands include:
Run `python -m quant_research_starter.cli --help` or `python -m quant_research_starter.cli <command> --help` for full usage. Main commands include:

* `python -m quant_research_starter.cli generate-data` β€” create synthetic price series or download data from adapters
* `python -m quant_research_starter.cli compute-factors` β€” calculate and export factor scores
* `python -m quant_research_starter.cli backtest` β€” run the vectorized backtest and export results

* `qrs generate-data` β€” create synthetic price series or download data from adapters
* `qrs compute-factors` β€” calculate and export factor scores
* `qrs backtest` β€” run the vectorized backtest and export results
**Note:** If you have the `qrs` command in your PATH, you can use `qrs` instead of `python -m quant_research_starter.cli`.

---

Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ qrs = "quant_research_starter.cli:cli"
requires = ["setuptools>=45", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-dir]
"" = "src"

[tool.black]
line-length = 88
target-version = ['py310']
Expand Down
173 changes: 159 additions & 14 deletions src/quant_research_starter.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,43 @@ Dynamic: license-file

# QuantResearchStarter

A modular, open-source quantitative research and backtesting framework designed for clarity and extensibility. Perfect for researchers, students, and developers interested in quantitative finance.

![Python Version](https://img.shields.io/badge/python-3.10%2B-blue)
![License](https://img.shields.io/badge/license-MIT-green)
[![Python Version](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/)
[![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
[![CI](https://github.com/username/QuantResearchStarter/actions/workflows/ci.yml/badge.svg)](https://github.com/username/QuantResearchStarter/actions)

## Features
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.

---

## Why this project

QuantResearchStarter aims to provide a clean, well-documented starting point for quantitative research and backtesting. It focuses on:

* **Readability**: idiomatic Python, type hints, and small modules you can read and change quickly.
* **Testability**: deterministic vectorized backtests with unit tests and CI.
* **Extensibility**: plug-in friendly factor & data adapters so you can try new ideas fast.

---

## Key features

- **Data Management**: Download real data or generate synthetic data for testing
- **Factor Library**: Implement momentum, value, size, and volatility factors
- **Backtesting Engine**: Vectorized backtester with transaction costs and constraints
- **Risk Metrics**: Comprehensive performance and risk analytics
- **Modular Design**: Easy to extend with new factors and strategies
- **Production Ready**: Type hints, tests, CI/CD, and documentation
* **Data management** β€” download market data or generate synthetic price series for experiments.
* **Factor library** β€” example implementations of momentum, value, size, and volatility factors.
* **Vectorized backtesting engine** β€” supports transaction costs, slippage, and portfolio constraints.
* **Risk & performance analytics** β€” returns, drawdowns, Sharpe, turnover, and other risk metrics.
* **CLI & scripts** β€” small tools to generate data, compute factors, and run backtests from the terminal.
* **Production-ready utilities** β€” type hints, tests, continuous integration, and documentation scaffolding.

## Quick Start
---

### Installation
## Quick start

### Requirements

* Python 3.10+
* pip

### Install locally

```bash
# Clone the repository
Expand All @@ -70,5 +89,131 @@ cd QuantResearchStarter
# Install package in development mode
pip install -e .

# Install development dependencies
# Install development dependencies (tests, linters, docs)
pip install -e ".[dev]"

# Optional UI dependencies
pip install streamlit plotly
```

### Demo (one-line)

```bash
make demo
```

### Step-by-step demo

```bash
# generate synthetic sample price series
qrs generate-data -o data_sample/sample_prices.csv -s 5 -d 365

# compute example factors
qrs compute-factors -d data_sample/sample_prices.csv -f momentum -f value -o output/factors.csv

# run a backtest
qrs backtest -d data_sample/sample_prices.csv -s output/factors.csv -o output/backtest_results.json

# optional: start the Streamlit dashboard
streamlit run src/quant_research_starter/dashboard/streamlit_app.py
```

---

## Example: small strategy (concept)

```python
from quant_research_starter.backtest import Backtester
from quant_research_starter.data import load_prices
from quant_research_starter.factors import Momentum

prices = load_prices("data_sample/sample_prices.csv")
factor = Momentum(window=63)
scores = factor.compute(prices)

bt = Backtester(prices, signals=scores, capital=1_000_000)
results = bt.run()
print(results.performance.summary())
```

> The code above is illustrativeβ€”see `examples/` for fully working notebooks and scripts.

---

## CLI reference

Run `qrs --help` or `qrs <command> --help` for full usage. Main commands include:

* `qrs generate-data` β€” create synthetic price series or download data from adapters
* `qrs compute-factors` β€” calculate and export factor scores
* `qrs backtest` β€” run the vectorized backtest and export results

---

## Project structure (overview)

```
QuantResearchStarter/
β”œβ”€ src/quant_research_starter/
β”‚ β”œβ”€ data/ # data loaders & adapters
β”‚ β”œβ”€ factors/ # factor implementations
β”‚ β”œβ”€ backtest/ # backtester & portfolio logic
β”‚ β”œβ”€ analytics/ # performance and risk metrics
β”‚ β”œβ”€ cli/ # command line entry points
β”‚ └─ dashboard/ # optional Streamlit dashboard
β”œβ”€ examples/ # runnable notebooks & example strategies
β”œβ”€ tests/ # unit + integration tests
└─ docs/ # documentation source
```

---

## Tests & CI

We include unit tests and a CI workflow (GitHub Actions). Run tests locally with:

```bash
pytest -q
```

The CI pipeline runs linting, unit tests, and builds docs on push/PR.

---

## Contributing

Contributions are very welcome. Please follow these steps:

1. Fork the repository
2. Create a feature branch
3. Add tests for new behavior
4. Open a pull request with a clear description and rationale

Please review `CONTRIBUTING.md` and the `CODE_OF_CONDUCT.md` before submitting.

---

## AI policy β€” short & practical

**Yes β€” you are allowed to use AI tools** (ChatGPT, Copilot, Codeium, etc.) to help develop, prototype, or document code in this repository.

A few friendly guidelines:

* **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>").
* **Review and test** all AI-generated code. Treat it as a helpful draft, not final production-quality code.
* **Follow licensing** and attribution rules for any external snippets the AI suggests. Don’t paste large verbatim copyrighted material.
* **Security & correctness**: double-check numerical logic, data handling, and anything that affects trading decisions.

This policy is intentionally permissive: we want the community to move fast while keeping quality and safety in mind.

---

## License

This project is licensed under the MIT License β€” see the `LICENSE` file for details.

---

## Acknowledgements

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.
3 changes: 3 additions & 0 deletions src/quant_research_starter.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ src/quant_research_starter.egg-info/requires.txt
src/quant_research_starter.egg-info/top_level.txt
src/quant_research_starter/backtest/__init__.py
src/quant_research_starter/backtest/vectorized.py
src/quant_research_starter/dashboard/streamlit_app.py
src/quant_research_starter/data/__init__.py
src/quant_research_starter/data/downloaders.py
src/quant_research_starter/data/init.py
src/quant_research_starter/data/sample_loader.py
src/quant_research_starter/data/synthetic.py
src/quant_research_starter/examples/benchmark/benchmark_factors.py
src/quant_research_starter/factors/__init__.py
src/quant_research_starter/factors/base.py
src/quant_research_starter/factors/bollinger.py
src/quant_research_starter/factors/init.py
src/quant_research_starter/factors/momentum.py
src/quant_research_starter/factors/size.py
Expand Down
67 changes: 67 additions & 0 deletions src/quant_research_starter/examples/benchmark/benchmark_factors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Benchmark script to compare performance of factor computations.

Usage:
python examples/benchmarks/benchmark_factors.py
"""

import time

import numpy as np
import pandas as pd

from quant_research_starter.factors import (
BollingerBandsFactor,
IdiosyncraticVolatility,
MomentumFactor,
SizeFactor,
ValueFactor,
VolatilityFactor,
)


def generate_synthetic_prices(
n_assets: int = 500, n_days: int = 252 * 3
) -> pd.DataFrame:
"""Generate synthetic random walk price data for testing."""
np.random.seed(42)
returns = np.random.normal(0, 0.01, size=(n_days, n_assets))
prices = 100 * np.exp(np.cumsum(returns, axis=0))
dates = pd.date_range(end=pd.Timestamp.today(), periods=n_days, freq="B")
tickers = [f"Stock_{i:03d}" for i in range(n_assets)]
return pd.DataFrame(prices, index=dates, columns=tickers)


def benchmark_factor(factor, prices: pd.DataFrame):
"""Benchmark runtime of a given factor."""
start = time.time()
_ = factor.compute(prices)
end = time.time()
elapsed = end - start
print(
f"{factor.name:<25} | Lookback: {factor.lookback:<5} | Time: {elapsed:.3f} sec"
)


def main():
print("Generating synthetic data...")
prices = generate_synthetic_prices(n_assets=500, n_days=252 * 3)
print(f"Data shape: {prices.shape}")

print("\nRunning factor benchmarks...\n")

factors = [
MomentumFactor(lookback=63),
ValueFactor(),
SizeFactor(),
VolatilityFactor(lookback=21),
IdiosyncraticVolatility(lookback=63),
BollingerBandsFactor(lookback=20),
]

for factor in factors:
benchmark_factor(factor, prices)


if __name__ == "__main__":
main()
Loading