|
import pandas as pd |
|
import requests |
|
|
|
|
|
|
|
def get_monthly_sip_nav_df(df, start_date, end_date, SIP_date): |
|
df = df.copy() |
|
df['date'] = pd.to_datetime(df['date']) |
|
df = df[(df['date'] >= start_date) & (df['date'] <= end_date)] |
|
if SIP_date == 'start': |
|
df = df.groupby([df['date'].dt.year, df['date'].dt.month]).first() |
|
elif SIP_date == 'end': |
|
df = df.groupby([df['date'].dt.year, df['date'].dt.month]).last() |
|
else: |
|
df = df.groupby([df['date'].dt.year, df['date'].dt.month]).apply(lambda x: x.iloc[len(x)//2]) |
|
return df |
|
|
|
|
|
|
|
def get_all_mf_schemes_df(): |
|
url = "https://api.mfapi.in/mf" |
|
response = requests.get(url) |
|
schemes = response.json() |
|
return pd.DataFrame(schemes) |
|
|
|
|
|
def get_mf_scheme_data(scheme_code): |
|
url = f"https://api.mfapi.in/mf/{scheme_code}" |
|
response = requests.get(url) |
|
data = response.json() |
|
df = pd.DataFrame(data['data']) |
|
df['date'] = pd.to_datetime(df['date'], format='%d-%m-%Y') |
|
df['nav'] = df['nav'].astype(float) |
|
df = df.sort_values('date') |
|
inception_date = df['date'].min() |
|
return df, inception_date |
|
|
|
|