Example #1
0
 public override double[] MultipleOutputUpdate(StockAnalysis.Share.Bar data)
 {
     if (_acceptBarInput)
     {
         if (_singleOutput)
         {
             return(new double[1] {
                 _sobiMetric.Update(data)
             });
         }
         else
         {
             return(_mobiMetric.Update(data));
         }
     }
     else
     {
         if (_singleOutput)
         {
             return(new double[1] {
                 _soriMetric.Update(data.ClosePrice)
             });
         }
         else
         {
             return(_moriMetric.Update(data.ClosePrice));
         }
     }
 }
 public override double Update(StockAnalysis.Share.Bar bar)
 {
     return((_cma1.Update(bar) +
             _cma2.Update(bar) +
             _cma3.Update(bar) +
             _cma4.Update(bar)) / 4);
 }
Example #3
0
        public void Update(StockAnalysis.Share.Bar bar)
        {
            double price = BarPriceSelector.Select(bar, _priceSelector);

            _highest.Update(price);
            double newHighest = _highest.Value;

            bool oldBreakout = Breakout;

            Breakout = Math.Abs(newHighest - price) < 1e-6;

            CurrentHighest = newHighest;

            if (Breakout)
            {
                // rebreakout is always breakout
                if (oldBreakout)
                {
                    // continuous breakout is not rebreakout
                    Rebreakout = false;
                    _intervalSinceLastBreakout = 0;
                }
                else
                {
                    // possible a rebreakout.
                    if (_intervalSinceLastBreakout > 0 &&
                        _intervalSinceLastBreakout <= _maxInterval &&
                        _intervalSinceLastBreakout >= _minInterval)
                    {
                        Rebreakout = true;
                        IntervalSinceLastBreakout = _intervalSinceLastBreakout;

                        _intervalSinceLastBreakout = 0;
                    }
                    else
                    {
                        Rebreakout = false;
                        _intervalSinceLastBreakout = 0;
                    }
                }
            }
            else
            {
                // rebreakout is always breakout
                Rebreakout = false;

                if (oldBreakout)
                {
                    _intervalSinceLastBreakout = 1;
                }
                else
                {
                    if (_intervalSinceLastBreakout > 0)
                    {
                        _intervalSinceLastBreakout++;
                    }
                }
            }
        }
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            double truePrice = (bar.HighestPrice + bar.LowestPrice + 2 * bar.ClosePrice) / 4;

            double sumCost   = _msCost.Update(bar.Volume * truePrice);
            double sumVolume = _msVolume.Update(bar.Volume);

            return(sumCost / sumVolume);
        }
Example #5
0
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            double cost = ((bar.ClosePrice - bar.LowestPrice)
                           - (bar.HighestPrice - bar.ClosePrice))
                          / (bar.HighestPrice - bar.LowestPrice)
                          * bar.Volume;

            return(_sumCost.Update(cost) / _sumVolume.Update(bar.Volume));
        }
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            double highest = _highest.Update(bar.HighestPrice);
            double lowest  = _lowest.Update(bar.LowestPrice);

            double rsv = (bar.ClosePrice - lowest) / (highest - lowest) * 100;

            return(100.0 - rsv);
        }
Example #7
0
 public override double[] Update(StockAnalysis.Share.Bar bar)
 {
     return(new double[FieldCount]
     {
         bar.ClosePrice,
         bar.OpenPrice,
         bar.HighestPrice,
         bar.LowestPrice,
         bar.Volume,
         bar.Amount
     });
 }
Example #8
0
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            double obv = _firstBar
                ? bar.Volume
                : _prevObv + Math.Sign(bar.ClosePrice - _prevClosePrice) * bar.Volume;

            // update status
            _prevClosePrice = bar.ClosePrice;
            _prevObv        = obv;
            _firstBar       = false;

            // return result;
            return(obv);
        }
Example #9
0
        public static double Select(StockAnalysis.Share.Bar bar, int selector)
        {
            switch (selector)
            {
            case 0: return(bar.HighestPrice);

            case 1: return(bar.LowestPrice);

            case 2: return(bar.ClosePrice);

            case 3: return(bar.OpenPrice);

            default:
                throw new ArgumentOutOfRangeException("selector must be in [0..3]");
            }
        }
Example #10
0
        public override double[] MultipleOutputUpdate(StockAnalysis.Share.Bar data)
        {
            double calleeResult;

            if (_callee.FieldNames.Length <= 1)
            {
                calleeResult = _callee.SingleOutputUpdate(data);

                return(_caller.MultipleOutputUpdate(calleeResult));
            }
            else
            {
                throw new InvalidOperationException(
                          "callee has multiple outputs, and caller can't handle it");
            }
        }
Example #11
0
        public override double SingleOutputUpdate(StockAnalysis.Share.Bar data)
        {
            if (!_singleOutput)
            {
                throw new NotSupportedException(
                          string.Format("Metric {0} has multiple output", _metric.GetType().Name));
            }

            if (!_acceptBarInput)
            {
                return(_soriMetric.Update(data.ClosePrice));
            }
            else
            {
                return(_sobiMetric.Update(data));
            }
        }
