def cal_summary_table_enhanced_fund(fund_name, fund_code, fund_type, date_array, benchmark_code, benchmark_name, benchmark_ratio=1.0): """ 指数型基金表现总结 分区间计算 基金和基准表现(累计收益 年化收益 超额收益 跟踪误差 信息比率 超额收益最大回撤等) """ # 分类读取基金数据 fund_data = MfcData().get_mfc_nav(fund_code, fund_name, fund_type) benchmark_data = Index().get_index_factor(benchmark_code, attr=["CLOSE"]) enhanced_table = pd.DataFrame([], columns=date_array[:, 0]) fs = FinancialSeries(pd.DataFrame(fund_data), pd.DataFrame(benchmark_data), benchmark_ratio) for i_date in range(date_array.shape[0]): label = date_array[i_date, 0] bd = Date().change_to_str(date_array[i_date, 1]) ed = Date().change_to_str(date_array[i_date, 2]) enhanced_table.loc[fund_name + "累计收益", label] = fs.get_interval_return(bd, ed) enhanced_table.loc[benchmark_name + "累计收益", label] = fs.get_interval_return_benchmark( bd, ed) bench_return = fs.get_interval_return_benchmark_ratio(bd, ed) enhanced_table.loc[benchmark_name + "*%s累计收益" % benchmark_ratio, label] = bench_return enhanced_table.loc[fund_name + "超额收益", label] = fs.get_interval_excess_return(bd, ed) enhanced_table.loc[fund_name + "超额年化收益", label] = fs.get_interval_excess_return_annual( bd, ed) enhanced_table.loc[fund_name + "跟踪误差", label] = fs.get_interval_tracking_error(bd, ed) enhanced_table.loc[fund_name + "信息比率", label] = fs.get_interval_mean_ir(bd, ed) enhanced_table.loc[ fund_name + "超额收益最大回撤", label] = fs.get_interval_excess_return_max_drawdown(bd, ed) enhanced_table.loc[fund_name + "标准差", label] = fs.get_interval_std_annual(bd, ed) enhanced_table.loc[fund_name + "夏普比率", label] = fs.get_interval_shape_ratio( bd, ed, 0.03) enhanced_table.loc[fund_name + "最大回撤", label] = fs.get_interval_max_drawdown(bd, ed) enhanced_table.loc[fund_name + "年化收益", label] = fs.get_interval_return_annual(bd, ed) enhanced_table.loc[ benchmark_name + "年化收益", label] = fs.get_interval_return_annual_benchmark(bd, ed) return enhanced_table
def cal_summary_period(self, beg_date=None, end_date=None): """ 计算组合在区间内 收益率、波动率等表现情况 并画图并存储图片 """ self.get_port_return() if beg_date is None: beg_date = self.port_return.index[0] if end_date is None: end_date = self.port_return.index[-1] fs = FinancialSeries( pd.DataFrame(self.port_return["CumPortReturn"] + 1.0), pd.DataFrame(self.port_return["CumIndexReturn"] + 1.0)) port_return = self.port_return.loc[beg_date:end_date, :] result = pd.DataFrame([]) beg_date = port_return.index[0] end_date = port_return.index[-1] label = str(beg_date)[0:4] + '年' result.loc[label, '开始时间'] = beg_date result.loc[label, '结束时间'] = end_date result.loc[label, "收益率"] = fs.get_interval_return(beg_date, end_date) result.loc[label, "年化收益率"] = fs.get_interval_return_annual( beg_date, end_date) result.loc[label, "年化波动率"] = fs.get_interval_std_annual(beg_date, end_date) result.loc[label, "年化跟踪误差"] = fs.get_interval_tracking_error( beg_date, end_date) result.loc[label, "最大回撤率"] = fs.get_interval_max_drawdown(beg_date, end_date) result.loc[label, "超额收益率"] = fs.get_interval_excess_return( beg_date, end_date) result.loc[label, "年化超额收益率"] = fs.get_interval_excess_return_annual( beg_date, end_date) result.loc[label, "超额收益率最大回撤"] = fs.get_interval_excess_return_max_drawdown( beg_date, end_date) result.loc[label, "基准收益率"] = fs.get_interval_return_benchmark( beg_date, end_date) result.loc[label, "基准年化收益率"] = fs.get_interval_return_annual_benchmark( beg_date, end_date) result.loc[label, "基准年化波动率"] = fs.get_interval_std_annual_benchmark( beg_date, end_date) result.loc[label, "基准最大回撤率"] = fs.get_interval_max_drawdown_benchmark( beg_date, end_date) self.plot_port_return_period(beg_date, end_date) return result.T