@@ -218,7 +218,7 @@ def semideviation_annual(self) -> pd.Series:
218218 SHV.US 0.000560
219219 dtype: float64
220220 """
221- return helpers .Frame .get_semideviation (self .assets_ror ) * 12 ** 0.5
221+ return helpers .Frame .get_semideviation (self .assets_ror ) * 12 ** 0.5
222222
223223 def get_var_historic (self , time_frame : int = 12 , level : int = 1 ) -> pd .Series :
224224 """
@@ -365,14 +365,16 @@ def recovery_periods(self) -> pd.Series:
365365 max_recovery_periods = pd .Series (dtype = int )
366366 for name in self .symbols :
367367 namespace = name .split ("." , 1 )[- 1 ]
368- if namespace == ' INFL' :
368+ if namespace == " INFL" :
369369 continue
370370 s = growth [name ]
371371 s1 = s .where (s == 0 ).notnull ().astype (int )
372372 s1_1 = s .where (s == 0 ).isnull ().astype (int ).cumsum ()
373373 s2 = s1 .groupby (s1_1 ).cumsum ()
374374 # Max recovery period date should not be in the border (it's not recovered)
375- max_period = s2 .max () if s2 .idxmax ().to_timestamp () != self .last_date else np .NAN
375+ max_period = (
376+ s2 .max () if s2 .idxmax ().to_timestamp () != self .last_date else np .NAN
377+ )
376378 ser = pd .Series (max_period , index = [name ])
377379 max_recovery_periods = pd .concat ([max_recovery_periods , ser ])
378380 return max_recovery_periods
@@ -491,7 +493,9 @@ def get_rolling_cagr(self, window: int = 12, real: bool = False) -> pd.DataFrame
491493 df = self ._add_inflation ()
492494 if real :
493495 df = self ._make_real_return_time_series (df )
494- return helpers .Frame .get_rolling_fn (df , window = window , fn = helpers .Frame .get_cagr )
496+ return helpers .Frame .get_rolling_fn (
497+ df , window = window , fn = helpers .Frame .get_cagr
498+ )
495499
496500 def get_cumulative_return (
497501 self , period : Union [str , int , None ] = None , real : bool = False
@@ -553,7 +557,9 @@ def get_cumulative_return(
553557 "Real cumulative return is not defined (no inflation information is available)."
554558 "Set inflation=True in AssetList to calculate it."
555559 )
556- cumulative_inflation = helpers .Frame .get_cumulative_return (self .inflation_ts [dt :])
560+ cumulative_inflation = helpers .Frame .get_cumulative_return (
561+ self .inflation_ts [dt :]
562+ )
557563 cr = (1.0 + cr ) / (1.0 + cumulative_inflation ) - 1.0
558564 cr .drop (self .inflation , inplace = True )
559565 return cr
@@ -602,7 +608,10 @@ def get_rolling_cumulative_return(
602608 if real :
603609 df = self ._make_real_return_time_series (df )
604610 return helpers .Frame .get_rolling_fn (
605- df , window = window , fn = helpers .Frame .get_cumulative_return , window_below_year = True
611+ df ,
612+ window = window ,
613+ fn = helpers .Frame .get_cumulative_return ,
614+ window_below_year = True ,
606615 )
607616
608617 @property
@@ -692,7 +701,9 @@ def describe(
692701 ytd_return = self .get_cumulative_return (period = "YTD" )
693702 row = ytd_return .to_dict ()
694703 row .update (period = "YTD" , property = "Compound return" )
695- description = pd .concat ([description , pd .DataFrame (row , index = [0 ])], ignore_index = True )
704+ description = pd .concat (
705+ [description , pd .DataFrame (row , index = [0 ])], ignore_index = True
706+ )
696707 # CAGR for a list of periods
697708 if self .pl .years >= 1 :
698709 for i in years :
@@ -702,32 +713,46 @@ def describe(
702713 else :
703714 row = {x : None for x in df .columns }
704715 row .update (period = f"{ i } years" , property = "CAGR" )
705- description = pd .concat ([description , pd .DataFrame (row , index = [0 ])], ignore_index = True )
716+ description = pd .concat (
717+ [description , pd .DataFrame (row , index = [0 ])], ignore_index = True
718+ )
706719 # CAGR for full period
707720 row = self .get_cagr (period = None ).to_dict ()
708721 row .update (period = self ._pl_txt , property = "CAGR" )
709- description = pd .concat ([description , pd .DataFrame (row , index = [0 ])], ignore_index = True )
722+ description = pd .concat (
723+ [description , pd .DataFrame (row , index = [0 ])], ignore_index = True
724+ )
710725 # Dividend Yield
711726 row = self .assets_dividend_yield .iloc [- 1 ].to_dict ()
712727 row .update (period = "LTM" , property = "Dividend yield" )
713- description = pd .concat ([description , pd .DataFrame (row , index = [0 ])], ignore_index = True )
728+ description = pd .concat (
729+ [description , pd .DataFrame (row , index = [0 ])], ignore_index = True
730+ )
714731 # risk for full period
715732 row = self .risk_annual .to_dict ()
716733 row .update (period = self ._pl_txt , property = "Risk" )
717- description = pd .concat ([description , pd .DataFrame (row , index = [0 ])], ignore_index = True )
734+ description = pd .concat (
735+ [description , pd .DataFrame (row , index = [0 ])], ignore_index = True
736+ )
718737 # CVAR
719738 if self .pl .years >= 1 :
720739 row = self .get_cvar_historic ().to_dict ()
721740 row .update (period = self ._pl_txt , property = "CVAR" )
722- description = pd .concat ([description ,pd .DataFrame (row , index = [0 ])], ignore_index = True )
741+ description = pd .concat (
742+ [description , pd .DataFrame (row , index = [0 ])], ignore_index = True
743+ )
723744 # max drawdowns
724745 row = self .drawdowns .min ().to_dict ()
725746 row .update (period = self ._pl_txt , property = "Max drawdowns" )
726- description = pd .concat ([description , pd .DataFrame (row , index = [0 ])], ignore_index = True )
747+ description = pd .concat (
748+ [description , pd .DataFrame (row , index = [0 ])], ignore_index = True
749+ )
727750 # max drawdowns dates
728751 row = self .drawdowns .idxmin ().to_dict ()
729752 row .update (period = self ._pl_txt , property = "Max drawdowns dates" )
730- description = pd .concat ([description , pd .DataFrame (row , index = [0 ])], ignore_index = True )
753+ description = pd .concat (
754+ [description , pd .DataFrame (row , index = [0 ])], ignore_index = True
755+ )
731756 # inception dates
732757 row = {}
733758 for ti in self .symbols :
@@ -737,7 +762,9 @@ def describe(
737762 row .update (period = None , property = "Inception date" )
738763 if hasattr (self , "inflation" ):
739764 row .update ({self .inflation : self .inflation_first_date .strftime ("%Y-%m" )})
740- description = pd .concat ([description , pd .DataFrame (row , index = [0 ])], ignore_index = True )
765+ description = pd .concat (
766+ [description , pd .DataFrame (row , index = [0 ])], ignore_index = True
767+ )
741768 # last asset date
742769 row = {}
743770 for ti in self .symbols :
@@ -747,11 +774,15 @@ def describe(
747774 row .update (period = None , property = "Last asset date" )
748775 if hasattr (self , "inflation" ):
749776 row .update ({self .inflation : self .inflation_last_date .strftime ("%Y-%m" )})
750- description = pd .concat ([description , pd .DataFrame (row , index = [0 ])], ignore_index = True )
777+ description = pd .concat (
778+ [description , pd .DataFrame (row , index = [0 ])], ignore_index = True
779+ )
751780 # last data date
752781 row = {x : self .last_date .strftime ("%Y-%m" ) for x in df .columns }
753782 row .update (period = None , property = "Common last data date" )
754- description = pd .concat ([description , pd .DataFrame (row , index = [0 ])], ignore_index = True )
783+ description = pd .concat (
784+ [description , pd .DataFrame (row , index = [0 ])], ignore_index = True
785+ )
755786 # rename columns
756787 if hasattr (self , "inflation" ):
757788 description .rename (columns = {self .inflation : "inflation" }, inplace = True )
@@ -929,7 +960,9 @@ def get_dividend_mean_growth_rate(self, period=5) -> pd.Series:
929960 growth_ts = self .dividends_annual .pct_change ().iloc [
930961 1 :- 1
931962 ] # Slice the last year for full dividends
932- growth_ts .replace ([np .inf , - np .inf , np .nan ], 0 , inplace = True ) # replace possible nan and inf
963+ growth_ts .replace (
964+ [np .inf , - np .inf , np .nan ], 0 , inplace = True
965+ ) # replace possible nan and inf
933966 dt0 = self .last_date
934967 dt = helpers .Date .subtract_years (dt0 , period )
935968 return ((growth_ts [dt :] + 1.0 ).prod ()) ** (1 / period ) - 1.0
@@ -1011,12 +1044,12 @@ def tracking_difference_annual(self) -> pd.DataFrame:
10111044 >>> al.tracking_difference_annual.plot(kind='bar')
10121045 """
10131046 result = pd .DataFrame ()
1014- for x in self .assets_ror .resample ('Y' ):
1047+ for x in self .assets_ror .resample ("Y" ):
10151048 df = x [1 ]
10161049 wealth_index = helpers .Frame .get_wealth_indexes (df )
10171050 row = helpers .Index .tracking_difference (wealth_index ).iloc [[- 1 ]]
10181051 result = pd .concat ([result , row ], ignore_index = False )
1019- result .index = result .index .asfreq ('Y' )
1052+ result .index = result .index .asfreq ("Y" )
10201053 return result
10211054
10221055 @property
@@ -1390,11 +1423,14 @@ def get_sharpe_ratio(self, rf_return: float = 0) -> pd.Series:
13901423 BND.US 0.390814
13911424 dtype: float64
13921425 """
1393- mean_return = self .mean_return .drop (self .inflation ) if self .inflation else self .mean_return
1426+ mean_return = (
1427+ self .mean_return .drop (self .inflation )
1428+ if self .inflation
1429+ else self .mean_return
1430+ )
13941431 return ratios .get_sharpe_ratio (
1395- pf_return = mean_return ,
1396- rf_return = rf_return ,
1397- std_deviation = self .risk_annual )
1432+ pf_return = mean_return , rf_return = rf_return , std_deviation = self .risk_annual
1433+ )
13981434
13991435 def get_sortino_ratio (self , t_return : float = 0 ) -> pd .Series :
14001436 """
@@ -1421,9 +1457,17 @@ def get_sortino_ratio(self, t_return: float = 0) -> pd.Series:
14211457 BND.US 0.028969
14221458 dtype: float64
14231459 """
1424- mean_return = self .mean_return .drop (self .inflation ) if self .inflation else self .mean_return
1425- semideviation = helpers .Frame .get_below_target_semideviation (ror = self .assets_ror , t_return = t_return ) * 12 ** 0.5
1460+ mean_return = (
1461+ self .mean_return .drop (self .inflation )
1462+ if self .inflation
1463+ else self .mean_return
1464+ )
1465+ semideviation = (
1466+ helpers .Frame .get_below_target_semideviation (
1467+ ror = self .assets_ror , t_return = t_return
1468+ )
1469+ * 12 ** 0.5
1470+ )
14261471 return ratios .get_sortino_ratio (
1427- pf_return = mean_return ,
1428- t_return = t_return ,
1429- semi_deviation = semideviation )
1472+ pf_return = mean_return , t_return = t_return , semi_deviation = semideviation
1473+ )
0 commit comments