Example #12
0
        public override double[] Update(StockAnalysis.Share.Bar bar)
        {
            double lowestPrice  = _lowest.Update(bar.LowestPrice);
            double highestPrice = _highest.Update(bar.HighestPrice);

            double rsv = (bar.ClosePrice - lowestPrice) / (highestPrice - lowestPrice) * 100.0;

            double k = rsv;
            double d = ((_kDecay - 1) * _prevD + k) / _kDecay;
            double j = _jCoeff * d - (_jCoeff - 1) * k;

            // update status;
            _prevD = d;

            return(new double[3] {
                k, d, j
            });
        }
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            double truePrice = (bar.HighestPrice + bar.LowestPrice + 2 * bar.ClosePrice) / 4;

            _truePrices.Add(truePrice);

            double maTruePrice = _maTruePrice.Update(truePrice);

            double sum = 0.0;

            for (int i = 0; i < _truePrices.Length; ++i)
            {
                sum += Math.Abs(_truePrices[i] - maTruePrice);
            }

            double d = sum / _truePrices.Length;

            return(d == 0.0 ? 0.0 : (truePrice - maTruePrice) / d / Alpha);
        }
Example #14
0
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            const double SmallValue = 1e-10;

            double pv, nv, zv;

            if (_firstBar)
            {
                pv = nv = SmallValue;
                zv = bar.Volume;
            }
            else
            {
                if (bar.ClosePrice > _prevClosePrice)
                {
                    pv = bar.Volume;
                    nv = zv = 0.0;
                }
                else if (bar.ClosePrice < _prevClosePrice)
                {
                    nv = bar.Volume;
                    pv = zv = 0.0;
                }
                else
                {
                    zv = bar.Volume;
                    pv = nv = 0.0;
                }
            }

            double msPv = _msPv.Update(pv) + SmallValue;
            double msNv = _msNv.Update(nv) + SmallValue;
            double msZv = _msZv.Update(zv) + SmallValue;

            double result = (msPv + msZv / 2.0) / (msNv + msZv / 2.0) * 100.0;

            // update status
            _prevClosePrice = bar.ClosePrice;
            _firstBar       = false;

            // return result;
            return(result);
        }
Example #15
0
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            const double SmallValue = 1e-10;

            double truePrice = (bar.HighestPrice + bar.LowestPrice + bar.ClosePrice) / 3;

            double positiveMoneyFlow;
            double negativeMoneyFlow;

            if (_firstData)
            {
                positiveMoneyFlow = truePrice * bar.Volume;
                negativeMoneyFlow = SmallValue;
            }
            else
            {
                if (truePrice > _prevTruePrice)
                {
                    positiveMoneyFlow = truePrice * bar.Volume;
                    negativeMoneyFlow = 0.0;
                }
                else if (truePrice < _prevTruePrice)
                {
                    positiveMoneyFlow = 0.0;
                    negativeMoneyFlow = truePrice * bar.Volume;
                }
                else
                {
                    positiveMoneyFlow = negativeMoneyFlow = SmallValue;
                }
            }

            double sumPmf = _msPmf.Update(positiveMoneyFlow);
            double sumNmf = _msNmf.Update(negativeMoneyFlow);

            // update status
            _prevTruePrice = truePrice;
            _firstData     = false;

            // return result
            return(100.0 / (1.0 + sumPmf / sumNmf));
        }
Example #16
0
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            double bp = bar.ClosePrice - Math.Min(bar.LowestPrice, _prevClosePrice);
            double tr = Math.Max(bar.HighestPrice, _prevClosePrice) - Math.Min(bar.LowestPrice, _prevClosePrice);

            double[] average = new double[3];

            for (int i = 0; i < 3; ++i)
            {
                average[i] = _msBp[i].Update(bp) / _msTr[i].Update(tr);
            }

            double sumWeight = (_weight[0] + _weight[1] + _weight[2]) / 100.0;

            double result = (_weight[0] * average[0]
                             + _weight[1] * average[1]
                             + _weight[2] * average[2])
                            / sumWeight;

            // update status;
            _prevClosePrice = bar.ClosePrice;

            return(result);
        }
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            double index = (bar.ClosePrice - bar.OpenPrice) * bar.Volume / (bar.HighestPrice - bar.LowestPrice);

            return(_ms.Update(index));
        }
 public void Update(StockAnalysis.Share.Bar bar)
 {
     _expression.MultipleOutputUpdate(bar);
 }
Example #19
0
 public override double[] MultipleOutputUpdate(StockAnalysis.Share.Bar data)
 {
     return(new double[1] {
         Operand.MultipleOutputUpdate(data)[_fieldIndex]
     });
 }
Example #20
0
 public override double SingleOutputUpdate(StockAnalysis.Share.Bar data)
 {
     return(Operand.SingleOutputUpdate(data));
 }