mutual-fund / app /models /portfolio_models.py
lucifer7210's picture
Upload 21 files
eb606e1 verified
from pydantic import BaseModel, Field
from typing import List, Dict, Optional, Any
from datetime import datetime
from enum import Enum
class InvestmentType(str, Enum):
LUMP_SUM = "Lump Sum"
SIP_MONTHLY = "SIP (Monthly)"
STP = "STP"
class PortfolioHolding(BaseModel):
scheme_code: str
category: str
fund_house: str
invested_amount: float = Field(gt=0)
current_value: float = Field(gt=0)
units: float = Field(gt=0)
current_nav: float = Field(gt=0)
investment_type: InvestmentType
nav_data: List[Any] = []
class Portfolio(BaseModel):
holdings: Dict[str, PortfolioHolding] = {}
class PortfolioMetrics(BaseModel):
total_value: float
total_invested: float
total_gains: float
category_allocation: Dict[str, float]
class PortfolioTemplate(str, Enum):
CONSERVATIVE = "Conservative"
BALANCED = "Balanced"
AGGRESSIVE = "Aggressive"
CUSTOM_SAMPLE = "Custom Sample"
class RebalanceAction(BaseModel):
category: str
current_pct: float
target_pct: float
difference: float
amount_change: float
action: str # "INCREASE" or "DECREASE"
class RebalanceAnalysis(BaseModel):
actions: List[RebalanceAction]
recommended_strategy: str
target_allocation: Dict[str, float]
class PerformanceReport(BaseModel):
total_invested: float
total_value: float
total_gains: float
overall_return_pct: float
fund_performance: List[Dict[str, Any]]
best_performer: Optional[str] = None
worst_performer: Optional[str] = None
max_return: float
min_return: float
volatility: float
sharpe_ratio: float
portfolio_metrics: PortfolioMetrics