diff --git a/README.md b/README.md index 8cca0d9..e9870eb 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/build/lib/finmodels/__init__.py b/build/lib/finmodels/__init__.py new file mode 100644 index 0000000..b6def28 --- /dev/null +++ b/build/lib/finmodels/__init__.py @@ -0,0 +1,3 @@ +# financial_models/__init__.py +from .dcf import calculate_dcf +from .portfolio_optimization import optimize_portfolio diff --git a/build/lib/finmodels/dcf.py b/build/lib/finmodels/dcf.py new file mode 100644 index 0000000..147056e --- /dev/null +++ b/build/lib/finmodels/dcf.py @@ -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 diff --git a/build/lib/finmodels/portfolio_optimization.py b/build/lib/finmodels/portfolio_optimization.py new file mode 100644 index 0000000..df8ccac --- /dev/null +++ b/build/lib/finmodels/portfolio_optimization.py @@ -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 diff --git a/dist/finmodels-1.0.0-py3-none-any.whl b/dist/finmodels-1.0.0-py3-none-any.whl new file mode 100644 index 0000000..2ace997 Binary files /dev/null and b/dist/finmodels-1.0.0-py3-none-any.whl differ diff --git a/dist/finmodels-1.0.0.tar.gz b/dist/finmodels-1.0.0.tar.gz new file mode 100644 index 0000000..e405b97 Binary files /dev/null and b/dist/finmodels-1.0.0.tar.gz differ diff --git a/finmodels.egg-info/PKG-INFO b/finmodels.egg-info/PKG-INFO new file mode 100644 index 0000000..3b62385 --- /dev/null +++ b/finmodels.egg-info/PKG-INFO @@ -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: nishantamil@gmail.com +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. diff --git a/finmodels.egg-info/SOURCES.txt b/finmodels.egg-info/SOURCES.txt new file mode 100644 index 0000000..3282b92 --- /dev/null +++ b/finmodels.egg-info/SOURCES.txt @@ -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 \ No newline at end of file diff --git a/finmodels.egg-info/dependency_links.txt b/finmodels.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/finmodels.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/finmodels.egg-info/requires.txt b/finmodels.egg-info/requires.txt new file mode 100644 index 0000000..8e0df78 --- /dev/null +++ b/finmodels.egg-info/requires.txt @@ -0,0 +1,2 @@ +numpy +cvxpy diff --git a/finmodels.egg-info/top_level.txt b/finmodels.egg-info/top_level.txt new file mode 100644 index 0000000..1c369a9 --- /dev/null +++ b/finmodels.egg-info/top_level.txt @@ -0,0 +1 @@ +finmodels diff --git a/finmodels/__init__.py b/finmodels/__init__.py new file mode 100644 index 0000000..b6def28 --- /dev/null +++ b/finmodels/__init__.py @@ -0,0 +1,3 @@ +# financial_models/__init__.py +from .dcf import calculate_dcf +from .portfolio_optimization import optimize_portfolio diff --git a/finmodels/dcf.py b/finmodels/dcf.py new file mode 100644 index 0000000..147056e --- /dev/null +++ b/finmodels/dcf.py @@ -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 diff --git a/finmodels/portfolio_optimization.py b/finmodels/portfolio_optimization.py new file mode 100644 index 0000000..df8ccac --- /dev/null +++ b/finmodels/portfolio_optimization.py @@ -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 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..5da3b43 --- /dev/null +++ b/setup.py @@ -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='nishantamil@gmail.com', + 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', + ], +)