# Assignment

## # Assignment Assignment

##### Calculate Mutual Fund Profit

Objective:
Create a class or a function to calculate the profit for a mutual fund investment.

Function/Class Signature:

``````calculate_profit(scheme_code, start_date, end_date, capital=1000000.0)
``````

Parameters:

1. `scheme_code` (str): The unique scheme code of the mutual fund.
2. `start_date` (str – dd-mm-yyyy): The purchase date of the mutual fund.
3. `end_date` (str – dd-mm-yyyy): The redemption date of the mutual fund.
4. `capital` (float, optional): The initial investment amount (default: 1000000.0).

Example:

Let’s assume you invested ₹1,000,000 in a mutual fund with scheme code 101206 on 26-07-2023 and redeemed it on 18-10-2023. To calculate the profit, follow these steps:

1. Get the Net Asset Value (NAV) of the mutual fund on both the purchase date (26-07-2023) and redemption date (18-10-2023) using the API: https://api.mfapi.in/mf/101206.

• NAV on 26-07-2023: 3682.28990
• NAV on 18-10-2023: 3737.30240
2. Calculate the number of units allotted on the purchase date:

``````Number of units allotted on 26-07-2023 = Initial investment / NAV on 26-07-2023
Number of units allotted on 26-07-2023 = 1000000 / 3682.28990 = 271.57 units
``````
3. Calculate the value of the units on the redemption date:

``````Value of 271.57 units as on 18-10-2023 = Number of units allotted on 26-07-2023 * NAV on 18-10-2023
Value of 271.57 units as on 18-10-2023 = 271.57 * 3737.30240 = 1014939.75
``````

Calculate the net profit:

``````Net Profit = Value on redemption date - Initial investment
Net Profit = 1014939.75 - 1000000 = 14939.75
``````
• Create a FastAPI app with single route `/profit` that takes query string params `scheme_code`, `start_date`, `end_date`, `capital`. The request would essentially will look like `/profit?scheme_code=101206& start_date= 26-07-2023&end_date=18-10-2023&capital=1000000. `Use the Python function to calculate profit. 