示例#1
0
        /// <summary>
        /// @"Token\Pair\BID\OFFER\HIGH\LOW\STATUS\NOTATION\DECIMALS\CLOSINGBID", @"\");
        /// </summary>
        /// <param name="data"></param>
        /// <param name="dateTimeFormat"></param>
        /// <returns></returns>
        public Rate ToRateOnConnect(string data, ref TickTime origin)
        {
            if (System.String.IsNullOrEmpty(data) || data.Length < 10)
            {
                return(null);
            }

            //Ignore token, might be corrupted
            string[] properties = Asmodat.Abbreviate.String.ToList(data, "\\");
            if (properties.Length != 10)
            {
                return(null);
            }


            string status   = properties[6];
            string notation = properties[7];

            if (status != "D" && status != "R")
            {
                return(null);
            }

            if (notation != "E" && notation != "A")
            {
                return(null);
            }

            Rate rate = new Rate();

            try
            {
                rate.Pair       = properties[1];
                rate.DECIMALS   = ForexConfiguration.GetDecimals(rate.Pair);
                rate.BID        = Doubles.Parse(properties[2], rate.DECIMALS);
                rate.OFFER      = Doubles.Parse(properties[3], rate.DECIMALS);
                rate.HIGH       = Doubles.Parse(properties[4], rate.DECIMALS);
                rate.LOW        = Doubles.Parse(properties[5], rate.DECIMALS);
                rate.STATUS     = status;
                rate.NOTATION   = notation;
                rate.CLOSINGBID = Doubles.Parse(properties[8], rate.DECIMALS);

                rate.ChartData.TickTime = (origin += 1);


                //backtest
                double pchange = RateInfo.ChangePercentage(rate.BID, rate.OFFER, rate.HIGH, rate.LOW);
                if (pchange < 25)
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                Exceptions.Add(e);
                return(null);
            }

            return(rate);
        }
示例#2
0
        public string Step1BRemoveLySuffixes(string word, int r1)
        {
            foreach (var suffix in new[] { "eedly", "eed" }.Where(word.EndsWith))
            {
                if (SuffixInR1(word, r1, suffix))
                {
                    return(ReplaceSuffix(word, suffix, "ee"));
                }
                return(word);
            }

            foreach (var suffix in new[] { "ed", "edly", "ing", "ingly" }.Where(word.EndsWith))
            {
                var trunc = ReplaceSuffix(word, suffix);//word.Substring(0, word.Length - suffix.Length);
                if (trunc.Any(IsVowel))
                {
                    if (new[] { "at", "bl", "iz" }.Any(trunc.EndsWith))
                    {
                        return(trunc + "e");
                    }
                    if (Doubles.Any(trunc.EndsWith))
                    {
                        return(trunc.Substring(0, trunc.Length - 1));
                    }
                    if (IsShortWord(trunc))
                    {
                        return(trunc + "e");
                    }
                    return(trunc);
                }
                return(word);
            }

            return(word);
        }
示例#3
0
        public bool CrossesUnder(object _price1, int displace1, object _price2, int displace2)
        {
            Doubles price1 = model.Doubles(_price1);
            Doubles price2 = model.Doubles(_price2);

            return(price1[displace1] < price2[displace2] && price1[displace1 + 1] >= price2[displace2 + 1]);
        }
