Skip to content

Commit

Permalink
Investment assest allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
shraddha761 committed Aug 9, 2023
1 parent dd77787 commit 659af3e
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 1 deletion.
5 changes: 5 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ The initial price of the product or service. |
| POST /margin_of_safety | Calculate margin of safety | - `current_sales` (float): The amount of current sales. |
| | | - `break_even_point` (float): The break_even_point amount. |
|--------------------------- ---|----------------------------------------|---------------------------------------------------------|
| POST /investment_assest_allocation | Calculate Investment Assest Allocation | - `risk_tolerance` (String): The degree of willingness and capacity to endure potential investment losses in pursuit of higher returns. |
| | | - `investment_goals` (String): Specific financial objectives an investor aims to achieve through their investment. |
| | | - `age` (int): The current age of the investor. |
| | | - `market_outlook` (String): An assessment of the anticipated direction. |
|--------------------------- ---|----------------------------------------|---------------------------------------------------------|
19 changes: 19 additions & 0 deletions ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2362,3 +2362,22 @@ Sample Output
"Margin Of Safety": 8%,
}
```
**POST** `/investment_assest_allocation`
- Request body : `{
"risk_tolerance": moderate,
"investment_goals": retirement,
"age":30
"market_outlook":bullish
}`
- Sample output
```py
{
"Tag": "Investment Assest Allocation",
"expected_return": 50000,
"risk_level": 46000,
"diversification_metrics": 0.08,
"rebalancing_strategy": calendar-based,
}
```
16 changes: 16 additions & 0 deletions helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2112,3 +2112,19 @@ def tax_bracket_calculator(income:float, filing_status:str):
def margin_of_safety(current_sales:float, break_even_point: float):
margin = ((current_sales - break_even_point) / current_sales) * 100
return margin

# Function to Calculate Investment Assest Allocation

def investment_assest_allocation(risk_tolerance:str, investment_goals:str, age:int, market_outlook:str):
allocation = {
"conservative": {"stocks": 30, "bonds": 60, "cash": 10},
"moderate": {"stocks": 50, "bonds": 40, "cash": 10},
"aggressive": {"stocks": 70, "bonds": 20, "cash": 10}
}

allocation_mix = allocation.get(risk_tolerance)

total_allocation = sum(allocation_mix.values())
allocation_ratio = {asset_class: (allocation / total_allocation) for asset_class, allocation in allocation_mix.items()}

return allocation_ratio
14 changes: 13 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
from tasks.cash_conversion_cycle import cash_conversion_cycle_task
from tasks.financialAssestRatio import financial_assest_ratio
from tasks.PolicyPremium import calculate_policy_premium
from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio, PriceElasticity, PolicyPremium, AveragePaymentPeriod, ModifiedInternalRateOfReturn, SavingGoal, InterestCoverageRatio, MarginOfSafety, TaxBracketCalculator
from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio, PriceElasticity, PolicyPremium, AveragePaymentPeriod, ModifiedInternalRateOfReturn, SavingGoal, InterestCoverageRatio, MarginOfSafety, TaxBracketCalculator, InvestmentAssestAllocation
from tasks.financialAssestRatio import financial_assest_ratio
from tasks.PriceElasticity import calculate_price_elasticity
from tasks.average_payment_period import average_payment_period_task
Expand All @@ -144,6 +144,7 @@
from tasks.interest_coverage_ratio import interest_coverage_ratio_task
from tasks.tax_bracket_calculator import tax_bracket_calculator
from tasks.margin_of_safety import margin_of_safety_task
from tasks.Investment_Assest_Allocation import investment_assest_allocation

# Creating the app
app = FastAPI(
Expand Down Expand Up @@ -2033,3 +2034,14 @@ def tax_bracket_calculator(request: TaxBracketCalculator):
)
def margin_of_safety(request: MarginOfSafety):
return margin_of_safety_task(request.current_sales, request.break_even_point)

# Endpoint to calculate Investment Assest Allocation

@app.post(
"/investment_assest_allocation",
tags=["investment_assest_allocation"],
description="Calculates Investment Assest Allocation",
)
def investment_assest_allocation(request: InvestmentAssestAllocation):
return investment_assest_allocation(request.risk_tolerance, request.investment_goals,
request.age, request.market_outlook)
51 changes: 51 additions & 0 deletions tasks/Investment_Assest_Allocation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from helpers import functions
from fastapi import HTTPException, status

def investment_assest_allocation(
risk_tolerance: str,
investment_goals: str,
age: int,
market_outlook: str
):
try:
if risk_tolerance == "conservative":
allocation = {"stocks": 30, "bonds": 60, "cash": 10}
elif risk_tolerance == "moderate":
allocation = {"stocks": 50, "bonds": 40, "cash": 10}
else:
allocation = {"stocks": 70, "bonds": 20, "cash": 10}

if investment_goals == "retirement":
expected_return = 0.08
else:
expected_return = 0.1

if market_outlook == "bullish":
expected_return += 0.02
elif market_outlook == "bearish":
expected_return -= 0.02

if age < 30:
risk_level = "low"
elif age < 50:
risk_level = "moderate"
else:
risk_level = "high"

correlation_coefficient = 0.5
num_unique_holdings = 25

rebalancing_strategy = "calendar-based"
return {
"Tag": "Investment Assest Allocation",
"asset_allocation": allocation,
"expected_return": expected_return,
"risk_level": risk_level,
"diversification_metrics": {
"correlation_coefficient": correlation_coefficient,
"num_unique_holdings": num_unique_holdings,
},
"rebalancing_strategy": rebalancing_strategy,
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
7 changes: 7 additions & 0 deletions validators/request_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,10 @@ class TaxBracketCalculator(BaseModel):
class MarginOfSafety(BaseModel):
current_sales:float
break_even_point: float

class InvestmentAssestAllocation(BaseModel):
risk_tolerance: str
investment_goals: str
time_horizon: float
age: int
market_outlook: str

0 comments on commit 659af3e

Please sign in to comment.