pmorissette / ffn

ffn - a financial function library for Python
pmorissette.github.io/ffn
MIT License
1.86k stars 283 forks source link

Daily Mean Hard Coded Definition #168

Open staymadson opened 2 years ago

staymadson commented 2 years ago
            self.daily_mean = r.mean() * 252
            self.daily_vol = np.std(r, ddof=1) * np.sqrt(252)

            # if type(self.rf) is float:
            if isinstance(self.rf, float):
                self.daily_sharpe = r.calc_sharpe(rf=self.rf, nperiods=252)
                self.daily_sortino = calc_sortino_ratio(r, rf=self.rf, nperiods=252)
            # rf is a price series
            else:
                _rf_daily_price_returns = self.rf.to_returns()
                self.daily_sharpe = r.calc_sharpe(
                    rf=_rf_daily_price_returns, nperiods=252
                )
                self.daily_sortino = calc_sortino_ratio(
                    r, rf=_rf_daily_price_returns, nperiods=252
                )

The yearly return data is hard coded to 252 days which accurately represents trading on the NYSE or other standard markets. However, other markets trade 365 (366) days per year, or somewhere in between (e.g. 6 days a week for futures). The returns should either dynamically adjust based on the time series presented or offer an ability to set the number of trading days.

timkpaine commented 2 years ago

https://github.com/pmorissette/ffn/pull/145