1、卡尔曼策略
This commit is contained in:
@@ -33,6 +33,7 @@ class Strategy(ABC):
|
||||
"""
|
||||
self.context = context # 存储 context 对象
|
||||
self.symbol = symbol # 策略操作的合约Symbol
|
||||
self.main_symbol = symbol
|
||||
self.params = params
|
||||
self.enable_log = enable_log
|
||||
self.trading = False
|
||||
@@ -187,7 +188,7 @@ class Strategy(ABC):
|
||||
|
||||
# 你可以将其他 kwargs (如 sep, end, file, flush) 传递给 print,
|
||||
# 但通常日志方法不会频繁使用这些。这里只支持最基础的打印。
|
||||
print(f"{time_prefix}策略 ({self.symbol}): {message}", **kwargs)
|
||||
print(f"{time_prefix}策略 ({self.symbol}): {message}")
|
||||
|
||||
def on_rollover(self, old_symbol: str, new_symbol: str):
|
||||
"""
|
||||
@@ -219,13 +220,21 @@ class Strategy(ABC):
|
||||
return self._indicator_cache
|
||||
|
||||
# 数据有变化,重新创建数组并更新缓存
|
||||
close = np.array(close_data)
|
||||
open_price = np.array(self.get_price_history("open"))
|
||||
high = np.array(self.get_price_history("high"))
|
||||
low = np.array(self.get_price_history("low"))
|
||||
volume = np.array(self.get_price_history("volume"))
|
||||
close = np.array(close_data[-1000:])
|
||||
open_price = np.array(self.get_price_history("open")[-1000:])
|
||||
high = np.array(self.get_price_history("high")[-1000:])
|
||||
low = np.array(self.get_price_history("low")[-1000:])
|
||||
volume = np.array(self.get_price_history("volume")[-1000:])
|
||||
|
||||
self._indicator_cache = (close, open_price, high, low, volume)
|
||||
self._cache_length = current_length
|
||||
|
||||
return self._indicator_cache
|
||||
|
||||
def save_state(self, state: Any) -> None:
|
||||
if self.trading:
|
||||
self.context.save_state(state)
|
||||
|
||||
def load_state(self) -> None:
|
||||
if self.trading:
|
||||
self.context.load_state()
|
||||
|
||||
Reference in New Issue
Block a user