stats_utils.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:catalyst 作者: enigmampc 项目源码 文件源码
def get_pretty_stats(stats, recorded_cols=None, num_rows=10):
    """
    Format and print the last few rows of a statistics DataFrame.
    See the pyfolio project for the data structure.

    Parameters
    ----------
    stats: list[Object]
        An array of statistics for the period.

    num_rows: int
        The number of rows to display on the screen.

    Returns
    -------
    str

    """
    if isinstance(stats, pd.DataFrame):
        stats = stats.T.to_dict().values()

    df, columns = prepare_stats(stats, recorded_cols=recorded_cols)

    pd.set_option('display.expand_frame_repr', False)
    pd.set_option('precision', 8)
    pd.set_option('display.width', 1000)
    pd.set_option('display.max_colwidth', 1000)

    formatters = {
        'returns': lambda returns: "{0:.4f}".format(returns),
    }

    return df.tail(num_rows).to_string(
        columns=columns,
        formatters=formatters
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号