用.NET语言计算股票技术指标BOLL的代码
时间: 2023-05-14 22:06:15 浏览: 230
以下是用.NET语言计算股票技术指标BOLL的代码:
```csharp
public static void CalculateBoll(double[] close, int n, double k, out double[] mid, out double[] upper, out double[] lower)
{
mid = new double[close.Length];
upper = new double[close.Length];
lower = new double[close.Length];
double[] ma = new double[close.Length];
double[] md = new double[close.Length];
for (int i = 0; i < close.Length; i++)
{
double sum = 0;
for (int j = i - n + 1; j <= i; j++)
{
if (j < 0)
{
sum += close[0];
}
else
{
sum += close[j];
}
}
ma[i] = sum / n;
double sum2 = 0;
for (int j = i - n + 1; j <= i; j++)
{
if (j < 0)
{
sum2 += Math.Pow(close[0] - ma[i], 2);
}
else
{
sum2 += Math.Pow(close[j] - ma[i], 2);
}
}
md[i] = Math.Sqrt(sum2 / n);
mid[i] = ma[i];
upper[i] = ma[i] + k * md[i];
lower[i] = ma[i] - k * md[i];
}
}
```
其中,`close`是股票收盘价数组,`n`是计算周期,`k`是标准差倍数,`mid`、`upper`、`lower`分别是计算出的中轨、上轨、下轨数组。
阅读全文