lucifer7210's picture
Upload 21 files
eb606e1 verified
raw
history blame
3.17 kB
from fastapi import APIRouter, Depends, HTTPException
from typing import List, Dict, Any
from app.models.goal_models import (
ClientProfile, InvestmentGoal, GoalsDashboard,
SIPCalculationRequest, SIPCalculationResponse,
RequiredSIPRequest, RequiredSIPResponse, GoalsDashboardRequest
)
from app.services.sip_calculator import SIPCalculator
router = APIRouter()
@router.post("/dashboard", response_model=GoalsDashboard)
async def get_goals_dashboard(request: GoalsDashboardRequest):
"""
Calculate goals dashboard metrics including total required SIP, shortfall/surplus
"""
try:
total_required_sip = sum(goal.required_sip for goal in request.goals)
shortfall = max(0, total_required_sip - request.monthly_savings)
surplus = max(0, request.monthly_savings - total_required_sip)
return GoalsDashboard(
goals=request.goals,
total_required_sip=total_required_sip,
monthly_savings=request.monthly_savings,
shortfall=shortfall,
surplus=surplus
)
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error calculating goals dashboard: {str(e)}")
@router.post("/calculate-sip", response_model=SIPCalculationResponse)
async def calculate_sip(
request: SIPCalculationRequest,
include_yearly_breakdown: bool = False
):
"""
Calculate SIP maturity amount based on monthly investment, expected return, and time period
"""
try:
calculator = SIPCalculator()
result = calculator.get_sip_calculation(request, include_yearly_breakdown)
return result
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error calculating SIP: {str(e)}")
@router.post("/required-sip", response_model=RequiredSIPResponse)
async def calculate_required_sip(request: RequiredSIPRequest):
"""
Calculate required SIP amount to reach a target amount
"""
try:
calculator = SIPCalculator()
result = calculator.get_required_sip(request)
return result
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error calculating required SIP: {str(e)}")
@router.post("/inflation-adjusted")
async def calculate_inflation_adjusted_amount(
target_amount: float,
years: int,
expected_inflation: float
):
"""
Calculate inflation-adjusted target amount for a goal
"""
try:
inflation_adjusted_amount = target_amount * ((1 + expected_inflation/100) ** years)
calculator = SIPCalculator()
required_sip = calculator.calculate_required_sip(inflation_adjusted_amount, years, 12)
return {
"original_amount": target_amount,
"inflation_adjusted_amount": inflation_adjusted_amount,
"required_sip": required_sip,
"years": years,
"expected_inflation": expected_inflation
}
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error calculating inflation-adjusted amount: {str(e)}")