Welcome to fin_libs’s documentation!

Fin Libs is a Python library that exposes tools for financial analytics. This includes functions to calculate: * simple and compound interest * compound annual growth rate * weighted average * linear least squares * earning per share * net income

How to install fin_libs

This library can be installed by running pip install fin_libs given that you already have Python and pip installed.

Library usage

Example usage of each library module is included in the documentation of that module.

compound_annual_growth_rate

Library module to compute compund annual growth rate

Typical usage example:

rate = calculate_compound_annual_growth_rate(71, 100, 4)

fin_libs.compound_annual_growth_rate.calculate_compound_annual_growth_rate(first, last, years)

Calculate compound annual growth rate

Parameters:
  • first (float) – starting value

  • last (float) – ending value

  • years (int) – number of years

Returns:

calculated compound annual growth rate

Return type:

float

fin_libs.compound_annual_growth_rate.print_calculate_compound_annual_growth_rate(first, last, years)

Print compound annaul growth rate

Parameters:
  • first (float) – starting value

  • last (float) – ending value

  • years (int) – number of years

Returns:

None

dividends

Library module to compute dividend information

Typical usage example:

aapl_dr = calculate_dividend_rate(“AAPL”)

fin_libs.dividends.calculate_dividend_rate(ticker)

Calculate dividend rate

Parameters:

ticker (str) – name of the ticker

Returns:

dividend rate

Return type:

float

fin_libs.dividends.calculate_dividend_yield(ticker)

Calculate dividend yield

Parameters:

ticker (str) – name of the ticker

Returns:

dividend yield

Return type:

float

eps

Library module to compute earnings per share

Typical usage example:

aapl_eps = calculate_eps(“AAPL”)

fin_libs.eps.calculate_eps(ticker)

Calculate Earnings per Share

Parameters:

ticker (str) – the ticker for which we should calculate the EPS

Returns:

the EPS

Return type:

float

income

Library module to compute net income

Typical usage example:

net_income = calculate_net_income(“earnings.csv”, “transactions”)

fin_libs.income.calculate_net_income(csv_file_path, col_name)

Calculate net income

Parameters:
  • csv_file_path (str) – expect csv_file_path to have column with positive and negative values for money in & out

  • col_name (str) – name of the column

Returns:

the net income

Return type:

float

interest.compound

Library package to calculate compound interest

Typical usage example:

compound_interest = calculate_compound_interest(100, 5, 2)

fin_libs.interest.compound.calculate_compound_interest(principal, rate, time)

Calculate compound interest

Parameters:
  • principal (float) – principal amount

  • rate (float) – interest rate

  • time (int) – time

Returns:

compound interest

Return type:

float

interest.simple

Library package to calculate simple interest

Typical usage example:

simple_interest = calculate_simple_interest(100, 5, 2)

fin_libs.interest.simple.calculate_simple_interest(principal, rate, time)

Calculate simple interest

Parameters:
  • principal (float) – principal amount

  • rate (float) – interest rate

  • time (int) – time

Returns:

simple interest

Return type:

float

linear_least_squares

Library package to compute linear least squares regression

Typical usage example:

x, y, y_pred = do_linear_least_squares_regression(“data.csv”) plot_linear_least_squares_regression(x, y, y_pred, “red”)

fin_libs.linear_least_squares.do_linear_least_squares_regression(csv_file_path)

Does linear least squares regression

Parameters:

csv_file_path (string) – file path where data is located

Returns:

x coefficient int: y coefficient int: y predictor coefficient

Return type:

int

fin_libs.linear_least_squares.plot_linear_least_squares_regression(x, y, y_pred, color='yellow')

Plots chart of linear least squares regression

Parameters:
  • x (int) – x coefficient

  • y (int) – y coefficient

  • y_pred (int) – y predictor coefficient

  • color (string, optional) – color

Returns:

None

price

Module to calculate stock price ratios

Typical usage example:

apple_pe = calculate_price_to_earning(“AAPL”) apple_pbv = calculate_price_to_book_value(“AAPL”)

fin_libs.price.calculate_price_to_book_value(ticker)

Calculate Price to Book Value Ratio (P/BV)

Parameters:

ticker (str) – the ticker for which we should calculate the ratio

Returns:

the ratio

Return type:

float

fin_libs.price.calculate_price_to_earning(ticker)

Calculate Price to Earnings Ratio (P/E)

Parameters:

ticker (str) – the ticker for which we should calculate the ratio

Returns:

the ratio

Return type:

float

weighted_average

Library package to compute the weighted average

Typical usage example:

weighted_avg = compute_weighted_average(“data.csv”, “values”, “weights”)

fin_libs.weighted_average.compute_weighted_average(csv_file_path, distr_col, weights_col)

Compute weighted average

Parameters:
  • csv_file_path (str) – file path string

  • distr_col (str) – column name for distribution

  • weights_col (str) – column name for weights

Returns:

weighted average

Return type:

int