@@ -756,40 +756,6 @@ def perf_stats(returns, factor_returns=None):
756
756
return stats
757
757
758
758
759
- def get_max_drawdown_underwater (underwater ):
760
- """Determines peak, valley, and recovery dates given and 'underwater'
761
- DataFrame.
762
-
763
- An underwater DataFrame is a DataFrame that has precomputed
764
- rolling drawdown.
765
-
766
- Parameters
767
- ----------
768
- underwater : pd.Series
769
- Underwater returns (rolling drawdown) of a strategy.
770
-
771
- Returns
772
- -------
773
- peak : datetime
774
- The maximum drawdown's peak.
775
- valley : datetime
776
- The maximum drawdown's valley.
777
- recovery : datetime
778
- The maximum drawdown's recovery.
779
-
780
- """
781
-
782
- valley = np .argmax (underwater ) # end of the period
783
- # Find first 0
784
- peak = underwater [:valley ][underwater [:valley ] == 0 ].index [- 1 ]
785
- # Find last 0
786
- try :
787
- recovery = underwater [valley :][underwater [valley :] == 0 ].index [0 ]
788
- except IndexError :
789
- recovery = np .nan # drawdown not recovered
790
- return peak , valley , recovery
791
-
792
-
793
759
def perf_stats_bootstrap (returns , factor_returns = None ):
794
760
"""Calculates various performance metrics of a strategy, for use in
795
761
plotting.show_perf_stats.
@@ -822,16 +788,50 @@ def do_boostrap(stat_func, *args):
822
788
stats .loc [stat_name , '5%' ] = bootstrap_stats ['5%' ]
823
789
stats .loc [stat_name , '95%' ] = bootstrap_stats ['95%' ]
824
790
825
- for stat_func in simple_stat_funcs :
791
+ for stat_func in SIMPLE_STAT_FUNCS :
826
792
do_boostrap (stat_func , returns )
827
793
828
794
if factor_returns is not None :
829
- for stat_func in factor_stat_funcs :
795
+ for stat_func in FACTOR_STAT_FUNCS :
830
796
do_bootstrap (stat_func , returns , factor_returns )
831
797
832
798
return stats
833
799
834
800
801
+ def get_max_drawdown_underwater (underwater ):
802
+ """Determines peak, valley, and recovery dates given and 'underwater'
803
+ DataFrame.
804
+
805
+ An underwater DataFrame is a DataFrame that has precomputed
806
+ rolling drawdown.
807
+
808
+ Parameters
809
+ ----------
810
+ underwater : pd.Series
811
+ Underwater returns (rolling drawdown) of a strategy.
812
+
813
+ Returns
814
+ -------
815
+ peak : datetime
816
+ The maximum drawdown's peak.
817
+ valley : datetime
818
+ The maximum drawdown's valley.
819
+ recovery : datetime
820
+ The maximum drawdown's recovery.
821
+
822
+ """
823
+
824
+ valley = np .argmax (underwater ) # end of the period
825
+ # Find first 0
826
+ peak = underwater [:valley ][underwater [:valley ] == 0 ].index [- 1 ]
827
+ # Find last 0
828
+ try :
829
+ recovery = underwater [valley :][underwater [valley :] == 0 ].index [0 ]
830
+ except IndexError :
831
+ recovery = np .nan # drawdown not recovered
832
+ return peak , valley , recovery
833
+
834
+
835
835
def get_max_drawdown (returns ):
836
836
"""
837
837
Finds maximum drawdown.
0 commit comments