feat: bt-result to tabulate
This commit is contained in:
@@ -379,8 +379,8 @@ def text_table_add_metrics(strat_results: Dict) -> str:
|
|||||||
*drawdown_metrics,
|
*drawdown_metrics,
|
||||||
("Market change", f"{strat_results['market_change']:.2%}"),
|
("Market change", f"{strat_results['market_change']:.2%}"),
|
||||||
]
|
]
|
||||||
|
print_rich_table(metrics, ["Metric", "Value"], summary="SUMMARY METRICS", justify="left")
|
||||||
|
|
||||||
return tabulate(metrics, headers=["Metric", "Value"], tablefmt="orgtbl")
|
|
||||||
else:
|
else:
|
||||||
start_balance = fmt_coin(strat_results["starting_balance"], strat_results["stake_currency"])
|
start_balance = fmt_coin(strat_results["starting_balance"], strat_results["stake_currency"])
|
||||||
stake_amount = (
|
stake_amount = (
|
||||||
@@ -394,7 +394,7 @@ def text_table_add_metrics(strat_results: Dict) -> str:
|
|||||||
f"Your starting balance was {start_balance}, "
|
f"Your starting balance was {start_balance}, "
|
||||||
f"and your stake was {stake_amount}."
|
f"and your stake was {stake_amount}."
|
||||||
)
|
)
|
||||||
return message
|
print(message)
|
||||||
|
|
||||||
|
|
||||||
def _show_tag_subresults(results: Dict[str, Any], stake_currency: str):
|
def _show_tag_subresults(results: Dict[str, Any], stake_currency: str):
|
||||||
@@ -439,13 +439,7 @@ def show_backtest_result(
|
|||||||
days_breakdown_stats=days_breakdown_stats, stake_currency=stake_currency, period=period
|
days_breakdown_stats=days_breakdown_stats, stake_currency=stake_currency, period=period
|
||||||
)
|
)
|
||||||
|
|
||||||
table = text_table_add_metrics(results)
|
text_table_add_metrics(results)
|
||||||
if isinstance(table, str) and len(table) > 0:
|
|
||||||
print(" SUMMARY METRICS ".center(len(table.splitlines()[0]), "="))
|
|
||||||
print(table)
|
|
||||||
|
|
||||||
if isinstance(table, str) and len(table) > 0:
|
|
||||||
print("=" * len(table.splitlines()[0]))
|
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ def print_rich_table(
|
|||||||
headers: Sequence[str],
|
headers: Sequence[str],
|
||||||
summary: Optional[str] = None,
|
summary: Optional[str] = None,
|
||||||
*,
|
*,
|
||||||
|
justify="right",
|
||||||
table_kwargs: Optional[Dict[str, Any]] = None,
|
table_kwargs: Optional[Dict[str, Any]] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
table = Table(
|
table = Table(
|
||||||
*[c if isinstance(c, Column) else Column(c, justify="right") for c in headers],
|
*[c if isinstance(c, Column) else Column(c, justify=justify) for c in headers],
|
||||||
title=summary,
|
title=summary,
|
||||||
**(table_kwargs or {}),
|
**(table_kwargs or {}),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user