- simulate.py: --cap-tier large|mid|small|micro; yfinance market cap fetch with DB cache (ticker_meta table); argv fix for main.py dispatch - plot.py: equity curves now show cap tiers with Alpaca costs (zero commission); HP sweep uses Alpaca cost decomposition; SPY line clamped to last strategy date - db/models.py: TickerMeta table - db/db.py: get_cached_market_caps, upsert_market_caps - README: add --cap-tier to simulate docs; backfill note (~3 days for 2 years at SEC 10 req/s limit); remove duplicate setup block; remove em-dashes in prose; results table tilde estimates to be updated once cap-tier sims complete Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
90 lines
2.4 KiB
Python
90 lines
2.4 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import (
|
|
Boolean,
|
|
Column,
|
|
DateTime,
|
|
Float,
|
|
Index,
|
|
Integer,
|
|
String,
|
|
Text,
|
|
UniqueConstraint,
|
|
)
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
class Filing(Base):
|
|
__tablename__ = "filings"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
accession_number = Column(String, unique=True, nullable=False)
|
|
ticker = Column(String)
|
|
cik = Column(String)
|
|
insider_name = Column(String)
|
|
role = Column(String)
|
|
transaction_date = Column(String)
|
|
filed_date = Column(String)
|
|
shares = Column(Float)
|
|
price = Column(Float)
|
|
total_value = Column(Float)
|
|
flag = Column(String)
|
|
is_10b51 = Column(Boolean, default=False)
|
|
post_tx_shares = Column(Float)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
__table_args__ = (
|
|
Index("idx_filings_ticker", "ticker"),
|
|
Index("idx_filings_transaction_date", "transaction_date"),
|
|
Index("idx_filings_filed_date", "filed_date"),
|
|
)
|
|
|
|
|
|
class Signal(Base):
|
|
__tablename__ = "signals"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
ticker = Column(String)
|
|
trigger_date = Column(String)
|
|
cluster_size = Column(Integer)
|
|
total_cluster_value = Column(Float)
|
|
score = Column(Float)
|
|
alerted = Column(Boolean, default=False)
|
|
executed = Column(Boolean, default=False)
|
|
executed_at = Column(DateTime)
|
|
closed = Column(Boolean, default=False)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
__table_args__ = (
|
|
Index("idx_signals_ticker", "ticker"),
|
|
Index("idx_signals_alerted", "alerted"),
|
|
Index("idx_signals_executed", "executed"),
|
|
)
|
|
|
|
|
|
class TickerMeta(Base):
|
|
__tablename__ = "ticker_meta"
|
|
|
|
ticker = Column(String, primary_key=True)
|
|
market_cap = Column(Float, nullable=True)
|
|
fetched_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
|
|
class PriceCache(Base):
|
|
__tablename__ = "price_cache"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
ticker = Column(String, nullable=False)
|
|
date = Column(String, nullable=False)
|
|
close = Column(Float, nullable=False)
|
|
fetched_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint("ticker", "date", name="uq_price_cache_ticker_date"),
|
|
Index("idx_price_cache_ticker_date", "ticker", "date"),
|
|
)
|