Python 生成boll 指数代码
时间: 2023-03-25 20:01:28 浏览: 155
文华财经指标公式源码 BOLL指标公式公式源码.doc
可以使用以下代码生成布林带指数:
```python
import pandas as pd
import numpy as np
def bollinger_bands(close_prices, window_size, num_std):
rolling_mean = close_prices.rolling(window=window_size).mean()
rolling_std = close_prices.rolling(window=window_size).std()
upper_band = rolling_mean + (rolling_std * num_std)
lower_band = rolling_mean - (rolling_std * num_std)
return rolling_mean, upper_band, lower_band
# 示例
close_prices = pd.Series(np.random.randn(100))
window_size = 20
num_std = 2
rolling_mean, upper_band, lower_band = bollinger_bands(close_prices, window_size, num_std)
```
阅读全文