在没有 Pandas C# 的情况下将一分钟的刻度数据转换为五分钟的 OHLC

gam*_*der 5 c# resampling lmax

我从数据馈送 (lmax) 中获取一次分钟数据 (OHLC),我想将其重新采样为五分钟数据,然后再将其重新采样为十分钟、十五分钟和三十分钟。

我正在使用以下逻辑:

开盘=每 5 根蜡烛的第一个值(第一根蜡烛打开)

高 = 5 根蜡烛的最高值

低 = 5 根蜡烛的最低值

Close=最后一根蜡烛的收盘价(第 5 根蜡烛)

这是重新采样数据的正确方法吗?我觉得这是合乎逻辑的,但出于某种原因,他们网站上的数据源和我的代码之间存在明显的差异。我觉得是这样,因为我重新采样错了;如果我使用 Python,我可以参考 Pandas,但不能使用 C#(据我所知)。

这是重新采样数据的函数:

private static List<List<double>> normalize_candles(List<List<double>> indexed_data, int n)
        {
            double open = 0;
            double high = 0;
            double low = 5;
            double close = 0;
            int trunc = 0;
            if (indexed_data.Count() % n != 0)
            {
                trunc = indexed_data.Count() % n;
                for (int i = 0; i < trunc; i++)
                {
                    indexed_data.RemoveAt(indexed_data.Count() - 1);
                }
            }
            {

            }
            List<List<double>> normal_candle_data = new List<List<double>>();
            for (int i = 0; i < indexed_data.Count() / n; i++)
            {
                high = 0;
                low = 100;
                open = indexed_data[i * n][0];
                close = indexed_data[(i * n) + (n - 1)][3];
                for (int j = 0; j < n; j++)
                {
                    if (high < indexed_data[(i * n) + j][1])
                    {
                        high = indexed_data[(i * n) + j][1];
                    }
                    if (low > indexed_data[(i * n) + j][2])
                    {
                        low = indexed_data[(i * n) + j][2];
                    }

                }
                normal_candle_data.Add(new List<double>());
                normal_candle_data[i].Add(open);
                normal_candle_data[i].Add(high);
                normal_candle_data[i].Add(low);
                normal_candle_data[i].Add(close);

            }
            Console.WriteLine("\n\n");
            foreach (var obj in normal_candle_data)
            {

                Console.WriteLine(obj[0] + "," + obj[1] + "," + obj[2] + "," + obj[3]);

            }
            Console.WriteLine("size of orignal data is : " + indexed_data.Count() + "\nSize of normalized data is : " + normal_candle_data.Count());
            return normal_candle_data;



        }
Run Code Online (Sandbox Code Playgroud)