示例#1
0
        private CorridorStatistics ScanCorridorByFft(IList <Rate> ratesForCorridor, Func <Rate, double> priceHigh, Func <Rate, double> priceLow)
        {
            var ratesReversed = ratesForCorridor.ReverseIfNot().ToArray();
            var FftReversed   = false;

            FftMax = ratesReversed.Select(_priceAvg).FftFrequency(FftReversed).ToInt();

            var        startMax         = CorridorStopDate.IfMin(DateTime.MaxValue);
            var        startMin         = CorridorStartDate.GetValueOrDefault(ratesReversed[CorridorDistanceRatio.ToInt() - 1].StartDate);
            Lazy <int> lenghForwardOnly = new Lazy <int>(() => {
                var date = CorridorStats.Rates.LastOrDefault()?.StartDate;
                return(ratesReversed.TakeWhile(r => r.StartDate >= date).Count());
            });
            var lengthMax = !IsCorridorForwardOnly || CorridorStats.StartDate.IsMin() ? int.MaxValue : lenghForwardOnly.Value;

            WaveShort.Rates = null;
            WaveShort.Rates = startMax.IsMax() && !CorridorStartDate.HasValue
        ? ratesReversed.Take(FftMax.Min(lengthMax)).ToArray()
        : ratesReversed.SkipWhile(r => r.StartDate > startMax).TakeWhile(r => r.StartDate >= startMin).ToArray();
            var corridor = WaveShort.Rates.ScanCorridorWithAngle(CorridorGetHighPrice(), CorridorGetLowPrice(), TimeSpan.Zero, PointSize, CorridorCalcMethod);

            SetVoltage(ratesReversed[0], WaveShort.Rates.Select(_priceAvg).FftFrequency(FftReversed) / (double)WaveShort.Rates.Count);
            var    volts = RatesArray.Select(r => GetVoltage(r)).SkipWhile(v => v.IsNaN()).ToArray();
            double voltsAvg;
            var    voltsStdev = volts.StDev(out voltsAvg);

            GetVoltageAverage = () => new[] { voltsAvg };
            GetVoltageHigh    = () => new[] { voltsAvg + voltsStdev };
            return(corridor);
        }
        private CorridorStatistics ScanCorridorLazy(IList <Rate> ratesReversed, Lazy <int> lazyCount, Func <CorridorStatistics> showVolts = null, Action postProcess = null)
        {
            Lazy <int> lenghForwardOnly = new Lazy <int>(() => {
                if (ratesReversed.Count < RatesArray.Count)
                {
                    return(ratesReversed.Count);
                }
                var date = CorridorStats.Rates.LastOrDefault()?.StartDate;
                return(ratesReversed.TakeWhile(r => r.StartDate >= date).Count());
            });
            var lengthMax = new Lazy <int>(() => !IsCorridorForwardOnly || CorridorStats.StartDate.IsMin() ? int.MaxValue : lenghForwardOnly.Value);

            var startMax = new Lazy <DateTime>(() => CorridorStopDate.IfMin(DateTime.MaxValue));
            var startMin = CorridorStartDate.GetValueOrDefault(CorridorStats.StartDate);
            var rates    = !CorridorStartDate.HasValue
        ? !CorridorStopDate.IsMin()
        ? ratesReversed
                           .SkipWhile(r => lazyCount.Value > 0 && r.StartDate > startMax.Value)
                           .TakeWhile(r => r.StartDate > ratesReversed[lazyCount.Value].StartDate).ToArray()
        : ratesReversed.SkipWhile(r => lazyCount.Value > 0 && r.StartDate > startMax.Value).Take(lengthMax.Value.Min(lazyCount.Value)).ToArray()
        : ratesReversed.SkipWhile(r => r.StartDate > startMax.Value).TakeWhile(r => r.StartDate >= startMin).ToArray();

            if (IsCorridorForwardOnly && _isCorridorStopDateManual && rates.Last().StartDate < CorridorStats.StartDate)
            {
                WaveShort.ResetRates(CorridorStats.Rates);
            }
            else
            {
                WaveShort.ResetRates(rates);
            }
            if (CorridorStartDate.HasValue)
            {
                _corridorsTask.Run(() => {
                    CorridorLengthGreen = ratesReversed.TakeWhile(r => r.StartDate >= _corridorStartDate1).Count();
                    CorridorLengthBlue  = ratesReversed.TakeWhile(r => r.StartDate >= _corridorStartDate2).Count();
                    throw new Exception("Obsolete code entered");
                });
            }
            postProcess?.Invoke();
            return((showVolts ?? GetShowVoltageFunction())());
        }