Skip to content

Commit

Permalink
pushing initial release code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tamilselvanarjun committed Feb 19, 2024
1 parent 7d26664 commit d22d6ce
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 2 deletions.
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
# finmodels
finmodels is a Python package that provides various financial models for analysis and optimization.
#### 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.

#### Installation

You can install the package using `pip`:

```
pip install finmodels
```
Usage
Discounted Cash Flow (DCF) Valuation
```
import finmodels as fm
```
#### Example usage of DCF valuation
```
cash_flows = [100, 150, 200, 250]
discount_rate = 0.1
dcf_value = fm.calculate_dcf(cash_flows, discount_rate)
print("DCF Value:", dcf_value)
```
#### 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)
```
#### Contributors
Tamilselvan Arjunan
#### License
This project is licensed under the MIT License - see the LICENSE file for details.
3 changes: 3 additions & 0 deletions build/lib/finmodels/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# financial_models/__init__.py
from .dcf import calculate_dcf
from .portfolio_optimization import optimize_portfolio
14 changes: 14 additions & 0 deletions build/lib/finmodels/dcf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# financial_models/dcf.py
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 + 1) for i, cf in enumerate(cash_flows))
return dcf_value
33 changes: 33 additions & 0 deletions build/lib/finmodels/portfolio_optimization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# financial_models/portfolio_optimization.py
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
"""
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()

return weights.value
Binary file added dist/finmodels-1.0.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/finmodels-1.0.0.tar.gz
Binary file not shown.
60 changes: 60 additions & 0 deletions finmodels.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Metadata-Version: 2.1
Name: finmodels
Version: 1.0.0
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.

#### Installation

You can install the package using `pip`:

```
pip install finmodels
```
Usage
Discounted Cash Flow (DCF) Valuation
```
import finmodels as fm
```
#### Example usage of DCF valuation
```
cash_flows = [100, 150, 200, 250]
discount_rate = 0.1
dcf_value = fm.calculate_dcf(cash_flows, discount_rate)
print("DCF Value:", dcf_value)
```
#### 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)
```
#### Contributors
Tamilselvan Arjunan
#### License
This project is licensed under the MIT License - see the LICENSE file for details.
10 changes: 10 additions & 0 deletions finmodels.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
README.md
setup.py
finmodels/__init__.py
finmodels/dcf.py
finmodels/portfolio_optimization.py
finmodels.egg-info/PKG-INFO
finmodels.egg-info/SOURCES.txt
finmodels.egg-info/dependency_links.txt
finmodels.egg-info/requires.txt
finmodels.egg-info/top_level.txt
1 change: 1 addition & 0 deletions finmodels.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions finmodels.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numpy
cvxpy
1 change: 1 addition & 0 deletions finmodels.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
finmodels
3 changes: 3 additions & 0 deletions finmodels/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# financial_models/__init__.py
from .dcf import calculate_dcf
from .portfolio_optimization import optimize_portfolio
14 changes: 14 additions & 0 deletions finmodels/dcf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# financial_models/dcf.py
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 + 1) for i, cf in enumerate(cash_flows))
return dcf_value
33 changes: 33 additions & 0 deletions finmodels/portfolio_optimization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# financial_models/portfolio_optimization.py
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
"""
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()

return weights.value
25 changes: 25 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from setuptools import setup, find_packages

with open('README.md', 'r', encoding='utf-8') as f:
long_description = f.read()

setup(
name='finmodels',
version='1.0.0',
packages=find_packages(),
install_requires=[
'numpy',
'cvxpy',
],
author='Tamilselvan_Arjunan',
author_email='[email protected]',
description='finmodels is a Python package that provides various financial models for analysis and optimization.',
long_description=long_description, # Add this line
long_description_content_type='text/markdown', # Specify the content type if using Markdown
url='https://github.com/arjunlimat/finmodels',
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
)

0 comments on commit d22d6ce

Please sign in to comment.