Skip to content

Conversation

@adityacosmos24
Copy link
Contributor

@adityacosmos24 adityacosmos24 commented Oct 27, 2025

📋 Summary

This PR implements a CLI entrypoint for the QuantResearch package, allowing users to install the package with pip install . and run CLI commands via python -m quant_research_starter.cli or the qrs command.

🎯 Issue Addressed

Resolves the feature request to add setuptools/poetry entrypoint so users can pip install . and run quant-starter or similar CLI command.

Labels: packaging, enhancement, easy

🔧 Changes Made

1. Package Configuration (pyproject.toml)

  • ✅ Fixed package structure configuration in root pyproject.toml
  • ✅ Added [tool.setuptools.packages.find] to properly locate packages in src/ layout
  • ✅ Added [tool.setuptools.package-dir] to map the root package properly
  • ✅ CLI entrypoint already configured as qrs = "quant_research_starter.cli:cli"

2. Documentation Updates (README.md)

  • ✅ Added "Quick CLI Usage" section with two installation methods
  • ✅ Updated step-by-step demo with correct CLI commands
  • ✅ Updated CLI reference section with proper usage examples
  • ✅ Added note about PATH configuration for the qrs command

3. Testing Infrastructure

  • ✅ Created test_cli.py automated test script
  • ✅ Verified all CLI commands work end-to-end

📦 Installation

After merging this PR, users can:

# Clone and install
git clone <repo-url>
cd QuantResearch_Opcode
pip install -e .

# Or just install
pip install -e .

🚀 Usage

Option 1: Python Module (Recommended - Always Works)

# Show help
python -m quant_research_starter.cli --help

# Generate synthetic data
python -m quant_research_starter.cli generate-data -o data.csv -s 5 -d 100

# Compute factors
python -m quant_research_starter.cli compute-factors -d data.csv -f momentum -f value -o factors.csv

# Run backtest
python -m quant_research_starter.cli backtest -d data.csv -s factors.csv -o results.json

Option 2: Direct Command (If PATH is Configured)

qrs --help
qrs generate-data -o data.csv -s 5 -d 100
qrs compute-factors -d data.csv -f momentum -f value -o factors.csv
qrs backtest -d data.csv -s factors.csv -o results.json

🧪 Testing Instructions

Automated Testing

Run the comprehensive test script:

python test_cli.py

This will:

  1. ✅ Test CLI help command
  2. ✅ Generate synthetic data (5 symbols, 100 days)
  3. ✅ Compute momentum and value factors
  4. ✅ Run a complete backtest
  5. ✅ Verify all output files are created
  6. ✅ Show a summary of results

Manual Testing

Test each command individually:

1. Test help commands:

python -m quant_research_starter.cli --help
python -m quant_research_starter.cli generate-data --help
python -m quant_research_starter.cli compute-factors --help
python -m quant_research_starter.cli backtest --help

2. Test data generation:

python -m quant_research_starter.cli generate-data -o test_data.csv -s 10 -d 365
# Verify: test_data.csv should contain 10 symbols with 365 days of data

3. Test factor computation:

python -m quant_research_starter.cli compute-factors \
  -d test_data.csv \
  -f momentum -f value -f size -f volatility \
  -o test_factors.csv
# Verify: test_factors.csv should contain factor scores

4. Test backtest:

python -m quant_research_starter.cli backtest \
  -d test_data.csv \
  -s test_factors.csv \
  -o test_results.json
# Verify: test_results.json and backtest_plot.png should be created

Expected Output

When running the backtest, you should see:

Running backtest...
Backtest completed!
Final portfolio value: $943,186.41
Total return: -5.68%
Sharpe ratio: -0.97
Results saved -> test_results.json
Plot saved -> backtest_plot.png

Verification Checklist

  • pip install -e . completes without errors
  • python -m quant_research_starter.cli --help shows the help menu
  • generate-data command creates a CSV file
  • compute-factors command creates a CSV with factor scores
  • backtest command creates JSON results and PNG plot
  • All output files have non-zero size
  • Backtest results contain valid metrics (returns, Sharpe ratio, etc.)

📊 Example Workflow

Complete end-to-end workflow:

# 1. Install package
cd QuantResearch_Opcode
pip install -e .

# 2. Generate sample data
python -m quant_research_starter.cli generate-data -o sample_data.csv -s 10 -d 365

# 3. Compute factors
python -m quant_research_starter.cli compute-factors \
  -d sample_data.csv \
  -f momentum -f value \
  -o factors.csv

