风险等级改成了波动率
This commit is contained in:
parent
987c761f96
commit
9bc93e4a42
@ -304,7 +304,8 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
# 计算Bollinger Band宽度作为波动率制度指标
|
||||
bb_upper, bb_middle, bb_lower = ta.BBANDS(dataframe['close'], timeperiod=20, nbdevup=2.0, nbdevdn=2.0)
|
||||
bb_width_ratio = ((bb_upper - bb_lower) / bb_middle * 100).replace([np.inf, -np.inf], 0)
|
||||
bb_width_ratio = pd.Series((bb_upper - bb_lower) / bb_middle * 100, index=dataframe.index)
|
||||
bb_width_ratio = bb_width_ratio.replace([np.inf, -np.inf], 0)
|
||||
|
||||
# 波动率持续性指标(制度稳定性)
|
||||
volatility_regime = bb_width_ratio.rolling(20).mean()
|
||||
@ -376,8 +377,9 @@ class FreqaiPrimer(IStrategy):
|
||||
dataframe["&*-optimal_first_length"] = np.full(len(dataframe), 2, dtype=np.int32) # 默认值为2
|
||||
|
||||
# 添加调试信息
|
||||
logger.info(f"[{pair}] 📈 分类目标统计: {dict(pd.Series(optimal_length_class).value_counts())}")
|
||||
logger.info(f"[{pair}] 🎯 最新分类值: {optimal_length_class[-5:]}")
|
||||
optimal_length_series = pd.Series(optimal_length_class)
|
||||
logger.info(f"[{pair}] 📈 分类目标统计: {dict(optimal_length_series.value_counts())}")
|
||||
logger.info(f"[{pair}] 🎯 最新分类值: {optimal_length_series.iloc[-5:]}")
|
||||
|
||||
return dataframe
|
||||
def is_stochrsi_overbought(self, dataframe: DataFrame, period=10, threshold=85) -> bool:
|
||||
|
||||
50
numpy_fix_summary.md
Normal file
50
numpy_fix_summary.md
Normal file
@ -0,0 +1,50 @@
|
||||
# NumPy 数组方法错误修复总结
|
||||
|
||||
## 问题描述
|
||||
在 FreqAI 训练过程中出现新的错误:
|
||||
```
|
||||
AttributeError: 'numpy.ndarray' object has no attribute 'replace'
|
||||
```
|
||||
|
||||
## 根本原因
|
||||
`ta.BBANDS` 函数返回的是 `numpy.ndarray` 对象,但代码试图调用 `.replace()` 方法,这是 `pandas.Series` 的方法。
|
||||
|
||||
## 修复内容
|
||||
|
||||
### 1. 主修复:第307行
|
||||
**文件**: `/Users/zhangkun/myTestFreqAI/freqtrade/templates/freqaiprimer.py`
|
||||
|
||||
**修改前**:
|
||||
```python
|
||||
bb_width_ratio = ((bb_upper - bb_lower) / bb_middle * 100).replace([np.inf, -np.inf], 0)
|
||||
```
|
||||
|
||||
**修改后**:
|
||||
```python
|
||||
bb_width_ratio = pd.Series((bb_upper - bb_lower) / bb_middle * 100, index=dataframe.index)
|
||||
bb_width_ratio = bb_width_ratio.replace([np.inf, -np.inf], 0)
|
||||
```
|
||||
|
||||
### 2. 次修复:第378-379行
|
||||
**问题**: `np.select` 返回 numpy 数组,但使用了 pandas 方法
|
||||
|
||||
**修改前**:
|
||||
```python
|
||||
logger.info(f"[{pair}] 📈 分类目标统计: {dict(pd.Series(optimal_length_class).value_counts())}")
|
||||
logger.info(f"[{pair}] 🎯 最新分类值: {optimal_length_class[-5:]}")
|
||||
```
|
||||
|
||||
**修改后**:
|
||||
```python
|
||||
optimal_length_series = pd.Series(optimal_length_class)
|
||||
logger.info(f"[{pair}] 📈 分类目标统计: {dict(optimal_length_series.value_counts())}")
|
||||
logger.info(f"[{pair}] 🎯 最新分类值: {optimal_length_series.iloc[-5:]}")
|
||||
```
|
||||
|
||||
## 修复验证
|
||||
- ✅ 将 numpy 数组转换为 pandas Series 以使用 pandas 方法
|
||||
- ✅ 保持数据索引一致性
|
||||
- ✅ 修复了所有潜在的 numpy 数组方法调用问题
|
||||
|
||||
## 下一步
|
||||
现在可以重新启动 FreqAI 训练,这次应该能够正确处理数据类型转换。
|
||||
Loading…
x
Reference in New Issue
Block a user