fix: Update TradingBot signal processing to handle NaN values and improve MLFilter ONNX session configuration
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import pandas as pd
|
||||
from loguru import logger
|
||||
from src.config import Config
|
||||
from src.exchange import BinanceFuturesClient
|
||||
@@ -108,9 +109,9 @@ class TradingBot:
|
||||
|
||||
last_row = df.iloc[-1]
|
||||
signal_snapshot = {
|
||||
"rsi": float(last_row.get("rsi", 0)),
|
||||
"macd_hist": float(last_row.get("macd_hist", 0)),
|
||||
"atr": float(last_row.get("atr", 0)),
|
||||
"rsi": float(last_row["rsi"]) if "rsi" in last_row.index and pd.notna(last_row["rsi"]) else 0.0,
|
||||
"macd_hist": float(last_row["macd_hist"]) if "macd_hist" in last_row.index and pd.notna(last_row["macd_hist"]) else 0.0,
|
||||
"atr": float(last_row["atr"]) if "atr" in last_row.index and pd.notna(last_row["atr"]) else 0.0,
|
||||
}
|
||||
|
||||
self.current_trade_side = signal
|
||||
|
||||
@@ -53,8 +53,12 @@ class MLFilter:
|
||||
if self._onnx_path.exists():
|
||||
try:
|
||||
import onnxruntime as ort
|
||||
sess_opts = ort.SessionOptions()
|
||||
sess_opts.intra_op_num_threads = 1
|
||||
sess_opts.inter_op_num_threads = 1
|
||||
self._onnx_session = ort.InferenceSession(
|
||||
str(self._onnx_path),
|
||||
sess_options=sess_opts,
|
||||
providers=["CPUExecutionProvider"],
|
||||
)
|
||||
self._lgbm_model = None
|
||||
|
||||
@@ -71,10 +71,15 @@ def _export_onnx(
|
||||
transB=1),
|
||||
# sigmoid → (N, 1)
|
||||
helper.make_node("Sigmoid", ["logits"], ["proba_2d"]),
|
||||
# squeeze: (N, 1) → (N,)
|
||||
helper.make_node("Flatten", ["proba_2d"], ["proba"], axis=0),
|
||||
# squeeze: (N, 1) → (N,) — axis=-1 로 마지막 차원만 제거
|
||||
helper.make_node("Squeeze", ["proba_2d", "squeeze_axes"], ["proba"]),
|
||||
]
|
||||
|
||||
squeeze_axes = numpy_helper.from_array(
|
||||
np.array([-1], dtype=np.int64), name="squeeze_axes"
|
||||
)
|
||||
initializers.append(squeeze_axes)
|
||||
|
||||
graph = helper.make_graph(
|
||||
nodes,
|
||||
"mlx_filter",
|
||||
|
||||
Reference in New Issue
Block a user