Skip to content

v0.7.1 - Portfolio Purchase Date

Choose a tag to compare

@saidsurucu saidsurucu released this 29 Jan 13:49
· 22 commits to master since this release

New Features

Portfolio purchase_date Support

Add purchase date tracking to portfolio holdings for more accurate return calculations.

import borsapy as bp
from datetime import date

portfolio = bp.Portfolio()

# Add holdings with purchase date
portfolio.add("THYAO", shares=100, cost=280.0, purchase_date="2024-01-15")
portfolio.add("GARAN", shares=200, cost=45.0, purchase_date=date(2024, 6, 1))
portfolio.add("ASELS", shares=50, cost=120.0)  # Defaults to today

# Holdings DataFrame includes new columns
print(portfolio.holdings[['symbol', 'cost', 'purchase_date', 'holding_days']])
#   symbol  cost purchase_date  holding_days
# 0  THYAO   280    2024-01-15           380
# 1  GARAN    45    2024-06-01           242
# 2  ASELS   120    2026-01-29             0

# Risk metrics now use holding-based dates
metrics = portfolio.risk_metrics(period="1y")

Supported Date Formats:

  • String: "2024-01-15" (ISO format)
  • date: date(2024, 1, 15)
  • datetime: datetime(2024, 1, 15) (date part only)
  • None: Defaults to today

Technical Changes

  • portfolio.py: Holding dataclass now includes purchase_date: date | None
  • portfolio.py: add() method accepts purchase_date parameter
  • portfolio.py: holdings property includes purchase_date and holding_days columns
  • portfolio.py: history() filters data by each holding's purchase_date
  • portfolio.py: to_dict() and from_dict() handle purchase_date serialization
  • tests/test_portfolio.py: 17 new tests for purchase_date feature