Skip to content

Sample code for: Python for Stock Analysis: Build a Portfolio Analyzer - #879

Open
martin-martin wants to merge 3 commits into
masterfrom
python-stock-portfolio-analysis
Open

martin-martin wants to merge 3 commits into
masterfrom
python-stock-portfolio-analysis

Conversation

@martin-martin

@martin-martin martin-martin commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Where to put new files:

  • New files should go into a top-level subfolder, named after the article slug. For example: my-awesome-article

How to merge your changes:

  1. Make sure the CI code style tests all pass (+ run the automatic code formatter if necessary).
  2. Find an RP Team member on Slack and ask them to review & approve your PR.
  3. Once the PR has one positive ("approved") review, GitHub lets you merge the PR.
  4. 🎉

Code examples for the Python for Stock Analysis: Build a Portfolio Analyzer tutorial. Files live in the python-for-stock-analysis/ top-level folder, named after the article slug.

The materials were previously only available as a CMS protected download. This PR moves them into the materials repo in three commits:

  1. Port as-is: The code from the protected download, unchanged except for the folder name (python-finance-portfolio-analysis → python-stock-portfolio-analysis).
  2. Technical review fixes: Matches the updated article. fetch_prices.py keeps full precision and stops on failed downloads; portfolio.py rejects price gaps, validates weights, fixes the drawdown peak, uses the standard Sharpe ratio, and handles zero volatility; prices.csv is a fresh full-precision snapshot (October 2026); README has the current title and link.
  3. Slug rename: Folder renamed to python-for-stock-analysis/ to match the new post slug, which now contains the keyphrase.

Verified with Python 3.14 and the pinned requirements.txt: python portfolio.py reproduces the article's summary table. ruff format --check, ruff check, and dircheck.py pass.

🤖 Generated with Claude Code

martin-martin and others added 3 commits October 8, 2026 09:58
Port the materials from the CMS protected download
(python-finance-portfolio-analysis-materials) unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- fetch_prices.py: keep full precision and stop when a ticker fails
  to download instead of overwriting prices.csv
- portfolio.py: reject gaps instead of dropna(), validate weights,
  include starting value in drawdown peaks, use the standard Sharpe
  ratio, and return NaN for zero volatility
- prices.csv: full-precision snapshot downloaded in October 2026
- README.md: current tutorial title and link

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant