Skip to content
This repository was archived by the owner on Oct 28, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ yarn-error.log
.yarn-integrity

.idea/
package-lock.json
package-lock.json
.history
141 changes: 141 additions & 0 deletions scripts/guru_portfolio/13f_portfolio_visualization.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
Metadata-Version: 2.4
Name: 13f-portfolio-visualization
Version: 0.1.0
Summary: 13F Portfolio Data Extraction and Visualization Tool
Author-email: Finance Guru Team <[email protected]>
Keywords: finance,portfolio,visualization,13f,investment
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Topic :: Office/Business :: Financial :: Investment
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: pandas>=2.0.0
Requires-Dist: plotly>=5.14.0
Requires-Dist: numpy>=1.24.0
Requires-Dist: requests>=2.28.0
Requires-Dist: beautifulsoup4>=4.11.0
Requires-Dist: lxml>=4.9.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: flake8>=6.0.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"

# 13F Portfolio Visualization Tool

A Python tool for fetching and visualizing institutional investor portfolio data from 13F filings via [13f.info](https://13f.info).

## Features

- 📊 **Data Extraction**: Automatically fetches portfolio data from 13f.info
- 📈 **Interactive Visualizations**:
- Treemap visualization of portfolio holdings
- Sector allocation pie chart
- Top holdings bar chart
- 📝 **Comprehensive Reports**: Generates detailed markdown reports with portfolio metrics
- 🔍 **Portfolio Analysis**:
- Concentration metrics (HHI, Gini coefficient)
- Sector breakdown
- Top holdings analysis

## Installation

1. Clone the repository:
```bash
git clone <repository-url>
cd guru_portfolio
```

2. Install dependencies:
```bash
pip install -r requirements.txt
```

Or using the pyproject.toml:
```bash
pip install -e .
```

## Usage

Basic usage:
```bash
python main.py "Company Name" "Quarter"
```

### Examples

```bash
# Berkshire Hathaway Q3 2024
python main.py "Berkshire Hathaway Inc" "Q3 2024"

# Bridgewater Associates Q2 2024 with custom output directory
python main.py "Bridgewater Associates" "Q2 2024" --output-dir results/

# Scion Asset Management with top 30 holdings
python main.py "Scion Asset Management" "Q4 2023" --top-n 30
```

### Command Line Options

- `company`: Company name (must match exactly as shown on 13f.info)
- `quarter`: Quarter in format "Q1 2025"
- `--output-dir`, `-o`: Output directory for results (default: `output`)
- `--top-n`, `-n`: Number of top holdings to show in bar chart (default: 20)
- `--no-visualizations`: Skip creating visualizations (only generate report)

## Output

The tool generates the following files in the output directory:

1. **portfolio_analysis.md**: Comprehensive markdown report including:
- Executive summary
- Portfolio metrics and concentration analysis
- Sector breakdown
- Top 20 holdings table
- Analysis notes

2. **portfolio_treemap.html**: Interactive treemap visualization showing all holdings sized by market value

3. **sector_allocation.html**: Pie chart showing portfolio allocation by sector

4. **top_holdings.html**: Bar chart of top N holdings by portfolio weight

## Example Report

The generated markdown report includes:

- Total portfolio value and number of positions
- Concentration metrics (HHI, Gini coefficient, top holdings concentration)
- Sector allocation breakdown
- Detailed holdings table with shares, value, and weights
- Analytical insights based on portfolio characteristics

## Notes

- Company names must match exactly as they appear on 13f.info
- 13F reports are typically filed 45 days after quarter end
- Only institutional investment managers with >$100M AUM are required to file 13F reports
- The tool uses web scraping, so it may need updates if the website structure changes

## Dependencies

- pandas: Data manipulation and analysis
- plotly: Interactive visualizations
- requests: HTTP requests for web scraping
- beautifulsoup4: HTML parsing
- lxml: XML/HTML parser
- numpy: Numerical computations

## License

[Your License Here]

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
README.md
pyproject.toml
13f_portfolio_visualization.egg-info/PKG-INFO
13f_portfolio_visualization.egg-info/SOURCES.txt
13f_portfolio_visualization.egg-info/dependency_links.txt
13f_portfolio_visualization.egg-info/entry_points.txt
13f_portfolio_visualization.egg-info/requires.txt
13f_portfolio_visualization.egg-info/top_level.txt
modules/__init__.py
modules/data_fetcher.py
modules/data_processor.py
modules/report_generator.py
modules/visualizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[console_scripts]
portfolio-viz = main:main
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pandas>=2.0.0
plotly>=5.14.0
numpy>=1.24.0
requests>=2.28.0
beautifulsoup4>=4.11.0
lxml>=4.9.0

[dev]
pytest>=7.0.0
black>=23.0.0
flake8>=6.0.0
mypy>=1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
modules
180 changes: 180 additions & 0 deletions scripts/guru_portfolio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# 13F Portfolio Visualization Tool

A Python tool for fetching and visualizing institutional investor portfolio data from 13F filings via [13f.info](https://13f.info).

## Features

- 📊 **Data Extraction**: Automatically fetches portfolio data from 13f.info
- 📈 **Interactive Visualizations**:
- Treemap visualization of portfolio holdings
- Sector allocation pie chart
- Top holdings bar chart
- Performance comparison with S&P 500 benchmark
- Quarterly returns comparison
- Risk-adjusted metrics visualization
- 📝 **Comprehensive Reports**: Generates detailed markdown reports with portfolio metrics
- 🔍 **Portfolio Analysis**:
- Concentration metrics (HHI, Gini coefficient)
- Sector breakdown
- Top holdings analysis
- Performance vs S&P 500 benchmark
- Risk metrics (Sharpe ratio, beta, volatility)

## Installation

1. Clone the repository:
```bash
git clone <repository-url>
cd guru_portfolio
```

2. Install dependencies:
```bash
pip install -r requirements.txt
```

Or using the pyproject.toml:
```bash
pip install -e .
```

## Usage

Basic usage:
```bash
python main.py "Company Name" "Quarter"
```

### Examples

```bash
# Berkshire Hathaway Q3 2024
python main.py "Berkshire Hathaway Inc" "Q3 2024"

# Bridgewater Associates Q2 2024 with custom output directory
python main.py "Bridgewater Associates" "Q2 2024" --output-dir results/

# Scion Asset Management with top 30 holdings
python main.py "Scion Asset Management" "Q4 2023" --top-n 30

# ARK Invest with S&P 500 performance comparison (4 quarters lookback)
python main.py "ARK Invest" "Q3 2024" --compare-sp500 --lookback-quarters 4

# Berkshire Hathaway with extended performance history (8 quarters)
python main.py "Berkshire Hathaway Inc" "Q3 2024" --compare-sp500 --lookback-quarters 8 --save-html
```

### Command Line Options

- `company`: Company name (must match exactly as shown on 13f.info)
- `quarter`: Quarter in format "Q1 2025"
- `--output-dir`, `-o`: Output directory for results (default: `output`)
- `--top-n`, `-n`: Number of top holdings to show in bar chart (default: 20)
- `--no-visualizations`: Skip creating visualizations (only generate report)
- `--save-html`: Also save visualizations as interactive HTML files
- `--compare-sp500`: Enable performance comparison with S&P 500 benchmark
- `--lookback-quarters`: Number of quarters to look back for performance comparison (default: 4)

## Output

The tool generates the following files in the output directory:

### Standard Output Files

1. **portfolio_analysis.md**: Comprehensive markdown report including:
- Executive summary
- Portfolio metrics and concentration analysis
- Sector breakdown
- Top 20 holdings table
- Analysis notes
- Embedded PNG visualizations

2. **portfolio_treemap.png**: High-resolution treemap visualization showing all holdings sized by market value

3. **sector_allocation.png**: Pie chart showing portfolio allocation by sector

4. **top_holdings.png**: Bar chart of top N holdings by portfolio weight

### Performance Comparison Files (with `--compare-sp500`)

5. **performance_comparison.png**: Line chart comparing portfolio performance vs S&P 500 over time

6. **returns_comparison.png**: Bar chart showing quarterly returns comparison

7. **risk_metrics.png**: Bar chart comparing risk-adjusted metrics:
- Total return
- Volatility (annualized)
- Sharpe ratio
- Beta (if sufficient data)

### Interactive HTML Files (with `--save-html`)
- Interactive HTML versions of all visualizations for enhanced exploration

## Performance Comparison Feature

When using `--compare-sp500`, the tool:

1. **Simulates Historical Portfolio Values**: Creates a simplified historical view based on current holdings
2. **Fetches S&P 500 Data**: Downloads benchmark data from Yahoo Finance
3. **Calculates Performance Metrics**:
- Total return over the period
- Quarterly returns
- Cumulative returns
- Risk-adjusted performance (Sharpe ratio)
- Portfolio beta vs market
4. **Generates Comparison Visualizations**: Creates clear charts showing relative performance

### Performance Metrics Explained

- **Total Return**: Percentage change from start to end of period
- **Volatility**: Standard deviation of returns (annualized)
- **Sharpe Ratio**: Risk-adjusted return metric (higher is better)
- **Beta**: Measure of portfolio's volatility relative to S&P 500
- **Relative Performance**: Difference between portfolio and S&P 500 returns

## Testing

Run the test script to see the performance comparison feature in action:

```bash
python test_performance_comparison.py
```

This will test the feature with multiple well-known investment firms and generate sample outputs.

## Example Report

The generated markdown report includes:

- Total portfolio value and number of positions
- Concentration metrics (HHI, Gini coefficient, top holdings concentration)
- Sector allocation breakdown
- Detailed holdings table with shares, value, and weights
- Analytical insights based on portfolio characteristics

## Notes

- Company names must match exactly as they appear on 13f.info
- 13F reports are typically filed 45 days after quarter end
- Only institutional investment managers with >$100M AUM are required to file 13F reports
- The tool uses web scraping, so it may need updates if the website structure changes
- Performance comparison uses simplified assumptions and should not be used for actual investment decisions

## Dependencies

- pandas: Data manipulation and analysis
- plotly: Interactive visualizations
- requests: HTTP requests for web scraping
- beautifulsoup4: HTML parsing
- lxml: XML/HTML parser
- numpy: Numerical computations
- kaleido: Static image export for plotly
- yfinance: Yahoo Finance data for S&P 500 benchmark

## License

[Your License Here]

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
Loading