コード例 #1
0
ファイル: MiscCursorsTests.cs プロジェクト: lulzzz/Spreads
        public void CouldCalculateMovingStDevIncomlete()
        {
            var sm = new SortedMap <DateTime, double>();

            var count = 1000000;

            for (int i = 0; i < count; i++)
            {
                sm.Add(DateTime.UtcNow.Date.AddSeconds(i), i);
            }

            // slow implementation
            var sw = new Stopwatch();

            sw.Start();
            var ma = sm.StDev(20, true); //.ToSortedMap();
            var c  = 1;

            foreach (var m in ma)
            {
                if (c < 30)
                {
                    Console.WriteLine(m.Value);
                }
                else
                // TODO on c = 9490618 we have a different value: 5.91740018927231
                //   Excel value       5.91607978309962

                if (Math.Abs(m.Value - 5.9160797830996161) > 0.0000001)
                {
                    Console.WriteLine(m.Value);
                    Console.WriteLine($"Error c: {c}");
                    throw new ApplicationException("Invalid value");
                }
                c++;
            }
            sw.Stop();
            Console.WriteLine($"Final c: {c}");
            Console.WriteLine("SMA, elapsed: {0}, ops: {1}", sw.ElapsedMilliseconds, (int)((double)count / (sw.ElapsedMilliseconds / 1000.0)));
            //
        }
コード例 #2
0
ファイル: GenerationTests.cs プロジェクト: mindis/Spreads
        public void CouldGenerateRandomWalk()
        {
            var sw = new Stopwatch();

            sw.Restart();
            var acc = new SortedMap <int, double>();

            SortedMap <DateTime, double> sm = null;

            for (int i = 0; i < 10000; i++)
            {
                sm = RandomWalk.Generate(DateTime.Today.AddYears(-1), DateTime.Today, TimeSpan.FromDays(1), 0.5, 3.65, 365.0);
                acc.Add(i, sm.Last.Value);
            }
            sw.Stop();
            Console.WriteLine($"Elapsed: {sw.ElapsedMilliseconds}");

            // NB internalsvisibleto make it so easy to use values instead of Values
            // hopefully not an issue outside tests
            Console.WriteLine($"Average: {acc.Values.Average()}");
            Console.WriteLine($"StDev: {acc.StDev(int.MaxValue, true).Last.Value}");
            Console.WriteLine("Generated number of values: {0}", sm.Count);
            //gen = null;
        }
コード例 #3
0
ファイル: MiscCursorsTests.cs プロジェクト: b-e-n-j/Spreads
        public void CouldCalculateMovingStDevIncomlete() {
            var sm = new SortedMap<DateTime, double>();

            var count = 1000000;

            for (int i = 0; i < count; i++) {
                sm.Add(DateTime.UtcNow.Date.AddSeconds(i), i);
            }

            // slow implementation
            var sw = new Stopwatch();
            sw.Start();
            var ma = sm.StDev(20, true); //.ToSortedMap();
            var c = 1;
            foreach (var m in ma) {
                if (c < 30) {
                    Console.WriteLine(m.Value);
                } else
                // TODO on c = 9490618 we have a different value: 5.91740018927231
                //   Excel value       5.91607978309962

                if (Math.Abs(m.Value - 5.9160797830996161) > 0.0000001) {
                    Console.WriteLine(m.Value);
                    Console.WriteLine($"Error c: {c}");
                    throw new ApplicationException("Invalid value");

                }
                c++;
            }
            sw.Stop();
            Console.WriteLine($"Final c: {c}");
            Console.WriteLine("SMA, elapsed: {0}, ops: {1}", sw.ElapsedMilliseconds, (int)((double)count / (sw.ElapsedMilliseconds / 1000.0)));
            // 
        }