- Introduction
- Basic calculations
- Yahoo Finance parser
- Enterprise value
- Blog posts
- Library and references
PyFinMod is a framework implementing financial calculations in Python using pandas library.
Installation:
pip install -e git+https://github.com/smirnov-am/pyfinmod.git#egg=pyfinmod
import pandas as pd
from datetime import date, timedelta
from dateutil.relativedelta import relativedelta
dates = [date.today() + relativedelta(months=i) for i in range(13)]
df = pd.DataFrame(data={'cash flow': [-100] + [10]*12,
'date': dates})
annual_discount_rate = 0.1
from pyfinmod.basic import npv
npv(df, annual_discount_rate)
from pyfinmod.basic import irr
dates = [date.today() + relativedelta(years=i) for i in range(6)]
df3 = pd.DataFrame(data={'cash flow': [-145, 100, 100, 100, 100, -275], 'date': dates})
irr(df3, guess=0.1)
from pyfinmod.basic import pmt
pmt(principal=100, annual_interest_rate=0.3, term=12, period='month')
9.57859525723352
from pyfinmod.basic import fv
fv(deposits=[1000 for _ in range(10)], annual_interest_rate=0.1, period='year')
df = pd.DataFrame(data={'amount': [1000, 1500], 'date': [date.today(), date.today() + relativedelta(years=1, months=9)]})
from pyfinmod.basic import get_annual_rate_cc
get_annual_rate_cc(df)
0.23169434749037965
Parses Yahoo finance page for the ticker and returns a dataframe for
balance-sheet
, cash-flow
and income-statement
:
from pyfinmod.yahoo_finance import YahooFinanceParser
parser = YahooFinanceParser('AAPL')
parser.get_dataframe('balance-sheet')
Individual values from summary page:
parser = YahooFinanceParser('AAPL')
parser.get_value('Market Cap')
Get free cash flows using accounting book:
from pyfinmod.yahoo_finance import YahooFinanceParser
from pyfinmod.ev import get_enterprise_value
parser = YahooFinanceParser('AAPL')
df = parser.get_dataframe('balance-sheet')
get_enterprise_value(df)
Сash flows from cash flow statement:
from pyfinmod.ev import get_fcf_from_cscf
aapl_parser = YahooFinanceParser('AAPL')
balance_sheet = aapl_parser.get_dataframe('balance-sheet')
cash_flow = aapl_parser.get_dataframe('cash-flow')
get_fcf_from_cscf(income_statement, cash_flow)
from pyfinmod.yahoo_finance import YahooFinanceParser
from pyfinmod.wacc import wacc
from pyfinmod.ev import dcf
parser = YahooFinanceParser('AAPL')
e = parser.get_value('Market Cap')
beta = parser.get_value('Beta (3Y Monthly)')
income_statement = parser.get_dataframe('income-statement')
balance_sheet = parser.get_dataframe('balance-sheet')
aapl_wacc = wacc(e, balance_sheet, income_statement, beta,
risk_free_interest_rate=0.02,
market_return=0.08)
dcf(fcf, aapl_wacc, short_term_growth=0.08, long_term_growth=0.04)