The financial extension in PostgreSQL provides specialized functions for financial calculations, particularly for computing the Irregular Internal Rate of Return (XIRR). It enables handling cash flows with irregular timing, similar to spreadsheet functions like XIRR in Excel or LibreOffice. Your Nile database arrives withDocumentation Index
Fetch the complete documentation index at: https://thenile.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
financial extension already enabled, so there’s no need to run create extension.
Creating and Populating transactions Table
Let’s create a sample table to store financial transactions with dates and cash flows:
Calculating the Irregular Internal Rate of Return (XIRR)
To compute the XIRR for an account usingpg_financial:
Note:
xirr(amount, transaction_date) computes the internal rate of
return for cash flows occurring at irregular intervals. Negative amounts
typically represent investments, while positive amounts represent
returns.Providing an Initial Guess for XIRR
The guess argument is an optional initial guess. When omitted, the function will use annualized return as the guess, which is usually reliable. This attempts to compute the XIRR starting with an initial guess of 10% (0.1).Conclusion
Thepg_financial extension in PostgreSQL provides essential financial calculation capabilities, particularly for evaluating investment returns with irregular cash flows. It is useful for financial modeling and investment analytics.
For more details, refer to the pg_financial GitHub repository.