|
7 | 7 | from tabulate import tabulate
|
8 | 8 |
|
9 | 9 | from investing_algorithm_framework.domain import DATETIME_FORMAT, \
|
10 |
| - BacktestDateRange, TradeStatus, OrderSide |
| 10 | + BacktestDateRange, TradeStatus, OrderSide, TradeRiskType |
11 | 11 | from investing_algorithm_framework.domain.exceptions import \
|
12 | 12 | OperationalException
|
13 | 13 | from investing_algorithm_framework.domain.models.backtesting import \
|
@@ -141,12 +141,12 @@ def get_high_water_mark(stop_loss):
|
141 | 141 |
|
142 | 142 | def get_stop_loss_price(take_profit):
|
143 | 143 |
|
144 |
| - if take_profit["trade_risk_type"] == "trailing": |
| 144 | + if TradeRiskType.TRAILING.equals(take_profit["trade_risk_type"]): |
145 | 145 | initial_price = take_profit["open_price"]
|
146 | 146 | percentage = take_profit["percentage"]
|
147 | 147 | initial_stop_loss_price = \
|
148 | 148 | initial_price * (1 - (percentage / 100))
|
149 |
| - return f"{float(take_profit['stop_loss_price']):.{price_precision}f}({take_profit['percentage']})% ({initial_stop_loss_price}:.{price_precision}) {take_profit['trading_symbol']}" |
| 149 | + return f"{float(take_profit['stop_loss_price']):.{price_precision}f} ({(initial_stop_loss_price):.{price_precision}f}) ({take_profit['percentage']})% {take_profit['trading_symbol']}" |
150 | 150 | else:
|
151 | 151 | return f"{float(take_profit['stop_loss_price']):.{price_precision}f}({take_profit['percentage']})% {take_profit['trading_symbol']}"
|
152 | 152 |
|
@@ -217,7 +217,7 @@ def get_stop_loss_price(take_profit):
|
217 | 217 | stop_loss_table["Type"] = [
|
218 | 218 | f"{stop_loss['trade_risk_type']}" for stop_loss in selection
|
219 | 219 | ]
|
220 |
| - stop_loss_table["Stop Loss"] = [ |
| 220 | + stop_loss_table["Stop Loss (Initial Stop Loss)"] = [ |
221 | 221 | get_stop_loss_price(stop_loss) for stop_loss in selection
|
222 | 222 | ]
|
223 | 223 | stop_loss_table["Open price"] = [
|
@@ -268,12 +268,12 @@ def get_sold_amount(take_profit):
|
268 | 268 |
|
269 | 269 | def get_take_profit_price(take_profit):
|
270 | 270 |
|
271 |
| - if take_profit["trade_risk_type"] == "TRAILING": |
| 271 | + if TradeRiskType.TRAILING.equals(take_profit["trade_risk_type"]): |
272 | 272 | initial_price = take_profit["open_price"]
|
273 | 273 | percentage = take_profit["percentage"]
|
274 | 274 | initial_take_profit_price = \
|
275 | 275 | initial_price * (1 + (percentage / 100))
|
276 |
| - return f"{float(take_profit['take_profit_price']):.{price_precision}f}({take_profit['percentage']})% ({initial_take_profit_price}) {take_profit['trading_symbol']}" |
| 276 | + return f"{float(take_profit['take_profit_price']):.{price_precision}f} ({(initial_take_profit_price):.{price_precision}f}) ({take_profit['percentage']})% {take_profit['trading_symbol']}" |
277 | 277 | else:
|
278 | 278 | return f"{float(take_profit['take_profit_price']):.{price_precision}f}({take_profit['percentage']})% {take_profit['trading_symbol']}"
|
279 | 279 |
|
@@ -355,7 +355,7 @@ def get_status(take_profit):
|
355 | 355 | f"{stop_loss['trade_risk_type']}" for stop_loss
|
356 | 356 | in selection
|
357 | 357 | ]
|
358 |
| - take_profit_table["Take profit"] = [ |
| 358 | + take_profit_table["Take profit (Initial Take Profit)"] = [ |
359 | 359 | get_take_profit_price(stop_loss) for stop_loss in selection
|
360 | 360 | ]
|
361 | 361 | take_profit_table["Open price"] = [
|
@@ -772,7 +772,7 @@ def pretty_print_backtest(
|
772 | 772 | .:=+#%%%%%*###%%%%#*+#%%%%%%*+-: {COLOR_YELLOW}Initial balance:{COLOR_RESET}{COLOR_GREEN} {backtest_report.initial_unallocated}{COLOR_RESET}
|
773 | 773 | +%%%%%%%%%%%%%%%%%%%= {COLOR_YELLOW}Final balance:{COLOR_RESET}{COLOR_GREEN} {float(backtest_report.total_value):.{price_precision}f}{COLOR_RESET}
|
774 | 774 | :++ .=#%%%%%%%%%%%%%*- {COLOR_YELLOW}Total net gain:{COLOR_RESET}{COLOR_GREEN} {float(backtest_report.total_net_gain):.{price_precision}f} {float(backtest_report.total_net_gain_percentage):.{percentage_precision}}%{COLOR_RESET}
|
775 |
| - :++: :+%%%%%%#-. {COLOR_YELLOW}Growth:{COLOR_RESET}{COLOR_GREEN} {float(backtest_report.growth):.{price_precision}f} {float(backtest_report.growth_rate):.{percentage_precision}}%{COLOR_RESET} |
| 775 | + :++: :+%%%%%%#-. {COLOR_YELLOW}Growth:{COLOR_RESET}{COLOR_GREEN} {float(backtest_report.growth):.{price_precision}f} {float(backtest_report.growth_rate):.{percentage_precision}f}%{COLOR_RESET} |
776 | 776 | :++: .%%%%%#= {COLOR_YELLOW}Number of trades closed:{COLOR_RESET}{COLOR_GREEN} {backtest_report.number_of_trades_closed}{COLOR_RESET}
|
777 | 777 | :++: .#%%%%%#*= {COLOR_YELLOW}Number of trades open(end of backtest):{COLOR_RESET}{COLOR_GREEN} {backtest_report.number_of_trades_open}{COLOR_RESET}
|
778 | 778 | :++- :%%%%%%%%%+= {COLOR_YELLOW}Percentage positive trades:{COLOR_RESET}{COLOR_GREEN} {backtest_report.percentage_positive_trades}%{COLOR_RESET}
|
|
0 commit comments