示例#4
0
        public virtual void TestNonexistantFields()
        {
            Directory         dir = NewDirectory();
            RandomIndexWriter iw  = new RandomIndexWriter(Random(), dir, Similarity, TimeZone);
            Document          doc = new Document();

            iw.AddDocument(doc);
            DirectoryReader ir = iw.Reader;

            iw.Dispose();

            AtomicReader ar = GetOnlySegmentReader(ir);

            IFieldCache cache = FieldCache.DEFAULT;

            cache.PurgeAllCaches();
            Assert.AreEqual(0, cache.GetCacheEntries().Length);

#pragma warning disable 612, 618
            Bytes bytes = cache.GetBytes(ar, "bogusbytes", true);
            Assert.AreEqual(0, bytes.Get(0));

            Int16s shorts = cache.GetInt16s(ar, "bogusshorts", true);
            Assert.AreEqual(0, shorts.Get(0));
#pragma warning restore 612, 618

            Int32s ints = cache.GetInt32s(ar, "bogusints", true);
            Assert.AreEqual(0, ints.Get(0));

            Int64s longs = cache.GetInt64s(ar, "boguslongs", true);
            Assert.AreEqual(0, longs.Get(0));

            Singles floats = cache.GetSingles(ar, "bogusfloats", true);
            Assert.AreEqual(0, floats.Get(0), 0.0f);

            Doubles doubles = cache.GetDoubles(ar, "bogusdoubles", true);
            Assert.AreEqual(0, doubles.Get(0), 0.0D);

            BytesRef        scratch  = new BytesRef();
            BinaryDocValues binaries = cache.GetTerms(ar, "bogusterms", true);
            binaries.Get(0, scratch);
            Assert.AreEqual(0, scratch.Length);

            SortedDocValues sorted = cache.GetTermsIndex(ar, "bogustermsindex");
            Assert.AreEqual(-1, sorted.GetOrd(0));
            sorted.Get(0, scratch);
            Assert.AreEqual(0, scratch.Length);

            SortedSetDocValues sortedSet = cache.GetDocTermOrds(ar, "bogusmultivalued");
            sortedSet.SetDocument(0);
            Assert.AreEqual(SortedSetDocValues.NO_MORE_ORDS, sortedSet.NextOrd());

            IBits bits = cache.GetDocsWithField(ar, "bogusbits");
            Assert.IsFalse(bits.Get(0));

            // check that we cached nothing
            Assert.AreEqual(0, cache.GetCacheEntries().Length);
            ir.Dispose();
            dir.Dispose();
        }
示例#5
0
        public static void Process16bitWAV(ref byte[] sample, out double[] fft_result, bool corrections)
        {
            if (sample == null || sample.Length <= 1)
            {
                fft_result = null;
                return;
            }

            int size = (int)(Math.Log(sample.Length) / Math.Log(2));

            byte[] data = sample.Take((int)Math.Pow(2, size)).ToArray();

            fft_result = new double[data.Length / 2];
            for (int i = 0, h = 0; i < data.Length; i += 2)
            {
                fft_result[h] = (double)BitConverter.ToInt16(data, i);
                h++;
            }

            fft_result = AMath.FourierTransform.FFTDb(ref fft_result);

            if (corrections)
            {
                fft_result = Doubles.Replace(fft_result, double.NaN, 0);
                fft_result = Doubles.Replace(fft_result, double.NegativeInfinity, 0);
                fft_result = Doubles.Replace(fft_result, double.PositiveInfinity, 140);
            }
        }
示例#6
0
        public static object IsGreater(object x, object y)
        {
            if (AreTypes.Bool(x, y))
            {
                return(((bool)x).IsGreater((bool)y));
            }
            if (AreTypes.String(x, y))
            {
                return(((string)x).IsGreater((string)y));
            }
            if (AreTypes.DateTime(x, y))
            {
                return(((DateTime)x).IsGreater((DateTime)y));
            }
            if (AreTypes.AnyDecimal(x, y))
            {
                return(Converting.ToDecimal(x).IsGreater(Converting.ToDecimal(y)));
            }
            if (AreTypes.AnyDouble(x, y))
            {
                return(Doubles.ToDouble(x).IsGreater(Doubles.ToDouble(y)));
            }

            return(null);
        }
        public double GetLiveProfit(string confirmation)
        {
            Deal deal    = DataDeals[confirmation];
            Rate current = ForexRates.Data[deal.Product];

            double profit   = 0;
            double previous = Doubles.ParseAny(deal.Rate);

            if (deal.BuySell == "B")
            {
                profit += current.BID - previous;
            }
            else if (deal.BuySell == "S")
            {
                profit += current.OFFER - previous;
            }
            else
            {
                throw new Exception("GetLiveProfit unknown deal BuySell format !");
            }

            profit *= int.Parse(deal.Contract);

            return(profit);
        }
