def calc_calendar_distribution(df_signal): daily_signal = df_signal.sum(axis=1) daily_signal = daily_signal.fillna(0).astype(int) idx = daily_signal.index.values month = jutil.date_to_month(idx) year = jutil.date_to_year(idx) monthly_signal = daily_signal.groupby(by=month).sum() yearly_signal = daily_signal.groupby(by=year).sum() monthly_signal = pd.DataFrame(monthly_signal, columns=['Time']) yearly_signal = pd.DataFrame(yearly_signal, columns=['Time']) monthly_signal.index.name = 'Month' yearly_signal.index.name = 'Year' return daily_signal, monthly_signal, yearly_signal
def get_stats(self): df_return = self.returns.copy() idx = df_return.index df_return.loc[:, 'daily_active'] = df_return['strat'] - df_return['bench'] df_return.loc[:, 'month'] = jutil.date_to_month(idx) df_return.loc[:, 'year'] = jutil.date_to_year(idx) def calc_cum(df): return np.prod(df.add(1.0)) - 1.0 stats_monthly = df_return.groupby('month')['daily_active'].apply( calc_cum) stats_yearly = df_return.groupby('year')['daily_active'].apply( calc_cum) ''' plt.figure(figsize=(16, 10)) sns.distplot(df_return['daily_active'], bins=np.arange(-5e-2, 5e-2, 1e-3), kde=False) plt.savefig('a.png') plt.close() ''' print