🛠️ToolsShed

Asset Allocation Calculator

Calculate your ideal portfolio asset allocation based on age, risk tolerance, and investment goals.

Sıkça Sorulan Sorular

Kod Uygulaması

def calculate_allocation(age: int, risk: str, goal: str) -> dict:
    # Base stock percentage using 110-age rule
    base_stock = max(10, 110 - age)

    # Adjust for risk tolerance
    adjustments = {"conservative": -15, "moderate": 0, "aggressive": 15}
    base_stock += adjustments.get(risk, 0)

    # Adjust for goal
    goal_adj = {"retirement": 0, "growth": 10, "income": -10, "preservation": -20}
    base_stock += goal_adj.get(goal, 0)

    base_stock = max(5, min(95, base_stock))
    bonds = max(5, 100 - base_stock - 5)
    cash = 100 - base_stock - bonds

    return {"stocks": base_stock, "bonds": bonds, "cash": cash}

# Example
result = calculate_allocation(age=35, risk="moderate", goal="retirement")
print(f"Stocks: {result['stocks']}%")
print(f"Bonds:  {result['bonds']}%")
print(f"Cash:   {result['cash']}%")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.