def get_portfolio_current_value(): simulated_value = 0 real_value = 0 has_real_trader = False has_simulated_trader = False for exchange_manager in interfaces.get_exchange_managers(): if trading_api.is_trader_existing_and_enabled(exchange_manager): current_value = trading_api.get_current_portfolio_value( exchange_manager) # current_value might be 0 if no trades have been made / canceled => use origin value if current_value == 0: current_value = trading_api.get_origin_portfolio_value( exchange_manager) if trading_api.is_trader_simulated(exchange_manager): simulated_value += current_value has_simulated_trader = True else: real_value += current_value has_real_trader = True return has_real_trader, has_simulated_trader, real_value, simulated_value
def _log_global_report(self, exchange_manager): _, profitability, _, market_average_profitability, _ = trading_api.get_profitability_stats( exchange_manager) reference_market = trading_api.get_reference_market( self.backtesting_config) end_portfolio = trading_api.get_portfolio(exchange_manager) end_portfolio_value = trading_api.get_current_portfolio_value( exchange_manager) starting_portfolio = trading_api.get_origin_portfolio(exchange_manager) starting_portfolio_value = trading_api.get_origin_portfolio_value( exchange_manager) self.logger.info( f"[End portfolio] value {round(end_portfolio_value, 5)} {reference_market} " f"Holdings: {pretty_printer.global_portfolio_pretty_print(end_portfolio, ' | ')}" ) self.logger.info( f"[Starting portfolio] value {round(starting_portfolio_value, 5)} {reference_market} " f"Holdings: {pretty_printer.global_portfolio_pretty_print(starting_portfolio, ' | ')}" ) self.logger.info( f"Global market profitability (vs {reference_market}) : " f"{market_average_profitability}% | Octobot : {profitability}%") self.logger.info( f"Simulation lasted " f"{round(backtesting_api.get_backtesting_duration(self.octobot_backtesting.backtesting), 3)} sec" )
def get_global_profitability(): simulated_global_profitability = 0 real_global_profitability = 0 simulated_no_trade_profitability = 0 real_no_trade_profitability = 0 simulated_full_origin_value = 0 real_full_origin_value = 0 market_average_profitability = None has_real_trader = False has_simulated_trader = False for exchange_manager in interfaces.get_exchange_managers(): if trading_api.is_trader_existing_and_enabled(exchange_manager): current_value, _, _, market_average_profitability, initial_portfolio_current_profitability = \ trading_api.get_profitability_stats(exchange_manager) if trading_api.is_trader_simulated(exchange_manager): simulated_full_origin_value += trading_api.get_origin_portfolio_value( exchange_manager) simulated_global_profitability += current_value simulated_no_trade_profitability += initial_portfolio_current_profitability has_simulated_trader = True else: real_full_origin_value += trading_api.get_origin_portfolio_value( exchange_manager) real_global_profitability += current_value real_no_trade_profitability += initial_portfolio_current_profitability has_real_trader = True simulated_percent_profitability = simulated_global_profitability * 100 / simulated_full_origin_value \ if simulated_full_origin_value > 0 else 0 real_percent_profitability = real_global_profitability * 100 / real_full_origin_value \ if real_full_origin_value > 0 else 0 return has_real_trader, has_simulated_trader, \ real_global_profitability, simulated_global_profitability, \ real_percent_profitability, simulated_percent_profitability, \ real_no_trade_profitability, simulated_no_trade_profitability, \ market_average_profitability
def _get_real_portfolio_value(self): if self.has_real_trader: total_value = 0 for exchange_manager in self.exchange_managers: current_value = trading_api.get_current_portfolio_value( exchange_manager) # current_value might be 0 if no trades have been made / canceled => use origin value if current_value == 0: current_value = trading_api.get_origin_portfolio_value( exchange_manager) total_value += current_value return float(total_value) else: return 0