Skip to content

Commit

Permalink
(feat) change encoder decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
cardosofede committed Sep 18, 2023
1 parent c69c8f7 commit d179f58
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
5 changes: 2 additions & 3 deletions pages/backtest_manager/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
from hummingbot.data_feed.candles_feed.candles_factory import CandlesConfig
from hummingbot.smart_components.strategy_frameworks.data_types import OrderLevel
from hummingbot.smart_components.strategy_frameworks.directional_trading import DirectionalTradingBacktestingEngine
from hummingbot.smart_components.utils import ConfigEncoderDecoder

import constants
import os
import json
import streamlit as st
from docker_manager import DockerManager

from quants_lab.strategy.strategy_analysis import StrategyAnalysis
from utils.enum_encoder import EnumEncoderDecoder
from utils.graphs import BacktestingGraphs
from utils.optuna_database_manager import OptunaDBManager
from utils.os_utils import load_controllers, dump_dict_to_yaml
Expand Down Expand Up @@ -60,7 +59,7 @@ def initialize_session_state_vars():
trial_selected = st.selectbox("Select a trial to backtest", list(trials.keys()))
trial = trials[trial_selected]
# Transform trial config in a dictionary
encoder_decoder = EnumEncoderDecoder(TradeType, OrderType, PositionMode)
encoder_decoder = ConfigEncoderDecoder(TradeType, OrderType, PositionMode)
trial_config = encoder_decoder.decode(json.loads(trial["config"]))

# Strategy parameters section
Expand Down
6 changes: 3 additions & 3 deletions pages/backtest_manager/analyze_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from hummingbot.data_feed.candles_feed.candles_factory import CandlesConfig
from hummingbot.smart_components.strategy_frameworks.data_types import OrderLevel, TripleBarrierConf
from hummingbot.smart_components.strategy_frameworks.directional_trading import DirectionalTradingBacktestingEngine
from hummingbot.smart_components.utils import ConfigEncoderDecoder

import constants
import os
Expand All @@ -10,7 +11,6 @@
from decimal import Decimal

from quants_lab.strategy.strategy_analysis import StrategyAnalysis
from utils.enum_encoder import EnumEncoderDecoder
from utils.graphs import BacktestingGraphs
from utils.optuna_database_manager import OptunaDBManager
from utils.os_utils import load_controllers
Expand Down Expand Up @@ -61,7 +61,7 @@ def initialize_session_state_vars():
trial_selected = st.selectbox("Select a trial to backtest", list(trials.keys()))
trial = trials[trial_selected]
# Transform trial config in a dictionary
encoder_decoder = EnumEncoderDecoder(TradeType, OrderType, PositionMode)
encoder_decoder = ConfigEncoderDecoder(TradeType, OrderType, PositionMode)
trial_config = encoder_decoder.decode(json.loads(trial["config"]))

# Strategy parameters section
Expand Down Expand Up @@ -189,7 +189,7 @@ def initialize_session_state_vars():
config = controller["config"](**st.session_state["strategy_params"])
controller = controller["class"](config=config)
if save_config:
encoder_decoder = EnumEncoderDecoder(TradeType, OrderType, PositionMode)
encoder_decoder = ConfigEncoderDecoder(TradeType, OrderType, PositionMode)
encoder_decoder.yaml_dump(config.dict(),
f"hummingbot_files/controller_configs/{config.strategy_name}_{trial_selected}.yml")
run_backtesting_button = st.button("⚙️Run Backtesting!")
Expand Down
8 changes: 4 additions & 4 deletions pages/backtest_manager/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from hummingbot.data_feed.candles_feed.candles_factory import CandlesConfig
from hummingbot.smart_components.strategy_frameworks.data_types import OrderLevel, TripleBarrierConf
from hummingbot.smart_components.strategy_frameworks.directional_trading import DirectionalTradingBacktestingEngine
from streamlit_elements import elements, mui
from hummingbot.smart_components.utils import ConfigEncoderDecoder

import constants
from quants_lab.strategy.strategy_analysis import StrategyAnalysis
from utils.enum_encoder import EnumEncoderDecoder
from utils.graphs import BacktestingGraphs
from utils.os_utils import load_controllers

Expand Down Expand Up @@ -128,9 +127,10 @@
config = controller["config"](**st.session_state["strategy_params"])
controller = controller["class"](config=config)
if save_config:
encoder_decoder = EnumEncoderDecoder(TradeType, OrderType, PositionMode)
encoder_decoder = ConfigEncoderDecoder(TradeType, OrderType, PositionMode)
# TODO: make this configurable
encoder_decoder.yaml_dump(config.dict(),
f"hummingbot_files/controller_configs/{config.strategy_name}_{trial_selected}.yml")
f"hummingbot_files/controller_configs/{config.strategy_name}.yml")
run_backtesting_button = st.button("⚙️Run Backtesting!")
if run_backtesting_button:
try:
Expand Down

0 comments on commit d179f58

Please sign in to comment.