-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pushing initial release code changes
- Loading branch information
1 parent
7d26664
commit d22d6ce
Showing
15 changed files
with
245 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
numpy | ||
cvxpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
finmodels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
], | ||
) |