示例#8
0
        public static object Add(object x, object y)
        {
            if (AreTypes.Bool(x, y))
            {
                return(((bool)x).Add((bool)y));
            }
            if (AreTypes.String(x, y))
            {
                return(Strings.Add((string)x, (string)y));
            }
            if (AreTypes.DateTime(x, y))
            {
                return(((DateTime)x).AddSafe((DateTime)y));
            }
            if (AreTypes.AnyDecimal(x, y))
            {
                return(Converting.ToDecimal(x).Add(Converting.ToDecimal(y)));
            }
            if (AreTypes.AnyDouble(x, y))
            {
                return(Doubles.ToDouble(x).Add(Doubles.ToDouble(y)));
            }

            return(null);
        }
示例#9
0
        public void GetFilenameDoublesTest()
        {
            string path = @"C:\Users\rolf\Documents\SongBeamer";
            var    test = new Doubles(path);

            foreach (var d in test.SongFilenameDoublesCollection)
            {
                Debug.WriteLine(string.Format("---Referenzfile-ID {0}----------------------", d.SongReference.ID));
                Debug.WriteLine(d.SongReference.OrigFilename);
                Debug.WriteLineIf(!string.IsNullOrEmpty(d.SongReference.Title), "   Titel               : " + d.SongReference.Title);
                Debug.WriteLineIf(!string.IsNullOrEmpty(d.SongReference.TitleAlternativ), "   Titel alternativ    : " + d.SongReference.TitleAlternativ);
                Debug.WriteLineIf(!string.IsNullOrEmpty(d.SongReference.TitleSecondLang), "   Sprache 2           : " + d.SongReference.TitleSecondLang);
                Debug.WriteLineIf(!string.IsNullOrEmpty(d.SongReference.TitelAlternativSecondLang), "   Sprache 2 alternativ: " + d.SongReference.TitelAlternativSecondLang);
                Debug.WriteLineIf(!string.IsNullOrEmpty(d.SongReference.Songbook), "   Source              : " + d.SongReference.Songbook);
                foreach (var dd in d.SongDouble)
                {
                    Debug.WriteLine(string.Format("---Duplikat-ID {0}--------------------------", dd.ID.ToString()));
                    Debug.WriteLine(dd.OrigFilename);
                    Debug.WriteLineIf(!string.IsNullOrEmpty(dd.Title), "   Titel               : " + dd.Title);
                    Debug.WriteLineIf(!string.IsNullOrEmpty(dd.TitleAlternativ), "   Titel alternativ    : " + dd.TitleAlternativ);
                    Debug.WriteLineIf(!string.IsNullOrEmpty(dd.TitleSecondLang), "   Sprache 2           : " + dd.TitleSecondLang);
                    Debug.WriteLineIf(!string.IsNullOrEmpty(dd.TitelAlternativSecondLang), "   Sprache 2 alternativ: " + dd.TitelAlternativSecondLang);
                    Debug.WriteLineIf(!string.IsNullOrEmpty(dd.Songbook), "   Source              : " + dd.Songbook);
                }
                Debug.WriteLine("");
            }
        }
示例#10
0
        public void ModeTest()
        {
            string text = this.GetTextValue;

            switch (DisplayMode)
            {
            case Mode.Double:
            {
                double value = Doubles.ParseAny(text, DoubleDefault);

                this.Text = Doubles.ToString(value, DoubleDefault.ToString(), Decimals, DoubleMin, DoubleMax, ',') + Unit;
            };
                break;

            case Mode.Integer:
            {
                int value;
                try
                {
                    value = int.Parse(text);
                    if (value > IntegerMax || value < IntegerMin)
                    {
                        value = IntegerDefault;
                    }
                }
                catch { value = IntegerDefault; }

                this.Text = value + Unit;
            };
                break;

            default: return;
            }
        }
