Skip to content

Commit 9da3917

Browse files
perf: optimise volatility factor implementation
Optimised volatility codebase implementation
1 parent d0d1d26 commit 9da3917

File tree

4 files changed

+146
-7
lines changed

4 files changed

+146
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules
44
__pycache__/
55
*.py[cod]
66
*$py.class
7+
src/quant_research_starter.egg-info/PKG-INFO

README.md

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ pip install -e ".[dev]"
5353
pip install streamlit plotly
5454
```
5555

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+
5679
### Demo (one-line)
5780

5881
```bash
@@ -63,13 +86,13 @@ make demo
6386

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

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

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

7497
# optional: start the Streamlit dashboard
7598
streamlit run src/quant_research_starter/dashboard/streamlit_app.py
@@ -123,11 +146,13 @@ Supported frequencies:
123146

124147
## CLI reference
125148

126-
Run `qrs --help` or `qrs <command> --help` for full usage. Main commands include:
149+
Run `python -m quant_research_starter.cli --help` or `python -m quant_research_starter.cli <command> --help` for full usage. Main commands include:
150+
151+
* `python -m quant_research_starter.cli generate-data` — create synthetic price series or download data from adapters
152+
* `python -m quant_research_starter.cli compute-factors` — calculate and export factor scores
153+
* `python -m quant_research_starter.cli backtest` — run the vectorized backtest and export results
127154

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

132157
---
133158

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ qrs = "quant_research_starter.cli:cli"
5959
requires = ["setuptools>=45", "wheel"]
6060
build-backend = "setuptools.build_meta"
6161

62+
[tool.setuptools.packages.find]
63+
where = ["src"]
64+
65+
[tool.setuptools.package-dir]
66+
"" = "src"
67+
6268
[tool.black]
6369
line-length = 88
6470
target-version = ['py310']

test_cli.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Simple test script for QuantResearch CLI
4+
This demonstrates all the CLI functionality
5+
"""
6+
7+
import subprocess
8+
import sys
9+
from pathlib import Path
10+
11+
12+
def run_command(cmd):
13+
"""Run a command and print the result"""
14+
print(f"\n{'='*60}")
15+
print(f"Running: {cmd}")
16+
print('='*60)
17+
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
18+
19+
if result.stdout:
20+
print(result.stdout)
21+
if result.stderr and result.returncode != 0:
22+
print(f"ERROR: {result.stderr}")
23+
return False
24+
25+
return result.returncode == 0
26+
27+
28+
def main():
29+
"""Run all CLI tests"""
30+
print("\n🧪 Testing QuantResearch CLI")
31+
print("="*60)
32+
33+
# Define test directories
34+
test_data_dir = Path("test_data")
35+
test_output_dir = Path("test_output")
36+
37+
# Create test directories
38+
test_data_dir.mkdir(exist_ok=True)
39+
test_output_dir.mkdir(exist_ok=True)
40+
41+
# Test 1: Show help
42+
success = run_command("python -m quant_research_starter.cli --help")
43+
if not success:
44+
print("\n❌ Test 1 FAILED: Help command")
45+
sys.exit(1)
46+
47+
# Test 2: Generate data
48+
success = run_command(
49+
"python -m quant_research_starter.cli generate-data "
50+
"-o test_data/data.csv -s 5 -d 100"
51+
)
52+
if not success:
53+
print("\n❌ Test 2 FAILED: Generate data")
54+
sys.exit(1)
55+
56+
# Test 3: Compute factors
57+
success = run_command(
58+
"python -m quant_research_starter.cli compute-factors "
59+
"-d test_data/data.csv -f momentum -f value -o test_output/factors.csv"
60+
)
61+
if not success:
62+
print("\n❌ Test 3 FAILED: Compute factors")
63+
sys.exit(1)
64+
65+
# Test 4: Run backtest
66+
success = run_command(
67+
"python -m quant_research_starter.cli backtest "
68+
"-d test_data/data.csv -s test_output/factors.csv "
69+
"-o test_output/backtest_results.json"
70+
)
71+
if not success:
72+
print("\n❌ Test 4 FAILED: Run backtest")
73+
sys.exit(1)
74+
75+
# Verify output files exist
76+
print("\n📁 Checking output files...")
77+
files_to_check = [
78+
test_data_dir / "data.csv",
79+
test_output_dir / "factors.csv",
80+
test_output_dir / "backtest_results.json",
81+
test_output_dir / "backtest_plot.png"
82+
]
83+
84+
all_exist = True
85+
for file_path in files_to_check:
86+
if file_path.exists():
87+
print(f"✅ {file_path} exists ({file_path.stat().st_size} bytes)")
88+
else:
89+
print(f"❌ {file_path} missing!")
90+
all_exist = False
91+
92+
if not all_exist:
93+
print("\n❌ Some output files are missing")
94+
sys.exit(1)
95+
96+
# Summary
97+
print("\n" + "="*60)
98+
print("✅ ALL TESTS PASSED!")
99+
print("="*60)
100+
print(f"\n📂 Test files created in:")
101+
print(f" - {test_data_dir}/")
102+
print(f" - {test_output_dir}/")
103+
print("\n💡 You can view the results and plots in the test_output directory.")
104+
105+
106+
if __name__ == "__main__":
107+
main()

0 commit comments

Comments
 (0)