コード例 #1
0
    def _add_rolling_table(self):
        dtos = RollingAnalysisFactory.calculate_analysis(self.strategy_series, self.benchmark_series)

        column_names = [
            Table.ColumnCell("Rolling Return Period", css_class="left-align"),
            "Strategy Average",
            "Strategy Worst",
            Table.ColumnCell("Strategy Best", css_class="right-align"),
            "Benchmark Average",
            "Benchmark Worst",
            Table.ColumnCell("Benchmark Best", css_class="right-align"),
            Table.ColumnCell("% Strategy outperform Benchmark")]
        result = Table(column_names, grid_proportion=GridProportion.Sixteen, css_class="table rolling-table")

        for dto in dtos:
            result.add_row([Table.Cell(dto.period, css_class="right-align"),
                            Table.Cell(dto.strategy_average, "{:.2%}"),
                            Table.Cell(dto.strategy_worst, "{:.2%}"),
                            Table.Cell(dto.strategy_best, "{:.2%}"),
                            Table.Cell(dto.benchmark_average, "{:.2%}"),
                            Table.Cell(dto.benchmark_worst, "{:.2%}"),
                            Table.Cell(dto.benchmark_best, "{:.2%}"),
                            Table.Cell(dto.percentage_difference, "{:.2%}")])

        self.document.add_element(result)
コード例 #2
0
    def populate_table(self, table: Table, name=None) -> None:
        """
        Adds the data calculated in this analysis to the specified table. The table may be brand new or contain other
        analyses of the same kind.

        Parameters
        ----------
        table
            The table to add the data to.
        name
            Name to give this analysis in the columns.
        """
        new_table = Table()

        if name is None:
            name = self.returns_tms.name

        new_table.set_column_names(["Statistic", name])
        for item in self._get_results_list():
            row_name = item[1] + " [" + item[3] + "]"
            if item[3] == '':
                row_name = item[1]

            new_table.add_row([row_name, Table.Cell(item[2])])

        if len(table.rows) != 0:
            new_table = table.combine(new_table)

        table.set_column_names(new_table.get_column_names())
        table.rows = new_table.rows