示例#11
0
        public void GetStatistics(string pair, ServiceConfiguration.TimeFrame frame, int span, double confidence, ref double max, ref double average, ref double min, ref double test)
        {
            double[][] data = GetMonteCarlo(pair, frame, span, Index);
            double[]   values;

            if (Objects.IsNullOrEmpty(data))
            {
                return;
            }

            values = Doubles.ToArray(data.ToArray(), span - 1, true, false);

            if (Objects.IsNullOrEmpty(values))
            {
                return;
            }

            average = values.Average();
            double change = AMath.StandarConfidence(values, average, confidence, false);

            max = average + change;
            min = average - change;

            double success = 0;

            for (int i = 1; i < Indexes.Length; i++)
            {
                var pack = GetMonteCarlo(pair, frame, span, Indexes[i]);
                if (pack == null)
                {
                    success = 0;
                    break;
                }

                double[][] packet = pack.ToArray();
                values = Doubles.ToArray(packet, span - 1, true, false);


                if (Objects.IsNullOrEmpty(values))
                {
                    success = 0;
                    break;
                }

                double avg = values.Average();
                double ch  = AMath.StandarConfidence(values, avg, confidence, false);
                double mx  = avg + ch;
                double mn  = avg - ch;


                double value = TestData[Indexes[i] + span];

                if (value >= mn && value <= mx)
                {
                    ++success;
                }
            }

            test = ((double)success / (Indexes.Length - 1)) * 100;
        }
示例#12
0
        public virtual bool TryGetDetail(string key, out object detail)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            bool containsDetail = false;

            detail = null;
            if (Ids.ContainsKey(key))
            {
                containsDetail = true;
                detail         = Ids[key];
            }
            else if (Strings.ContainsKey(key))
            {
                containsDetail = true;
                detail         = Strings[key];
            }
            else if (Ints.ContainsKey(key))
            {
                containsDetail = true;
                detail         = Ints[key];
            }
            else if (Doubles.ContainsKey(key))
            {
                containsDetail = true;
                detail         = Doubles[key];
            }

            return(containsDetail);
        }
示例#13
0
 public DynamicSR()
 {
     ShowMidpoint   = false;
     lookbackPeriod = 4;
     confirmBars    = 2;
     dynamicS       = Doubles(10);
     dynamicR       = Doubles(10);
 }
示例#14
0
 public void InterpolateExponential()
 {
     Assert.AreEqual(3, Doubles.InterpolateExponential(3, 10, 0), 0.001);
     Assert.AreEqual(10, Doubles.InterpolateExponential(3, 10, 1), 0.001);
     Assert.AreEqual(3, Doubles.InterpolateExponential(1, 9, 0.5), 0.001);
     Assert.AreEqual(27, Doubles.InterpolateExponential(1, 9, 1.5), 0.001);
     Assert.AreEqual(1 / 3.0, Doubles.InterpolateExponential(1, 9, -0.5), 0.001);
 }
示例#15
0
 public Traversal() : base()
 {
     zigBars       = Integers(5);
     zigHighs      = Doubles(5);
     zagBars       = Integers(5);
     zagLows       = Doubles(5);
     Drawing.Color = Color.LightGreen;
 }
