Extract conversion to trades list to it's own function
This commit is contained in:
		| @@ -18,10 +18,7 @@ def store_backtest_result(recordfilename: Path, all_results: Dict[str, DataFrame | |||||||
|     :param all_results: Dict of Dataframes, one results dataframe per strategy |     :param all_results: Dict of Dataframes, one results dataframe per strategy | ||||||
|     """ |     """ | ||||||
|     for strategy, results in all_results.items(): |     for strategy, results in all_results.items(): | ||||||
|         records = [(t.pair, t.profit_percent, t.open_time.timestamp(), |         records = backtest_result_to_list(results) | ||||||
|                     t.close_time.timestamp(), t.open_index - 1, t.trade_duration, |  | ||||||
|                     t.open_rate, t.close_rate, t.open_at_end, t.sell_reason.value) |  | ||||||
|                    for index, t in results.iterrows()] |  | ||||||
|  |  | ||||||
|         if records: |         if records: | ||||||
|             filename = recordfilename |             filename = recordfilename | ||||||
| @@ -34,6 +31,18 @@ def store_backtest_result(recordfilename: Path, all_results: Dict[str, DataFrame | |||||||
|             file_dump_json(filename, records) |             file_dump_json(filename, records) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def backtest_result_to_list(results: DataFrame) -> List[List]: | ||||||
|  |     """ | ||||||
|  |     Converts a list of Backtest-results to list | ||||||
|  |     :param results: Dataframe containing results for one strategy | ||||||
|  |     :return: List of Lists containing the trades | ||||||
|  |     """ | ||||||
|  |     return [[t.pair, t.profit_percent, t.open_time.timestamp(), | ||||||
|  |              t.close_time.timestamp(), t.open_index - 1, t.trade_duration, | ||||||
|  |              t.open_rate, t.close_rate, t.open_at_end, t.sell_reason.value] | ||||||
|  |             for index, t in results.iterrows()] | ||||||
|  |  | ||||||
|  |  | ||||||
| def _get_line_floatfmt() -> List[str]: | def _get_line_floatfmt() -> List[str]: | ||||||
|     """ |     """ | ||||||
|     Generate floatformat (goes in line with _generate_result_line()) |     Generate floatformat (goes in line with _generate_result_line()) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user