Beispiel #1
0
        public virtual void AnalyseResult(IInstrument instrument, DateTime startTime, DateTime endTime, MarketDataGrade?grade)
        {
            ReferenceValueList.Clear();
            IsAnalyse = true;
            var g = MarketDataGrade.FiveMinutes;

            if (grade != null)
            {
                g = grade.Value;
            }
            AnalyseDataSource.PrepareCache(instrument, startTime, endTime, g);
            for (var time = startTime; time <= endTime; time = MarketData.GetNextTime(time, grade.Value))
            {
                ISignal d = null;
                try
                {
                    d = Calculate(instrument, startTime, time, grade);
                }
                catch
                {
                }
                if (d != null)
                {
                    AddReference(Name, new TimeValueObject()
                    {
                        TargetName = instrument.Ticker, Time = d.Time, Value = d.Value, Name = instrument.Name
                    });
                }
            }
            IsAnalyse = false;
        }
Beispiel #2
0
 public List <IMarketData> GetMarketData(IInstrument instrument, DateTime start, DateTime end, MarketDataGrade grade)
 {
     if (AnalyseDataSource != null)
     {
         return(AnalyseDataSource.GetDataList(instrument, start, end, grade));
     }
     return(null);
 }
Beispiel #3
0
        protected override ISignal Calculate(IInstrument instrument, DateTime startTime, DateTime endTime, MarketDataGrade?grade)
        {
            isSignalBiggerMeansBetter = true;
            if (grade == null)
            {
                grade = Grade;
            }
            try
            {
                var dl  = AnalyseDataSource.GetDataList(instrument, startTime, endTime, grade.Value);
                var RSI = new double[dl.Count];

                int bindex;
                int element;

                Core.Rsi(0, dl.Count - 1, dl.Select(p => p.Close).ToArray(),
                         Period, out bindex, out element, RSI);
                var valueList = RSI.ToList();
                CommonProc.TrimDoubleList(valueList);
                if (IsAnalyse)
                {
                    //if (!AnalyseValueList.ContainsKey("RSI"))
                    //{
                    //    AnalyseValueList.Add("RSI", new List<TimeValueObject>());
                    //}


                    if (valueList.Count > 0)
                    {
                        //AddSignal(instrument, dl.Max(v => v.Time), valueList.LastOrDefault(), dl.LastOrDefault().Close, "RSI", SignalType.Analyse);
                        var obj = new TimeValueObject()
                        {
                            Name = Name, Value = valueList.LastOrDefault()
                        };
                        obj.Time = dl.Max(v => v.Time);
                        AddReference("RSI", obj);
                        //AnalyseValueList["RSI"].Add(obj);
                        //var dif = dl.Count - valueList.Count;
                        //for (int i = valueList.Count - 1; i >= 0; i--)
                        //{

                        //    var o = new TimeValueObject() { Name = Name, Value = valueList[i] };
                        //    o.Time = dl[dif + i].Time;
                        //    AddReference("RSI", o);
                        //}
                    }
                }
                //var o = new TimeValueObject() { Name = Name, Time = endTime, Value = null };
                //o.Time = dl.Max(v => v.Time);
                //o.Value = RSI.ToArray().LastOrDefault();
                return(CreateSignal(instrument, dl.Max(v => v.Time), RSI.ToArray().LastOrDefault(), dl.LastOrDefault().Close));
            }
            catch (Exception e)
            {
                LogSupport.Error(e);
            }
            return(null);
        }
Beispiel #4
0
        protected override ISignal Calculate(IInstrument instrument, DateTime startTime, DateTime endTime, MarketDataGrade?grade)
        {
            if (IsHigh)
            {
                isSignalBiggerMeansBetter = true;
            }
            else
            {
                isSignalBiggerMeansBetter = false;
            }
            try
            {
                var    dl    = AnalyseDataSource.GetDataList(instrument, startTime, endTime, grade.Value);
                var    v     = GetPreviousEndValue(dl);
                double value = 0;
                if (v > 0)
                {
                    double price = 0;
                    if (StandardGrade > dl.LastOrDefault().Grade)
                    {
                        if (IsHigh)
                        {
                            price = dl.LastOrDefault().High;
                        }
                        else
                        {
                            price = dl.LastOrDefault().Low;
                        }
                    }
                    else
                    {
                        price = dl.LastOrDefault().Close;
                    }
                    double d = (price - v) / v;
                    if (IsHigh && d > Math.Abs(ThresholdPercent))
                    {
                        value = d - ThresholdPercent;
                    }
                    if (!IsHigh && d < (-1 * Math.Abs(ThresholdPercent)))
                    {
                        value = d + Math.Abs(ThresholdPercent);
                    }

                    if (Math.Abs(value) > CommonProc.EPSILON)
                    {
                        return(CreateSignal(instrument, dl.LastOrDefault().Time, value, price));
                    }
                }
                return(null);
            }
            catch
            {
                return(null);
            }
        }
        ISignal IsHigher(IInstrument instrument, DateTime start, DateTime end, MarketDataGrade?grade)
        {
            if (grade == null)
            {
                grade = Grade;
            }
            var ml = AnalyseDataSource.GetDataList(instrument, start, end, grade.Value);

            if (ml.Count <= PredicatePeriod + RecentPeriod)
            {
                return(null);
            }

            var recentMax    = 0d;
            var predicateMax = 0d;

            for (int i = 0; i < PredicatePeriod + RecentPeriod; i++)
            {
                var data = ml[ml.Count - 1 - i];
                if (i < RecentPeriod)
                {
                    recentMax = Math.Max(recentMax, data.Close);
                }
                else
                {
                    predicateMax = Math.Max(predicateMax, data.High);
                }
            }

            if (recentMax >= predicateMax * (Threshold + 1))
            {
                var o = new Signal()
                {
                    Name = Name, Time = end, Value = 0, IsPositive = isSignalBiggerMeansBetter, Price = recentMax, Ticker = instrument.Ticker
                };
                o.Time  = ml.Max(v => v.Time);
                o.Value = (recentMax - predicateMax) / predicateMax;
                return(o);
            }
            return(null);
        }