# 4. Run backtest
python -m quant_research_starter.cli backtest \
  -d sample_data.csv \
  -s factors.csv \
  -o backtest_results.json

# 5. View results
# - Open backtest_results.json to see metrics
# - Open backtest_plot.png to see portfolio performance

🐛 Known Issues / Notes

  1. PATH Warning: On Windows, you may see a warning about the scripts directory not being in PATH. The python -m method works regardless.
  2. First Run: The first CLI command may take a moment as matplotlib builds its font cache.
  3. Negative Returns: The example backtest shows negative returns - this is expected with synthetic data and basic strategies.

📝 Files Changed

  • pyproject.toml - Fixed package configuration
  • README.md - Updated usage documentation
  • test_cli.py - New automated test script
  • src/pyproject.toml - Removed (duplicate file)

✨ Benefits

  1. Better Developer Experience: Users can now install and run the CLI in one command
  2. Standard Python Packaging: Follows modern Python packaging best practices
  3. Flexible Usage: Two ways to run commands (module or direct)
  4. Well Documented: Clear instructions for installation and usage
  5. Tested: Comprehensive automated and manual tests

🔍 Screenshots

Add screenshots of the CLI in action if desired

📚 Related Documentation

  • README.md - Updated with CLI usage instructions
  • test_cli.py - Automated test suite
  • Original issue description

✅ Checklist

  • Code follows project style guidelines
  • Documentation updated
  • Tests added/updated
  • All tests pass
  • No breaking changes
  • Installation tested on clean environment
  • CLI commands verified to work

👥 Reviewers

Please pay special attention to:

  1. Package configuration in pyproject.toml
  2. CLI usage examples in README
  3. Test script comprehensiveness

issue resloved #13

Ready for Review 🚀

@ayushkrtiwari ayushkrtiwari requested a review from Copilot October 27, 2025 19:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a CLI entrypoint for the QuantResearch package, enabling users to install with pip install . and run commands via python -m quant_research_starter.cli or the qrs command. The PR fixes package discovery configuration and updates documentation to reflect the new CLI usage patterns.

Key Changes:

  • Fixed package structure configuration in pyproject.toml to properly locate packages in src/ layout
  • Updated README.md with comprehensive CLI usage instructions and examples
  • Added automated test script (test_cli.py) for end-to-end CLI validation

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pyproject.toml Added setuptools configuration for package discovery in src/ layout
README.md Updated CLI usage examples and instructions throughout documentation
test_cli.py New automated test script for CLI functionality validation
src/quant_research_starter/factors/volatility.py Refactored volatility factor implementations with vectorized operations
src/quant_research_starter/examples/benchmark/benchmark_factors.py New benchmark script for factor performance comparison
src/quant_research_starter.egg-info/SOURCES.txt Updated package source file listing
src/quant_research_starter.egg-info/PKG-INFO Updated package metadata and documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 11 to 18
- Proper `__init__` usage.
- Min_periods set on rolling operations; trimming of initial rows to avoid
ambiguous partial-window values.
- Guarding divide-by-zero when computing beta (market variance).
- Consistent handling for single-column (single-asset) DataFrames.
- Preserves DataFrame output shape/columns and sets self._values.
- Uses ddof=0 for rolling std/var to match population estimates (consistent &
fast).
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected capitalization of 'min_periods' to 'Min_periods'.

Copilot uses AI. Check for mistakes.
returns = prices.pct_change().dropna()
if returns.shape[0] < self.lookback:
raise ValueError(
f"Need at least {self.lookback} non-NA return rows to compute idio-vol"
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Use consistent terminology: 'idio-vol' should be 'idiosyncratic volatility' or 'idio_vol' for clarity.

Suggested change
f"Need at least {self.lookback} non-NA return rows to compute idio-vol"
f"Need at least {self.lookback} non-NA return rows to compute idiosyncratic volatility"

Copilot uses AI. Check for mistakes.
@ayushkrtiwari ayushkrtiwari added Semver:minor minor version changes PR:Accept To acknowledge the PR hacktoberfest-accepted Type:Medium junior developers talks labels Oct 27, 2025
@ayushkrtiwari ayushkrtiwari requested a review from Copilot October 27, 2025 20:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ayushkrtiwari ayushkrtiwari merged commit 40bc780 into OPCODE-Open-Spring-Fest:main Oct 27, 2025
7 of 8 checks passed
@ayushkrtiwari ayushkrtiwari mentioned this pull request Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted PR:Accept To acknowledge the PR Semver:minor minor version changes Type:Medium junior developers talks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants