【发布时间】:2019-09-10 15:04:51
【问题描述】:
我想使用以下方法,但作为业余程序员,我无法理解如何填充(格式化?)将用作该方法输入的 SortedList。 我有一个带有 DateTime 的 sql 表和一个始终关联“关闭”字符串的值(参见代码)
看了几个答案,都没有结论
public static void AddBollingerBands(ref SortedList<DateTime, Dictionary<string, double>> data, int period, int factor)
{
double total_average = 0;
double total_squares = 0;
for (int i = 0; i < data.Count(); i++)
{
total_average += data.Values[i]["close"];
total_squares += Math.Pow(data.Values[i]["close"], 2);
if (i >= period - 1)
{
double total_bollinger = 0;
double average = total_average / period;
double stdev = Math.Sqrt((total_squares - Math.Pow(total_average,2)/period) / period);
data.Values[i]["bollinger_average"] = average;
data.Values[i]["bollinger_top"] = average + factor * stdev;
data.Values[i]["bollinger_bottom"] = average - factor * stdev;
.......
......
【问题讨论】:
-
您在尝试执行此操作时遇到了什么问题?
-
字典和 SortedList 似乎都不是布林带数据的正确选择。我会使用按日期排序的类和集合
标签: c# dictionary sortedlist