progress. Initial untested version
This commit is contained in:
@@ -27,22 +27,6 @@ class PairState(Enum):
|
||||
CLOSE_STOP_PROFIT = 6
|
||||
|
||||
|
||||
# def get_symbol(instrument: Dict[str, str]) -> str:
|
||||
# if "symbol" in instrument:
|
||||
# return instrument["symbol"]
|
||||
# elif "instrument_id" in instrument:
|
||||
# instrument_id = instrument["instrument_id"]
|
||||
# instrument_pfx = instrument_id[: instrument_id.find("-") + 1]
|
||||
# symbol = instrument_id[len(instrument_pfx) :]
|
||||
# instrument["symbol"] = symbol
|
||||
# instrument["instrument_id_pfx"] = instrument_pfx
|
||||
# return symbol
|
||||
# else:
|
||||
# raise ValueError(
|
||||
# f"Invalid instrument: {instrument}, missing symbol or instrument_id"
|
||||
# )
|
||||
|
||||
|
||||
class TradingPair(NamedObject, ABC):
|
||||
config_: Config
|
||||
model_: Any # "PairsTradingModel"
|
||||
@@ -67,13 +51,12 @@ class TradingPair(NamedObject, ABC):
|
||||
self.instruments_[0].user_data_["symbol"] = instruments[0].instrument_id().split("-", 1)[1]
|
||||
self.instruments_[1].user_data_["symbol"] = instruments[1].instrument_id().split("-", 1)[1]
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"{self.__class__.__name__}:"
|
||||
f" symbol_a={self.symbol_a()},"
|
||||
f" symbol_b={self.symbol_b()},"
|
||||
f" model={self.model_.__class__.__name__}"
|
||||
)
|
||||
def run(self, market_data: pd.DataFrame, data_params: DataWindowParams) -> Prediction: # type: ignore[assignment]
|
||||
self.market_data_ = market_data[
|
||||
data_params.training_start_index_ : data_params.training_start_index_
|
||||
+ data_params.training_size_
|
||||
]
|
||||
return self.model_.predict(pair=self)
|
||||
|
||||
def colnames(self) -> List[str]:
|
||||
return [
|
||||
@@ -91,9 +74,15 @@ class TradingPair(NamedObject, ABC):
|
||||
|
||||
def get_instrument_b(self) -> ExchangeInstrument:
|
||||
return self.instruments_[1]
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"{self.__class__.__name__}:"
|
||||
f" symbol_a={self.symbol_a()},"
|
||||
f" symbol_b={self.symbol_b()},"
|
||||
f" model={self.model_.__class__.__name__}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
class ResearchTradingPair(TradingPair):
|
||||
|
||||
def __init__(
|
||||
@@ -109,8 +98,6 @@ class ResearchTradingPair(TradingPair):
|
||||
"state": PairState.INITIAL,
|
||||
}
|
||||
|
||||
# URGENT set exchange instruments for the pair
|
||||
|
||||
def is_closed(self) -> bool:
|
||||
return self.user_data_["state"] in [
|
||||
PairState.CLOSE,
|
||||
@@ -228,13 +215,6 @@ class ResearchTradingPair(TradingPair):
|
||||
}
|
||||
)
|
||||
|
||||
def run(self, market_data: pd.DataFrame, data_params: DataWindowParams) -> Prediction: # type: ignore[assignment]
|
||||
self.market_data_ = market_data[
|
||||
data_params.training_start_index_ : data_params.training_start_index_
|
||||
+ data_params.training_size_
|
||||
]
|
||||
return self.model_.predict(pair=self)
|
||||
|
||||
class LiveTradingPair(TradingPair):
|
||||
|
||||
def __init__(self, config: Config, instruments: List[ExchangeInstrument]):
|
||||
|
||||
Reference in New Issue
Block a user