def get_stats(self): # call get_logs before calling this function stats = pf.stats(self.ts, self.tlog, self.dbal, self.capital) return stats
def _get_stats(self): self.stats = pf.stats(self.ts, self.tlog, self.dbal, self.capital)
def stats(self): tlog, dbal = self.get_logs() stats = pf.stats(self._ts, tlog, dbal, self._start, self._end, self._capital) return stats
def get_stats(self): stats = pf.stats(self.ts, self.tlog, self.dbal, self.capital) return stats
def stats(self): tlog, dbal = self.get_logs() stats = pf.stats(self._ts, tlog, dbal, self._start, self._end, self._capital) return stats
def _get_stats(self): """ Get the statistics for the benchmark. """ self.stats = pf.stats(self.ts, self.tlog, self.dbal, self.capital)
# update cash cash = tlog.calc_cash(cash, close, shares) else: dbal.append(date, high, low, close, shares, cash, pf.TradeState.HOLD) t1 = time.time() total = t1 - t0 print(total) tlog = tlog.get_log() tlog.tail(100) dbal = dbal.get_log() dbal.tail() stats = pf.stats(ts, tlog, dbal, start, end, capital) pf.print_full(stats) benchmark = pf.Benchmark('SPY', capital, start, end) benchmark.run() benchmark.tlog, benchmark.dbal = benchmark.get_logs() benchmark.stats = benchmark.stats() pf.print_full(benchmark.stats) pf.plot_equity_curve(dbal, benchmark=benchmark.dbal) plt.show() pf.plot_trades(dbal, benchmark=benchmark.dbal) plt.show() metrics = ('annual_return_rate', 'max_closed_out_drawdown', 'drawdown_annualized_return', 'drawdown_recovery', 'best_month', 'worst_month', 'sharpe_ratio', 'sortino_ratio', 'monthly_std') df = pf.plot_bar_graph(stats, *metrics) plt.show()