Esempio n. 1
0
    def _add_table(self, tickers_eval_list):
        table = Table(column_names=["Ticker", "Max SQN per 100 trades", "Avg #trades per 1Y for Max SQN"],
                      css_class="table stats-table")

        sorted_tickers_eval_list = sorted(tickers_eval_list, key=lambda x: x.SQN)

        for ticker_eval in sorted_tickers_eval_list:
            table.add_row([ticker_eval.ticker.as_string(), ticker_eval.SQN, ticker_eval.avg_nr_of_trades_1Y])

        self.document.add_element(table)
Esempio n. 2
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)
Esempio n. 3
0
    def _add_statistics_table(self, ta_list: List[TimeseriesAnalysis]):
        table = Table(css_class="table stats-table")

        for ta in ta_list:
            ta.populate_table(table)
        self.document.add_element(table)
Esempio n. 4
0
    def _add_statistics_table(self):
        table = Table(column_names=["Measure", "Value"], css_class="table stats-table")

        number_of_trades = self.returns_of_trades.count()
        table.add_row(["Number of trades", number_of_trades])

        period_length = self.end_date - self.start_date
        period_length_in_years = to_days(period_length) / DAYS_PER_YEAR_AVG
        avg_number_of_trades = number_of_trades / period_length_in_years / self.nr_of_assets_traded
        table.add_row(["Avg number of trades per year per asset", avg_number_of_trades])

        positive_trades = self.returns_of_trades[self.returns_of_trades > 0]
        negative_trades = self.returns_of_trades[self.returns_of_trades < 0]

        percentage_of_positive = positive_trades.count() / number_of_trades
        percentage_of_negative = negative_trades.count() / number_of_trades
        table.add_row(["% of positive trades", percentage_of_positive * 100])
        table.add_row(["% of negative trades", percentage_of_negative * 100])

        avg_positive = positive_trades.mean()
        avg_negative = negative_trades.mean()
        table.add_row(["Avg positive trade [%]", avg_positive * 100])
        table.add_row(["Avg negative trade [%]", avg_negative * 100])

        best_return = max(self.returns_of_trades)
        worst_return = min(self.returns_of_trades)
        table.add_row(["Best trade [%]", best_return * 100])
        table.add_row(["Worst trade [%]", worst_return * 100])

        max_dd = max_drawdown(self.returns_of_trades)
        table.add_row(["Max drawdown [%]", max_dd * 100])

        prices_tms = self.returns_of_trades.to_prices()
        total_return = prices_tms.iloc[-1] / prices_tms.iloc[0] - 1
        table.add_row(["Total return [%]", total_return * 100])

        annualised_ret = annualise_total_return(total_return, period_length_in_years, SimpleReturnsSeries)
        table.add_row(["Annualised return [%]", annualised_ret * 100])

        avg_return = self.returns_of_trades.mean()
        table.add_row(["Avg return of trade [%]", avg_return * 100])

        std_of_returns = self.returns_of_trades.std()
        table.add_row(["Std of return of trades [%]", std_of_returns * 100])

        # System Quality Number
        sqn = avg_return / std_of_returns
        table.add_row(["SQN", sqn])
        table.add_row(["SQN for 100 trades", sqn * 10])  # SQN * sqrt(100)
        table.add_row(["SQN * Sqrt(avg number of trades per year)", sqn * sqrt(avg_number_of_trades)])

        self.document.add_element(table)
Esempio n. 5
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
Esempio n. 6
0
    def _insert_table_with_overall_measures(self, prices_df: PricesDataFrame, ticker: Ticker):
        table = Table(column_names=["Measure", "Value"], css_class="table stats-table")

        table.add_row(["Instrument", ticker.as_string()])
        series = prices_df[PriceField.Close]
        table.add_row(["Start date", date_to_str(series.index[0])])
        table.add_row(["End date", date_to_str(series.index[-1])])

        trend_strength_overall = trend_strength(prices_df, self.use_next_open_instead_of_close)
        table.add_row(["Overall strength of the day trends", trend_strength_overall])

        trend_strength_1y = trend_strength(prices_df.tail(252), self.use_next_open_instead_of_close)
        table.add_row(["Strength of the day trends in last 1Y", trend_strength_1y])
        self.ticker_to_trend_dict[ticker] = (trend_strength_1y, trend_strength_overall)

        table.add_row(["Up trends strength", up_trend_strength(prices_df, self.use_next_open_instead_of_close)])
        table.add_row(["Down trends strength", down_trend_strength(prices_df, self.use_next_open_instead_of_close)])
        self.document.add_element(table)
Esempio n. 7
0
def _pdf_usage(ta):
    table = Table()
    ta.populate_table(table)