Skip to main content

Corporate Finance calculations library with AI agent integration

Project description

pyCorpFin

A Python library for corporate finance calculations with built-in AI agent integration for LangChain, LangGraph, and other agentic frameworks.

Features

  • Core Finance Functions: NPV, IRR, MIRR, XIRR, EMI calculations
  • AI Agent Ready: Pre-built tools for LangChain and LangGraph
  • Zero Dependencies: Core library works without external packages
  • Pure Python: No compiled extensions required

Installation

Basic Installation

pip install pyCorpFin

With LangChain Support

pip install pyCorpFin[langchain]

With LangGraph Support

pip install pyCorpFin[langgraph]

With All AI Features

pip install pyCorpFin[all]

Quick Start

Direct Usage

from pyCorpFin import IRR, calculate_xirr
from datetime import datetime

# Calculate IRR
cashflows = [-1000, 300, 400, 500]
irr = IRR(cashflows)
print(f"IRR: {irr:.2%}")

# Calculate XIRR
dates = [datetime(2023, 1, 1), datetime(2023, 6, 1), 
         datetime(2023, 12, 1), datetime(2024, 6, 1)]
xirr = calculate_xirr(cashflows, dates)
print(f"XIRR: {xirr:.2%}")

With LangChain

from pyCorpFin.tools import get_langchain_tools
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI

# Get finance tools
tools = get_langchain_tools()

# Create agent
llm = ChatOpenAI(temperature=0)
agent = initialize_agent(
    tools, 
    llm, 
    agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True
)

# Use the agent
result = agent.run(
    "Calculate the IRR for an investment of $10,000 that returns "
    "$3,000 per year for 4 years"
)

With LangGraph

from langgraph.prebuilt import create_react_agent
from pyCorpFin.tools import get_langchain_tools
from langchain_openai import ChatOpenAI

tools = get_langchain_tools()
model = ChatOpenAI(model="gpt-4")

agent = create_react_agent(model, tools)

response = agent.invoke({
    "messages": [("user", "What's the EMI on a $100,000 loan at 8% for 20 years?")]
})

API Reference

Core Functions

  • IRR(cashflows, guess=0.1) - Internal Rate of Return
  • calculate_mirr(cashflows, finance_rate, reinvest_rate) - Modified IRR
  • calculate_xirr(cashflows, dates, guess=0.1) - Extended IRR
  • presentValue(cf, r, n) - Present Value
  • futureValue(cf, r, n) - Future Value
  • emi(PV, r, n) - Equated Monthly Installment

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycorpfin-0.1.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycorpfin-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file pycorpfin-0.1.0.tar.gz.

File metadata

  • Download URL: pycorpfin-0.1.0.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.5

File hashes

Hashes for pycorpfin-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2e75c701294be3fa0e5dd1d36e47e499422b6d5e5b885426bdae7e5f39455b93
MD5 1cabaa1439869ff83bc53809a164658b
BLAKE2b-256 cdf0681b705878e92db7d902697fcfb6d1f30cf503111d4eca0a9acec57dfc24

See more details on using hashes here.

File details

Details for the file pycorpfin-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pycorpfin-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.5

File hashes

Hashes for pycorpfin-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b79e868002ece367e7e9675d3e87d818b43977ae4ed13607da332201d124cf5
MD5 2f5ef1508ed0b2a7f1f7ce7181c365b9
BLAKE2b-256 5b8ca347d1fef0a538577dbb85f36d6059d32675545c48892ed1f49575c6e1af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page