I have a dataframe that is populated via a mySQL query. I convert this to an array to try and calculate the irr. The sorting and groupby functions work as intended, but I cannot seem to get around this error. I looked at this issue, but it doesn't seem to apply in my case.
I have tried to pass a list, DataFrame, and pandas table, but the function is looking for an array so that's what I send it. Any help on this is appreciated.
Thanks!
This is the dataset produced as the flows_by_year variable
sum
EffectiveDate
2017 -3660000.0
2018 -5520000.0
2019 -2460213.0
2020 1600000.0
import pandas as pd
import sqlite3
from sqlite3 import Error
import numpy_financial as npf
def IRR(fund, pool):
database = r'C:\Transaction_History.db'
conn = create_connection(database)
sql_flows = ('''SELECT EFFECTIVEDATE, TRANSACTIONAMOUNT FROM Trans_Hist WHERE FUND=''' +
'"' + fund + '"' + ' AND POOL=' + '"' + pool + '"' +
' AND (TRANSACTIONTYPE = "Funding" OR TRANSACTIONTYPE = "Cash");')
flows = pd.read_sql_query(sql_flows, conn, parse_dates=['EffectiveDate'])
flows.sort_values(by=['EffectiveDate'], inplace=True, ascending=True)
flows_by_year = flows.groupby(flows['EffectiveDate'].dt.year)['TransactionAmount'].agg(['sum'])
print(flows_by_year)
irr = round(npf.irr(flows_by_year.values), 4) * 100
irr = f'{irr:,.2f}'
print(irr)
return irr