Beispiel #6
0
        protected override ISignal Calculate(IInstrument instrument, DateTime startTime, DateTime endTime, MarketDataGrade?grade)
        {
            isSignalBiggerMeansBetter = true;
            if (grade == null)
            {
                grade = Grade;
            }
            try
            {
                var dl    = AnalyseDataSource.GetDataList(instrument, startTime, endTime, grade.Value);
                var slowK = new double[dl.Count];
                var slowD = new double[dl.Count];

                int bindex;
                int element;

                Core.Stoch(0, dl.Count - 1, dl.Select(p => p.High).ToArray(), dl.Select(p => p.Low).ToArray(), dl.Select(p => p.Close).ToArray(),
                           FastKPeriod, SlowKPeriod, SlowKType, SlowDPeriod, SlowDType, out bindex, out element, slowK, slowD);
                var skl = slowK.ToList <double>();
                var sdl = slowD.ToList <double>();
                CommonProc.TrimDoubleList(skl);
                CommonProc.TrimDoubleList(sdl);
                if (IsAnalyse)
                {
                    //if (!AnalyseValueList.ContainsKey("K"))
                    //{
                    //    AnalyseValueList.Add("K", new List<TimeValueObject>());
                    //}
                    //if (!AnalyseValueList.ContainsKey("D"))
                    //{
                    //    AnalyseValueList.Add("D", new List<TimeValueObject>());
                    //}
                    if (skl.Count > 0)
                    {
                        //var dif = dl.Count - skl.Count;
                        //for (int i = skl.Count - 1; i >= 0; i--)
                        //{

                        //    var o = new TimeValueObject() { Name = Name, Value = skl[i] };
                        //    o.Time = dl[dif + i].Time;
                        //    AddReference("K", o);
                        //}
                        var o = new TimeValueObject()
                        {
                            Name = Name, Value = skl.LastOrDefault()
                        };
                        o.Time = dl.Max(v => v.Time);
                        AddReference("K", o);
                        //AddSignal(instrument, dl.Max(v => v.Time), skl.LastOrDefault(), dl.LastOrDefault().Close, "K", SignalType.Analyse);
                        //AnalyseValueList["K"].Add(o);
                    }
                    if (sdl.Count > 0)
                    {
                        //var dif = dl.Count - sdl.Count;
                        //for (int i = skl.Count - 1; i >= 0; i--)
                        //{

                        //    var o = new TimeValueObject() { Name = Name, Value = sdl[i] };
                        //    o.Time = dl[dif + i].Time;
                        //    AddReference("D", o);
                        //}
                        var o = new TimeValueObject()
                        {
                            Name = Name, Value = sdl.LastOrDefault()
                        };
                        o.Time = dl.Max(v => v.Time);
                        AddReference("D", o);
                        //AnalyseValueList["D"].Add(o);
                        //AddSignal(instrument, dl.Max(v => v.Time), sdl.LastOrDefault(), dl.LastOrDefault().Close, "D", SignalType.Analyse);
                    }
                }
                if (skl[skl.Count - 2] < skl[skl.Count - 1] && sdl[sdl.Count - 2] < sdl[sdl.Count - 1])//current K,D increase
                {
                    return(CreateSignal(instrument, dl.Max(v => v.Time), ((skl[skl.Count - 1] - skl[skl.Count - 2]) + (sdl[sdl.Count - 1] - sdl[sdl.Count - 2])) / 2d, dl.LastOrDefault().Close));
                    //var o = new TimeValueObject() { Name = Name, Time = endTime, Value = null };
                    //o.Time = dl.Max(v => v.Time);
                    //o.Value= ((skl[skl.Count - 1] - skl[skl.Count - 2]) + (sdl[sdl.Count - 1] - sdl[sdl.Count - 2])) / 2d;
                    //return o;
                }
            }
            catch (Exception e)
            {
                LogSupport.Error(e);
            }
            return(null);
        }