예제 #1
0
 public CCMRow(CMRow cmRow)
 {
     this.startTime          = cmRow.startTime;
     this.endTime            = cmRow.endTime;
     this.deltaPt            = cmRow.deltaPt;
     this.startPt            = cmRow.startPt;
     this.endPt              = cmRow.endPt;
     this.isMomentumDetected = cmRow.isMomentumDetected;
 }
예제 #2
0
        public static List <CMRow> cloneRows(List <CMRow> rows)
        {
            List <CMRow> cRows = new List <CMRow>();

            foreach (CMRow row in rows)
            {
                CMRow cRow = row.Clone() as CMRow;
                cRows.Add(cRow);
            }
            return(cRows);
        }
예제 #3
0
        public static Boolean isMomentumDetected(List <CMRow> rows, int period, double averageThreshold, double pctRemove)
        {
            cmResult result     = calculateMaxAndAvg(rows, period, pctRemove);
            CMRow    currentRow = rows[rows.Count - 1];

            if (currentRow.deltaPt >= result.maxThreshold && currentRow.deltaPt >= result.averageThreshold * averageThreshold)
            {
                return(true);
            }
            return(false);

            /*
             * List<CMRow> _clnRows =  new List<CMRow> ();
             * _clnRows = cloneRows(rows);
             * CMRow currentRow = rows[rows.Count - 1];
             * _clnRows.Reverse();
             * List<CMRow> lastNRows = firstNRow(_clnRows, period);
             * lastNRows.Sort(delegate(CMRow x, CMRow y)
             * {
             *  if (x.deltaPt > y.deltaPt)
             *      return 1;
             *  if (x.deltaPt < y.deltaPt)
             *      return -1;
             *  if (x.deltaPt == y.deltaPt)
             *      return 0;
             *  return 0;
             * });
             *
             * int numExcluded = Convert.ToInt32(Math.Floor(period * 0.1));
             * int numTooHigh = numExcluded * 2;
             * int indexTooHighInclude = period -numTooHigh-1;
             * int startIncludeIndex = 0 + numExcluded ;
             * int endIncludeIndex = period - numExcluded -1;
             *
             * double average = 0;
             * double valueTooHigh = 0;
             * for (int i = 0; i < lastNRows.Count; i++)
             * {
             *  if (i >= startIncludeIndex && i <= endIncludeIndex) {
             *      average += lastNRows[i].deltaPt;
             *  }
             *
             *  if (i == indexTooHighInclude)
             *      valueTooHigh = lastNRows[i].deltaPt;
             * }
             * average = average / (lastNRows.Count - numExcluded * 2);
             * if (currentRow.deltaPt >= valueTooHigh && currentRow.deltaPt >= average * 3 )
             *  return true;
             * return false;
             */
        }
예제 #4
0
        public static List <CMRow> calculate(List <CMRow> rows, Series <DateTime, MarketDataElement> series, int period, DateTime startTime)
        {
            Series <DateTime, MarketDataElement> lastNData = MarketDateElementHelper.getLastNMarketData(series, period);
            MarketDataElement firstData = MarketDateElementHelper.getFirstAvaMarketData(lastNData, startTime);
            MarketDataElement lastData  = series.GetAt(series.KeyCount - 1);
            double            open      = firstData.open;
            double            close     = lastData.close;
            double            delta     = Math.Abs(close - open);

            CMRow row = new CMRow();

            row.startTime = firstData.time;
            row.startPt   = firstData.open;
            row.endTime   = lastData.time;
            row.endPt     = lastData.close;
            row.deltaPt   = delta;
            rows.Add(row);
            return(rows);
        }
예제 #5
0
        public static CMRow resolveConflictRow(CMRow row1, CMRow row2)
        {
            Boolean isConflict = false;

            if (row1.startTime <= row2.startTime && row1.endTime >= row2.startTime)
            {
                isConflict = true;
            }

            if (isConflict)
            {
                CMRow newRow = (CMRow)row2.Clone();
                newRow.startTime = row1.endTime.AddMinutes(1);
                return(newRow);
            }
            else
            {
                return(null);
            }
            return(null);
        }
예제 #6
0
        public static CMRow mergeRow(CMRow row1, CMRow row2)
        {
            double direction1 = row1.endPt - row1.startPt;
            double direction2 = row2.endPt - row2.startPt;

            if (direction1 * direction2 > 0 && row1.isMomentumDetected && row2.isMomentumDetected)
            {
                CMRow newRow = new CMRow();
                newRow.startPt            = row1.startPt;
                newRow.startTime          = row1.startTime;
                newRow.endPt              = row2.endPt;
                newRow.endTime            = row2.endTime;
                newRow.deltaPt            = Math.Abs(newRow.endPt - newRow.startPt);
                newRow.isMomentumDetected = true;
                return(newRow);
            }
            else
            {
                return(null);
            }
            return(null);
        }
예제 #7
0
        public static cmResult calculateMaxAndAvg(List <CMRow> rows, int period, double pctRemove)
        {
            List <CMRow> _clnRows = new List <CMRow>();

            _clnRows = cloneRows(rows);
            CMRow currentRow = rows[rows.Count - 1];

            _clnRows.Reverse();
            List <CMRow> lastNRows = firstNRow(_clnRows, period);

            lastNRows.Sort(delegate(CMRow x, CMRow y)
            {
                if (x.deltaPt > y.deltaPt)
                {
                    return(1);
                }
                if (x.deltaPt < y.deltaPt)
                {
                    return(-1);
                }
                if (x.deltaPt == y.deltaPt)
                {
                    return(0);
                }
                return(0);
            });

            double halfPctRemove = pctRemove / 2;
            //halfPctRemove = Math.Round(halfPctRemove, 1);
            int numExcluded         = Convert.ToInt32(Math.Floor(period * halfPctRemove));
            int numTooHigh          = numExcluded * 2;
            int indexTooHighInclude = period - numTooHigh - 1;
            int startIncludeIndex   = 0 + numExcluded;
            int endIncludeIndex     = period - numExcluded - 1;

            double average      = 0;
            double valueTooHigh = 0;

            for (int i = 0; i < lastNRows.Count; i++)
            {
                if (i >= startIncludeIndex && i <= endIncludeIndex)
                {
                    average += lastNRows[i].deltaPt;
                }

                if (i == indexTooHighInclude)
                {
                    valueTooHigh = lastNRows[i].deltaPt;
                }
            }

            average = average / (lastNRows.Count - numExcluded * 2);
            cmResult result = new cmResult();

            result.averageThreshold = average;
            result.maxThreshold     = valueTooHigh;
            return(result);
            //if (currentRow.deltaPt >= valueTooHigh && currentRow.deltaPt >= average * 3 )
            //    return true;
            //return false;
        }