Spaces:
Sleeping
Sleeping
Download db.py from rickyviale/polymonte-v113: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/spaces/rickyviale/polymonte-v113/resolve/main/db.py
- Command line
-
hf download hf://spaces/rickyviale/polymonte-v113/db.py
-
curl -L -o db.py https://huggingface.co/spaces/rickyviale/polymonte-v113/resolve/main/db.py
1.75 kB
| """ | |
| Polymonte V111 — Base de données SQLite (remplace PostgreSQL pour HF Spaces) | |
| """ | |
| import os | |
| from datetime import datetime | |
| from sqlalchemy import create_engine, Column, String, Float, Integer, DateTime, Text | |
| from sqlalchemy.orm import sessionmaker, declarative_base | |
| os.makedirs("data", exist_ok=True) | |
| DATABASE_URL = "sqlite:///data/polymonte.db" | |
| engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False}) | |
| SessionLocal = sessionmaker(bind=engine) | |
| Base = declarative_base() | |
| class Trade(Base): | |
| __tablename__ = "trades" | |
| id = Column(Integer, primary_key=True, index=True) | |
| timestamp = Column(String) | |
| symbol = Column(String, index=True) | |
| action = Column(String) | |
| qty = Column(Integer) | |
| price = Column(Float) | |
| regime = Column(String) | |
| atr = Column(Float, nullable=True) | |
| pnl = Column(Float, nullable=True) | |
| class EquityHistory(Base): | |
| __tablename__ = "equity_history" | |
| id = Column(Integer, primary_key=True, index=True) | |
| timestamp = Column(DateTime, default=datetime.utcnow, index=True) | |
| equity = Column(Float) | |
| drawdown_pct = Column(Float) | |
| class BacktestResult(Base): | |
| __tablename__ = "backtest_results" | |
| id = Column(Integer, primary_key=True, index=True) | |
| timestamp = Column(DateTime, default=datetime.utcnow) | |
| symbol = Column(String) | |
| total_return = Column(Float) | |
| sharpe_ratio = Column(Float) | |
| max_drawdown = Column(Float) | |
| win_rate = Column(Float) | |
| details = Column(Text, nullable=True) | |
| def init_db(): | |
| Base.metadata.create_all(bind=engine) | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |