From 9b87e01159dc26de886418bae53488bb96144b21 Mon Sep 17 00:00:00 2001 From: Pietropaolo Frisoni Date: Tue, 22 Aug 2023 12:37:32 +0200 Subject: [PATCH] using OPTIONAL data type --- finquant/data_types.py | 1 - finquant/portfolio.py | 4 ++-- finquant/quants.py | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/finquant/data_types.py b/finquant/data_types.py index 4e66ff4c..b4b1bbb4 100644 --- a/finquant/data_types.py +++ b/finquant/data_types.py @@ -67,7 +67,6 @@ def process_data(data: ARRAY_OR_DATAFRAME) -> FLOAT: # Numeric types FLOAT = Union[np.floating, float] -FLOAT_OPTIONAL = Union[FLOAT, None] INT = Union[np.integer, int] NUMERIC = Union[INT, FLOAT] diff --git a/finquant/portfolio.py b/finquant/portfolio.py index d4911429..eb4ee04a 100644 --- a/finquant/portfolio.py +++ b/finquant/portfolio.py @@ -511,14 +511,14 @@ def comp_sortino(self) -> FLOAT: self.expected_return, self.downside_risk, self.risk_free_rate ) - def comp_treynor(self) -> FLOAT: + def comp_treynor(self) -> Optional[FLOAT]: """Compute and return the Treynor Ratio of the portfolio. :type freq: :py:data:`~.finquant.data_types.FLOAT` :return: The Treynor Ratio of the portfolio. """ # compute the Treynor Ratio of the portfolio - treynor: FLOAT = treynor_ratio( + treynor: Optional[FLOAT] = treynor_ratio( self.expected_return, self.beta, self.risk_free_rate ) self.treynor = treynor diff --git a/finquant/quants.py b/finquant/quants.py index 763b8fff..00b4b956 100644 --- a/finquant/quants.py +++ b/finquant/quants.py @@ -4,7 +4,7 @@ """ -from typing import Tuple +from typing import Tuple, Optional import numpy as np import pandas as pd @@ -123,8 +123,8 @@ def sortino_ratio( def treynor_ratio( - exp_return: FLOAT, beta: FLOAT_OPTIONAL, risk_free_rate: FLOAT = 0.005 -) -> FLOAT_OPTIONAL: + exp_return: FLOAT, beta: Optional[FLOAT], risk_free_rate: FLOAT = 0.005 +) -> Optional[FLOAT]: """Computes the Treynor Ratio. :param exp_return: Expected Return of a portfolio