示例#16
0
文件: Add.cs 项目: jeason0813/Asmodat
        /// <summary>
        /// adds range of new data points to series specified by name
        /// </summary>
        /// <typeparam name="TInvoker"></typeparam>
        /// <param name="name"></param>
        /// <param name="points"></param>
        /// <param name="Invoker"></param>
        public void AddRange(string name, DataPoint[] points, ChartValueType?XValueType = null, ChartValueType?YValueType = null)
        {
            if (points.Length <= 0)
            {
                return;
            }



            Invoker.Invoke((MethodInvoker)(() =>
            {
                double xMin = ScaleX.ViewMinimum;
                double xMax = ScaleX.ViewMaximum;


                foreach (DataPoint point in points)
                {
                    ChartMain.Series[name].Points.Add(point);


                    if (MinX == null || MinX.XValue > point.XValue)
                    {
                        MinX = point;
                    }
                    if (MaxX == null || MaxX.XValue < point.XValue)
                    {
                        MaxX = point;
                    }
                }

                if (XValueType != null)
                {
                    ChartMain.Series[name].XValueType = (ChartValueType)XValueType;
                }
                if (YValueType != null)
                {
                    ChartMain.Series[name].YValueType = (ChartValueType)YValueType;
                }

                Area.AxisX.IsStartedFromZero = false;
                Area.AxisY.IsStartedFromZero = false;
                Area.RecalculateAxesScale();
                Area.RecalculateAxesScale();


                DataPoint last = ChartMain.Series[name].Points.Last();
                if (!Doubles.IsNaN(xMax, xMin) && last.XValue > xMax)
                {
                    double change = (xMax - last.XValue);
                    ScaleX.Zoom(xMin + change, last.XValue);
                }


                this.RescaleY();
            }));

            UpdateTime.SetNow();
        }
示例#17
0
 public void Interpolate1D()
 {
     Assert.AreEqual(5, Doubles.Interpolate(3, 7, 0.5), 0.001);
     Assert.AreEqual(3, Doubles.Interpolate(3, 7, 0), 0.001);
     Assert.AreEqual(7, Doubles.Interpolate(3, 7, 1), 0.001);
     Assert.AreEqual(6, Doubles.Interpolate(7, 3, 0.25), 0.001);
     Assert.AreEqual(11, Doubles.Interpolate(7, 3, -1), 0.001);
     Assert.AreEqual(9, Doubles.Interpolate(3, 7, 1.5), 0.001);
 }
示例#18
0
 public PivotLowVs(int left, int right, int length)
 {
     pivotLows     = Doubles();
     pivotBars     = Integers();
     LSTREN        = left;
     RSTREN        = right;
     LENGTH        = Math.Max(length, left + right + 1);
     Drawing.Color = Color.Aqua;
 }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains a time-series from matching arrays of dates and values.
 /// <para>
 /// The two arrays must be the same size and must be sorted from earliest to latest.
 ///
 /// </para>
 /// </summary>
 /// <param name="dates">  the date list </param>
 /// <param name="values">  the value list </param>
 /// <returns> the time-series </returns>
 internal static SparseLocalDateDoubleTimeSeries of(ICollection <LocalDate> dates, ICollection <double> values)
 {
     ArgChecker.noNulls(dates, "dates");
     ArgChecker.noNulls(values, "values");
     LocalDate[] datesArray  = dates.toArray(new LocalDate[dates.Count]);
     double[]    valuesArray = Doubles.toArray(values);
     validate(datesArray, valuesArray);
     return(createUnsafe(datesArray, valuesArray));
 }
示例#20
0
        public static object Sqrt(object x)
        {
            if (AreTypes.AnyDouble(x))
            {
                return(Doubles.ToDouble(x).Sqrt());
            }

            return(null);
        }
示例#21
0
        public static object Power(object x, object y)
        {
            if (AreTypes.AnyDouble(x, y))
            {
                return(Doubles.ToDouble(x).Power(Doubles.ToDouble(y)));
            }

            return(null);
        }
示例#22
0
 public PivotHighVs(int left, int right, int length)
 {
     pivotHighs         = Doubles();
     pivotBars          = Integers();
     this.leftStrength  = left;
     this.rightStrength = right;
     this.length        = Math.Max(length, left + right + 1);
     Drawing.Color      = Color.Orange;
 }
