Skip to content

Commit

Permalink
fixing the code
Browse files Browse the repository at this point in the history
  • Loading branch information
tamilselvanarjun committed Mar 29, 2024
2 parents 9dd0c71 + 726b331 commit a7de527
Show file tree
Hide file tree
Showing 22 changed files with 585 additions and 5 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
90 changes: 89 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
#### quantmodels

#### Overview
Expand Down Expand Up @@ -38,4 +39,91 @@ put_price = binomial_option_pricing(underlying_price, strike_price, time_to_matu

print(f"Call Option Price: {call_price:.2f}")
print(f"Put Option Price: {put_price:.2f}")
```
```
=======
#### finmodels

`finmodels` is a Python package designed for financial analysis and optimization. It includes a collection of financial models, such as Discounted Cash Flow (DCF) valuation and Mean-Variance Portfolio Optimization. With finmodels, you can perform essential financial calculations to support investment decisions and portfolio management.

#### Key Features
`Discounted Cash Flow (DCF) Valuation`: Calculate the present value of future cash flows to assess the intrinsic value of an investment.

`Portfolio Optimization`: Optimize portfolio allocations using Mean-Variance Optimization to balance returns and risk.

`The Leveraged Buyout (LBO) Model`: LBO Model is a financial analysis tool used in corporate finance for

evaluating the acquisition of a company using a significant amount of borrowed funds.

`IPO Model`: IPO Model is a simple Python script for calculating the Initial Public Offering (IPO) valuation using a discounted cash flow (DCF) model.


#### Installation

You can install the package using `pip`:

```
pip install finmodels
```
Usage
Discounted Cash Flow (DCF) Valuation
#### Example usage of DCF valuation

```
import finmodels as fm
cash_flows = [100, 150, 200, 250]
discount_rate = 0.1
dcf_value = fm.calculate_dcf(cash_flows, discount_rate)
print("DCF Value:", dcf_value)
```
#### Example usage of Portfolio Optimization
```
import finmodels as fm
import numpy as np
# Example usage of portfolio optimization
expected_returns = np.array([0.05, 0.08, 0.12])
covariance_matrix = np.array([[0.001, 0.0005, 0.0002],
[0.0005, 0.002, 0.001],
[0.0002, 0.001, 0.003]])
optimal_weights = fm.optimize_portfolio(expected_returns, covariance_matrix)
print("Optimal Portfolio Weights:", optimal_weights)
```

#### Example usage of Leveraged Buyout (LBO) Model
```
import finmodels as fm
# Example usage
acquisition_price_example = 1000
equity_percentage_example = 0.3
debt_interest_rate_example = 0.05
projection_years_example = 5
# Create an instance of LBOModel
lbo_model = fm.LBOModel(acquisition_price_example, equity_percentage_example,
debt_interest_rate_example, projection_years_example)
# Calculate and print equity returns
equity_returns_result = lbo_model.calculate_equity_returns()
print(f"Equity Returns for each year: {equity_returns_result}")
```

#### Example usage of IPO Model
```
import finmodels as fm
# Example usage
initial_valuation = 500000000 # Initial company valuation before IPO
funds_raised = 100000000 # Funds raised during the IPO
operating_income = 75000000 # Annual operating income before IPO
growth_rate = 0.05 # Annual growth rate of operating income
years = 5 # Number of years for the IPO model
ipo_model = fm.IPOModel(initial_valuation, funds_raised, operating_income, growth_rate, years)
ipo_model.print_summary()
```

#### Contributors
Tamilselvan Arjunan
#### License
This project is licensed under the MIT License - see the LICENSE file for details.
>>>>>>> 726b3315a24d8f382b3b486500d2fcddce8e5b4d
6 changes: 6 additions & 0 deletions build/lib/finmodels/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# financial_models/__init__.py
from .dcf import calculate_dcf
from .portfolio_optimization import optimize_portfolio
from .lbo import LBOModel
from .ipo import IPOModel

13 changes: 13 additions & 0 deletions build/lib/finmodels/dcf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def calculate_dcf(cash_flows, discount_rate):
"""
Calculate the Discounted Cash Flow (DCF) valuation.
Parameters:
- cash_flows: List or array of future cash flows
- discount_rate: Discount rate used in the calculation
Returns:
- DCF value
"""
dcf_value = sum(cf / (1 + discount_rate) ** i for i, cf in enumerate(cash_flows))
return dcf_value
29 changes: 29 additions & 0 deletions build/lib/finmodels/ipo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class IPOModel:
def __init__(self, initial_valuation, funds_raised, operating_income, growth_rate, years):
self.initial_valuation = initial_valuation
self.funds_raised = funds_raised
self.operating_income = operating_income
self.growth_rate = growth_rate
self.years = years

def calculate_ipo_valuation(self):
# Calculate the IPO valuation using a simple discounted cash flow (DCF) model
discount_factor = 1 + self.growth_rate
future_cash_flows = [self.operating_income * (discount_factor ** year) for year in range(1, self.years + 1)]
total_cash_flows = sum(future_cash_flows)
ipo_valuation = self.initial_valuation + total_cash_flows + self.funds_raised
return ipo_valuation

def print_summary(self):
ipo_valuation = self.calculate_ipo_valuation()
print(f"IPO Valuation after {self.years} years: ${ipo_valuation:,.2f}")

# Example usage
#initial_valuation = 500000000 # Initial company valuation before IPO
#funds_raised = 100000000 # Funds raised during the IPO
#operating_income = 75000000 # Annual operating income before IPO
#growth_rate = 0.05 # Annual growth rate of operating income
#years = 5 # Number of years for the IPO model

#ipo_model = IPOModel(initial_valuation, funds_raised, operating_income, growth_rate, years)
#ipo_model.print_summary()
70 changes: 70 additions & 0 deletions build/lib/finmodels/lbo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class LBOModel:
def __init__(self, acquisition_price, equity_percentage, debt_interest_rate, years):
"""
Initializes the LBOModel instance.
Parameters:
- acquisition_price (float): The purchase price of the target company.
- equity_percentage (float): The percentage of acquisition price funded by equity.
- debt_interest_rate (float): Annual interest rate on debt.
- years (int): Number of years for the projection period.
"""
self.acquisition_price = acquisition_price
self.equity_percentage = equity_percentage
self.debt_interest_rate = debt_interest_rate
self.years = years
self.equity_investment = acquisition_price * equity_percentage
self.debt_financing = acquisition_price - self.equity_investment

def calculate_free_cash_flows(self):
"""
Calculates projected free cash flows for each year.
Returns:
- list: Projected free cash flows for each year.
"""
# Simplified example: Assuming constant free cash flows for demonstration
average_free_cash_flow = 50
free_cash_flows = [average_free_cash_flow] * self.years
return free_cash_flows

def calculate_debt_payments(self):
"""
Calculates annual debt payments based on debt financing and interest rate.
Returns:
- list: Annual debt payments for each year.
"""
debt_payments = [self.debt_financing * self.debt_interest_rate] * self.years
return debt_payments

def calculate_equity_returns(self):
"""
Calculates equity returns for each year.
Returns:
- list: Equity returns for each year.
"""
free_cash_flows = self.calculate_free_cash_flows()
debt_payments = self.calculate_debt_payments()

equity_returns = [free_cash_flow - debt_payment for free_cash_flow, debt_payment
in zip(free_cash_flows, debt_payments)]

return equity_returns

# Example usage (commented out)
# acquisition_price_example = 1000
# equity_percentage_example = 0.3
# debt_interest_rate_example = 0.05
# projection_years_example = 5

# Create an instance of LBOModel (commented out)
# lbo_model = LBOModel(acquisition_price_example, equity_percentage_example,
# debt_interest_rate_example, projection_years_example)

# Calculate and print equity returns (commented out)
# equity_returns_result = lbo_model.calculate_equity_returns()
# print(f"Equity Returns for each year: {equity_returns_result}")
#

36 changes: 36 additions & 0 deletions build/lib/finmodels/portfolio_optimization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np
import cvxpy as cp

def optimize_portfolio(expected_returns, covariance_matrix):
"""
Optimize a portfolio using Mean-Variance Optimization.
Parameters:
- expected_returns: Expected returns for each asset
- covariance_matrix: Covariance matrix of asset returns
Returns:
- Optimal portfolio weights if successful, None otherwise
"""
num_assets = len(expected_returns)

# Define the variables for optimization
weights = cp.Variable(num_assets)
expected_return = expected_returns @ weights
risk = cp.quad_form(weights, covariance_matrix)

# Define the objective function (maximize return, minimize risk)
objective = cp.Maximize(expected_return - 0.5 * risk)

# Define the constraints (weights sum to 1, individual weights are non-negative)
constraints = [cp.sum(weights) == 1, weights >= 0]

# Formulate and solve the problem
problem = cp.Problem(objective, constraints)
problem.solve()

if problem.status == 'optimal':
return weights.value
else:
print("Optimization problem could not be solved.")
return None
Binary file added dist/finmodels-2.0.3-py3-none-any.whl
Binary file not shown.
Binary file added dist/finmodels-2.0.3.tar.gz
Binary file not shown.
99 changes: 99 additions & 0 deletions finmodels.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Metadata-Version: 2.1
Name: finmodels
Version: 2.0.3
Summary: finmodels is a Python package that provides various financial models for analysis and optimization.
Home-page: https://github.com/arjunlimat/finmodels
Author: Tamilselvan_Arjunan
Author-email: [email protected]
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
Requires-Dist: numpy
Requires-Dist: cvxpy

#### finmodels

`finmodels` is a Python package designed for financial analysis and optimization. It includes a collection of financial models, such as Discounted Cash Flow (DCF) valuation and Mean-Variance Portfolio Optimization. With finmodels, you can perform essential financial calculations to support investment decisions and portfolio management.

#### Key Features
`Discounted Cash Flow (DCF) Valuation`: Calculate the present value of future cash flows to assess the intrinsic value of an investment.

`Portfolio Optimization`: Optimize portfolio allocations using Mean-Variance Optimization to balance returns and risk.

`The Leveraged Buyout (LBO) Model`: LBO Model is a financial analysis tool used in corporate finance for

evaluating the acquisition of a company using a significant amount of borrowed funds.

`IPO Model`: IPO Model is a simple Python script for calculating the Initial Public Offering (IPO) valuation using a discounted cash flow (DCF) model.


#### Installation

You can install the package using `pip`:

```
pip install finmodels
```
Usage
Discounted Cash Flow (DCF) Valuation
#### Example usage of DCF valuation

```
import finmodels as fm
cash_flows = [100, 150, 200, 250]
discount_rate = 0.1
dcf_value = fm.calculate_dcf(cash_flows, discount_rate)
print("DCF Value:", dcf_value)
```
#### Example usage of Portfolio Optimization
```
import finmodels as fm
import numpy as np

# Example usage of portfolio optimization
expected_returns = np.array([0.05, 0.08, 0.12])
covariance_matrix = np.array([[0.001, 0.0005, 0.0002],
[0.0005, 0.002, 0.001],
[0.0002, 0.001, 0.003]])
optimal_weights = fm.optimize_portfolio(expected_returns, covariance_matrix)
print("Optimal Portfolio Weights:", optimal_weights)

```

#### Example usage of Leveraged Buyout (LBO) Model
```
import finmodels as fm
# Example usage
acquisition_price_example = 1000
equity_percentage_example = 0.3
debt_interest_rate_example = 0.05
projection_years_example = 5

# Create an instance of LBOModel
lbo_model = fm.LBOModel(acquisition_price_example, equity_percentage_example,
debt_interest_rate_example, projection_years_example)

# Calculate and print equity returns
equity_returns_result = lbo_model.calculate_equity_returns()
print(f"Equity Returns for each year: {equity_returns_result}")
```

#### Example usage of IPO Model
```
import finmodels as fm
# Example usage
initial_valuation = 500000000 # Initial company valuation before IPO
funds_raised = 100000000 # Funds raised during the IPO
operating_income = 75000000 # Annual operating income before IPO
growth_rate = 0.05 # Annual growth rate of operating income
years = 5 # Number of years for the IPO model

ipo_model = fm.IPOModel(initial_valuation, funds_raised, operating_income, growth_rate, years)
ipo_model.print_summary()
```

#### Contributors
Tamilselvan Arjunan
#### License
This project is licensed under the MIT License - see the LICENSE file for details.
Loading

0 comments on commit a7de527

Please sign in to comment.