fix: use actual invested amounts for avg_price in seed data
All checks were successful
Deploy to Production / deploy (push) Successful in 1m48s
All checks were successful
Deploy to Production / deploy (push) Successful in 1m48s
The seed script was incorrectly using the latest snapshot's market price as avg_price, resulting in inflated average costs. Now computes avg_price from actual total invested amounts per ticker. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
238c4d1caf
commit
653fa08fa4
@ -42,6 +42,15 @@ TARGETS = {
|
||||
"411060": Decimal("15"),
|
||||
}
|
||||
|
||||
# Actual total invested amounts per ticker (from brokerage records)
|
||||
TOTAL_INVESTED = {
|
||||
"069500": Decimal("541040"),
|
||||
"148070": Decimal("15432133"),
|
||||
"284430": Decimal("18375975"),
|
||||
"360750": Decimal("7683515"),
|
||||
"411060": Decimal("6829620"),
|
||||
}
|
||||
|
||||
# Historical snapshots from data.txt
|
||||
SNAPSHOTS = [
|
||||
{
|
||||
@ -242,13 +251,18 @@ def seed(db: Session):
|
||||
print(f"Created {tx_count} transactions from snapshot diffs")
|
||||
|
||||
# Set current holdings from latest snapshot
|
||||
# avg_price = total invested amount / quantity (from actual brokerage records)
|
||||
latest = SNAPSHOTS[-1]
|
||||
for h in latest["holdings"]:
|
||||
ticker = h["ticker"]
|
||||
qty = h["qty"]
|
||||
invested = TOTAL_INVESTED[ticker]
|
||||
avg_price = (invested / qty).quantize(Decimal("0.01"))
|
||||
db.add(Holding(
|
||||
portfolio_id=portfolio.id,
|
||||
ticker=h["ticker"],
|
||||
quantity=h["qty"],
|
||||
avg_price=h["price"], # Using current price as avg (best available)
|
||||
ticker=ticker,
|
||||
quantity=qty,
|
||||
avg_price=avg_price,
|
||||
))
|
||||
print(f"Set {len(latest['holdings'])} current holdings from {latest['date']}")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user