示例#23
0
        /// <summary>
        ///         {"Product", "Product"},
        ///        {"Amount", "Amount"},
        ///        {"Position", "Position"},
        ///        {"Change", "Change"},
        ///        {"Date", "Date"},
        /// </summary>
        /// <param name="deal"></param>
        private object[] ToObjectList(Deal deal)
        {
            if (deal == null)
            {
                return(null);
            }

            string BuySell = (deal.BuySell + "").ToUpper();
            double profit  = Manager.ForexTrading.GetLiveProfit(deal.ConfirmationNumber);

            List <object> objects = new List <object>();

            objects.Add(deal.Product);


            double now = -1;

            if (BuySell == "B")
            {
                objects.Add(" Long ");
                now = Manager.ForexRates.Data[deal.Product].BID;
            }
            else if (BuySell == "S")
            {
                objects.Add(" Short ");
                now = Manager.ForexRates.Data[deal.Product].OFFER;
            }
            else
            {
                objects.Add(" ??? ");
            }

            objects.Add(deal.Contract);
            objects.Add(deal.Rate);


            //Manager.ForexRates.Data[deal.Product].DECIMALS
            if (now <= 0)
            {
                objects.Add(" ??? ");
            }
            else
            {
                objects.Add(Doubles.ToString(now, "???", Manager.ForexConfiguration.GetDecimals(deal.Product), double.MinValue, double.MaxValue, ','));
            }


            objects.Add(Doubles.ToString(profit, "???", 2, double.MinValue, double.MaxValue, ','));
            objects.Add(deal.DealDate);// objects.Add(deal.DealDate.Substring(0, deal.DealDate.Length - 4));
            objects.Add(deal.ConfirmationNumber);


            return(objects.ToArray());
        }
示例#24
0
        public double Get(Doubles item)
        {
            switch (item)
            {
            case SessionSettings.Doubles.HWLimit:
                return(MyHWLimit);

            default:
                throw new Exception("Attempting to get unknown session setting.");
            }
        }
示例#25
0
        public double Lowest(object _values, int length, int displace)
        {
            Doubles values = model.Doubles(_values);
            double  min    = int.MaxValue;

            for (int i = displace; i < length + displace; i++)
            {
                min = Math.Min(values[i], min);
            }
            return(min);
        }
示例#26
0
        public double Highest(object _values, int length, int displace)
        {
            Doubles values = model.Doubles(_values);
            double  max    = int.MinValue;

            for (int i = displace; i < length + displace; i++)
            {
                max = Math.Max(values[i], max);
            }
            return(max);
        }
示例#27
0
        //-------------------------------------------------------------------------
        public virtual void test_putAll_collections()
        {
            ICollection <LocalDate>          dates  = Arrays.asList(date(2013, 1, 1), date(2014, 1, 1));
            ICollection <double>             values = Doubles.asList(2d, 3d);
            LocalDateDoubleTimeSeriesBuilder test   = LocalDateDoubleTimeSeries.builder();

            test.putAll(dates, values);

            assertEquals(test.get(date(2013, 1, 1)), double?.of(2d));
            assertEquals(test.get(date(2014, 1, 1)), double?.of(3d));
        }
示例#28
0
 public override void OnConfigure()
 {
     output = Doubles();
     if (anyInput == null)
     {
         input = Doubles(Bars.Close);
     }
     else
     {
         input = Doubles(anyInput);
     }
 }
示例#29
0
 public static object AddDays(object x, object y)
 {
     if (!IsType.AnyDouble(y))
     {
         return(null);
     }
     if (IsType.DateTime(x))
     {
         return(((DateTime)x).AddDaysSafe(Doubles.ToDouble(y)));
     }
     return(null);
 }
示例#30
0
 public override void OnConfigure()
 {
     if (anyInput == null)
     {
         input = Doubles(Bars.Close);
     }
     else
     {
         input = Doubles(anyInput);
     }
     isChartDynamic = Chart != null && Chart.IsDynamicUpdate;
 }