예제 #1
0
        /// <summary>
        /// Plots the correlation value of the pair.
        /// </summary>
        /// <returns></returns>
        public PairsCorrelation PairsCorrelation(Data.IDataSeries input, int correlPeriod, string firstInstrument, string secondInstrument)
        {
            if (cachePairsCorrelation != null)
            {
                for (int idx = 0; idx < cachePairsCorrelation.Length; idx++)
                {
                    if (cachePairsCorrelation[idx].CorrelPeriod == correlPeriod && cachePairsCorrelation[idx].FirstInstrument == firstInstrument && cachePairsCorrelation[idx].SecondInstrument == secondInstrument && cachePairsCorrelation[idx].EqualsInput(input))
                    {
                        return(cachePairsCorrelation[idx]);
                    }
                }
            }

            lock (checkPairsCorrelation)
            {
                checkPairsCorrelation.CorrelPeriod = correlPeriod;
                correlPeriod = checkPairsCorrelation.CorrelPeriod;
                checkPairsCorrelation.FirstInstrument = firstInstrument;
                firstInstrument = checkPairsCorrelation.FirstInstrument;
                checkPairsCorrelation.SecondInstrument = secondInstrument;
                secondInstrument = checkPairsCorrelation.SecondInstrument;

                if (cachePairsCorrelation != null)
                {
                    for (int idx = 0; idx < cachePairsCorrelation.Length; idx++)
                    {
                        if (cachePairsCorrelation[idx].CorrelPeriod == correlPeriod && cachePairsCorrelation[idx].FirstInstrument == firstInstrument && cachePairsCorrelation[idx].SecondInstrument == secondInstrument && cachePairsCorrelation[idx].EqualsInput(input))
                        {
                            return(cachePairsCorrelation[idx]);
                        }
                    }
                }

                PairsCorrelation indicator = new PairsCorrelation();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input            = input;
                indicator.CorrelPeriod     = correlPeriod;
                indicator.FirstInstrument  = firstInstrument;
                indicator.SecondInstrument = secondInstrument;
                Indicators.Add(indicator);
                indicator.SetUp();

                PairsCorrelation[] tmp = new PairsCorrelation[cachePairsCorrelation == null ? 1 : cachePairsCorrelation.Length + 1];
                if (cachePairsCorrelation != null)
                {
                    cachePairsCorrelation.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1]   = indicator;
                cachePairsCorrelation = tmp;
                return(indicator);
            }
        }
예제 #2
0
        /// <summary>
        /// Plots the correlation value of the pair.
        /// </summary>
        /// <returns></returns>
        public PairsCorrelation PairsCorrelation(Data.IDataSeries input, int correlPeriod, string firstInstrument, string secondInstrument)
        {
            if (cachePairsCorrelation != null)
                for (int idx = 0; idx < cachePairsCorrelation.Length; idx++)
                    if (cachePairsCorrelation[idx].CorrelPeriod == correlPeriod && cachePairsCorrelation[idx].FirstInstrument == firstInstrument && cachePairsCorrelation[idx].SecondInstrument == secondInstrument && cachePairsCorrelation[idx].EqualsInput(input))
                        return cachePairsCorrelation[idx];

            lock (checkPairsCorrelation)
            {
                checkPairsCorrelation.CorrelPeriod = correlPeriod;
                correlPeriod = checkPairsCorrelation.CorrelPeriod;
                checkPairsCorrelation.FirstInstrument = firstInstrument;
                firstInstrument = checkPairsCorrelation.FirstInstrument;
                checkPairsCorrelation.SecondInstrument = secondInstrument;
                secondInstrument = checkPairsCorrelation.SecondInstrument;

                if (cachePairsCorrelation != null)
                    for (int idx = 0; idx < cachePairsCorrelation.Length; idx++)
                        if (cachePairsCorrelation[idx].CorrelPeriod == correlPeriod && cachePairsCorrelation[idx].FirstInstrument == firstInstrument && cachePairsCorrelation[idx].SecondInstrument == secondInstrument && cachePairsCorrelation[idx].EqualsInput(input))
                            return cachePairsCorrelation[idx];

                PairsCorrelation indicator = new PairsCorrelation();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.CorrelPeriod = correlPeriod;
                indicator.FirstInstrument = firstInstrument;
                indicator.SecondInstrument = secondInstrument;
                Indicators.Add(indicator);
                indicator.SetUp();

                PairsCorrelation[] tmp = new PairsCorrelation[cachePairsCorrelation == null ? 1 : cachePairsCorrelation.Length + 1];
                if (cachePairsCorrelation != null)
                    cachePairsCorrelation.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cachePairsCorrelation = tmp;
                return indicator;
            }
        }