Beispiel #1
0
        public VarianceRatio(Bars bars, DataSeries ds, int lookback, int period, string description)
            : base(bars, description)
        {
            LNRet             lnr    = LNRet.Series(bars, ds, lookback);
            LNRet             lnr1   = LNRet.Series(bars, ds, 1);
            StdDevCalculation sample = StdDevCalculation.Sample;

            for (int bar = Math.Max(lookback, period); bar < bars.Count; bar++)
            {
                base[bar] = StdDev.Series(lnr, period, sample)[bar] / (StdDev.Series(lnr1, period, sample)[bar] * Math.Sqrt(lookback));
            }
        }
Beispiel #2
0
        public static LNRet Series(Bars bars, DataSeries ds, int period)
        {
            string description = string.Concat(new object[] { "LNRet(", ds.Description, ",", period.ToString(), ")" });

            if (bars.Cache.ContainsKey(description))
            {
                return((LNRet)bars.Cache[description]);
            }

            LNRet _LNRet = new LNRet(bars, ds, period, description);

            bars.Cache[description] = _LNRet;
            return(_LNRet);
        }
Beispiel #3
0
        public CTI(Bars bars, DataSeries ds, int period, bool positiveOnly, string description)
            : base(ds, description)
        {
            Helper.CompatibilityCheck();

            base.FirstValidValue = period;

            if (FirstValidValue > ds.Count || FirstValidValue < 0)
            {
                FirstValidValue = ds.Count;
            }
            if (ds.Count < period)
            {
                return;
            }

            #region Parallelization (removed in 2018.08 for crash/hang issues)

            //var rangePartitioner = Partitioner.Create(FirstValidValue, ds.Count);
            //var rangePartitioner = Partitioner.Create(0, ds.Count);

            //Parallel.ForEach(rangePartitioner, (range, loopState) =>
            //{
            //    for (int i = range.Item1; i < range.Item2; i++)
            //    {
            //        base[i] = LNRet.Series(bars, ds, period)[i] / (StdDev.Series(LNRet.Series(bars, ds, 1), period, StdDevCalculation.Sample)[i] * Math.Sqrt(period));
            //        if (positiveOnly)
            //            base[i] = Math.Abs(base[i]);
            //    }
            //});

            #endregion

            for (int i = 0; i < ds.Count; i++)
            {
                base[i] = LNRet.Series(bars, ds, period)[i] / (StdDev.Series(LNRet.Series(bars, ds, 1), period, StdDevCalculation.Sample)[i] * Math.Sqrt(period));
                if (positiveOnly)
                {
                    base[i] = Math.Abs(base[i]);
                }
            }
        }