diff --git a/README.md b/README.md index ac85624..0f1b8cc 100644 --- a/README.md +++ b/README.md @@ -254,6 +254,7 @@ look at the examples provided in `./example`. - Value at Risk, - Sharpe Ratio, - Sortino Ratio, + - Treynor Ratio, - Beta parameter, - R squared coefficient. diff --git a/example/Example-Build-Portfolio-from-web.py b/example/Example-Build-Portfolio-from-web.py index 066d913..d0abe52 100644 --- a/example/Example-Build-Portfolio-from-web.py +++ b/example/Example-Build-Portfolio-from-web.py @@ -67,7 +67,7 @@ # # In the below example we are using `yfinance` to download stock data. We specify the start and end date of the stock prices to be downloaded. # We also provide the optional parameter `market_index` to download the historical data of a market index. -# `FinQuant` can use them to calculate the beta parameter and R squared coefficient, measuring the portfolio's daily volatility and relationship compared to the market. +# `FinQuant` can use them to calculate the Treynor Ratio, beta parameter, and R squared coefficient, measuring the portfolio's daily volatility compared to the market. # diff --git a/finquant/quants.py b/finquant/quants.py index b027448..763b8ff 100644 --- a/finquant/quants.py +++ b/finquant/quants.py @@ -124,7 +124,7 @@ def sortino_ratio( def treynor_ratio( exp_return: FLOAT, beta: FLOAT_OPTIONAL, risk_free_rate: FLOAT = 0.005 -) -> FLOAT: +) -> FLOAT_OPTIONAL: """Computes the Treynor Ratio. :param exp_return: Expected Return of a portfolio @@ -138,7 +138,7 @@ def treynor_ratio( :rtype: :py:data:`~.finquant.data_types.FLOAT` :return: Treynor Ratio as a floating point number: - ``(exp_return - risk_free_rate) / float(beta)`` + ``(exp_return - risk_free_rate) / beta`` """ # Type validations: type_validation( @@ -147,7 +147,7 @@ def treynor_ratio( risk_free_rate=risk_free_rate, ) if beta is None: - return np.nan + return None else: res_treynor_ratio: FLOAT = (exp_return - risk_free_rate) / beta return res_treynor_ratio diff --git a/tests/test_market.py b/tests/test_market.py index 5524796..cccb2c4 100644 --- a/tests/test_market.py +++ b/tests/test_market.py @@ -41,3 +41,4 @@ def test_Market(): assert pf.market_index.name == "^GSPC" assert pf.beta is not None assert pf.rsquared is not None + assert pf.treynor is not None