Пример #1
0
        internal void ProcessBuy(DateTime time, double bid, double ask, UnilateralTickCollection <DateTime> ticks)
        {
            KeyValuePair <DateTime, double>?whenTP = ticks.FirstEventWhenMoreOrEqual(time, ask + m_tp);

            AllCount++;
            if (null == whenTP)
            {
                return;
            }
            Count++;
            KeyValuePair <DateTime, double> when = (KeyValuePair <DateTime, double>)whenTP;
            TimeSpan interval = when.Key - time;
            double   hours    = interval.TotalHours;

            Sum  += hours;
            Sum2 += hours * hours;
            if (time == when.Key)
            {
                return;
            }
            double minimum = ticks.FindMinimum(time, when.Key);

            minimum  = ask - minimum;
            Spread  += minimum;
            Spread2 += (minimum * minimum);
        }
Пример #2
0
 private static void ProcessBuy(DateTime time, double bid, double ask, UnilateralTickCollection <DateTime> ticks)
 {
     foreach (var element in s_infos)
     {
         element.Value.ProcessBuy(time, bid, ask, ticks);
     }
 }
Пример #3
0
 public ResetTimeAnalyzer(double tp, double timeFactor, UnilateralTickCollection <int> bids, UnilateralTickCollection <int> asks,
                          double coefToUSD, double swap = 0)
 {
     m_bids           = bids;
     m_asks           = asks;
     TakeProfit       = tp;
     TimeFactor       = timeFactor;
     this.m_swap      = swap;
     this.m_coefToUSD = coefToUSD;
 }
Пример #4
0
        public static void Run(string symbol)
        {
            Initialize(symbol);
            TicksFactory factory = CreateFactory(symbol);
            List <KeyValuePair <DateTime, double> > bids  = factory.Bids;
            List <KeyValuePair <DateTime, double> > asks  = factory.Asks;
            UnilateralTickCollection <DateTime>     ticks = new UnilateralTickCollection <DateTime>(asks);

            RunTest(bids, asks, ticks, ProcessSell);
            Save(symbol + " sell");
            ticks = new UnilateralTickCollection <DateTime>(bids);
            RunTest(bids, asks, ticks, ProcessBuy);
            Save(symbol + " buy");
        }
Пример #5
0
        private void MakeIndex(List <GroupTick> ticks)
        {
            List <KeyValuePair <int, double> > data = new List <KeyValuePair <int, double> >();
            int count = ticks.Count;

            // prepare bids
            for (int index = 0; index < count; ++index)
            {
                data.Add(new KeyValuePair <int, double>(index, ticks[index].OpenBid));
            }
            BidsIndexCollection = new UnilateralTickCollection <int>(data);
            // prepare asks
            data.Clear();
            for (int index = 0; index < count; ++index)
            {
                data.Add(new KeyValuePair <int, double>(index, ticks[index].OpenAsk));
            }
            AsksIndexCollection = new UnilateralTickCollection <int>(data);
        }
Пример #6
0
        public void CompareOneAndMultiplyAnalyses()
        {
            UnilateralTickCollection <int> bids = new UnilateralTickCollection <int>(s_bids);
            UnilateralTickCollection <int> asks = new UnilateralTickCollection <int>(s_asks);

            ResetTimeAnalyzer first  = new ResetTimeAnalyzer(0.01, 1 / 60d, bids, asks, 1);
            ResetTimeAnalyzer second = new ResetTimeAnalyzer(0.01, 1 / 60d, bids, asks, 1);


            first.Process(s_buy, s_sell);
            second.Process(s_buy, s_sell);

            Assert.IsTrue(first.TakeProfit == second.TakeProfit);
            Assert.IsTrue(first.TimeFactor == second.TimeFactor);
            Assert.IsTrue(first.AverageTime == second.AverageTime);
            Assert.IsTrue(first.AverageLoss == second.AverageLoss);
            Assert.IsTrue(first.SigmaTime == second.SigmaTime);
            Assert.IsTrue(first.SigmaLoss == second.SigmaLoss);
            Assert.IsTrue(first.ResettingPercentage == second.ResettingPercentage);

            second.Process(s_buy, s_sell);
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.TakeProfit, second.TakeProfit));
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.TimeFactor, second.TimeFactor));
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.AverageTime, second.AverageTime));
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.AverageLoss, second.AverageLoss));
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.SigmaTime, second.SigmaTime, 0.001));
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.SigmaLoss, second.SigmaLoss, 0.001));
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.ResettingPercentage, second.ResettingPercentage));

            second.Process(s_buy, s_sell);
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.TakeProfit, second.TakeProfit));
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.TimeFactor, second.TimeFactor));
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.AverageTime, second.AverageTime));
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.AverageLoss, second.AverageLoss));
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.SigmaTime, second.SigmaTime, 0.001));
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.SigmaLoss, second.SigmaLoss, 0.001));
            Assert.IsTrue(NumericalMethods.IsApproximatelyEqual(first.ResettingPercentage, second.ResettingPercentage));
        }
Пример #7
0
        public TicksUnit()
        {
            TicksFactory factory = new TicksFactory();

            factory.Parse(Resources.Ticks, cPattern, 1, 2, 3);
            m_items = factory.Bids;
            m_items.Sort(Compare);
            m_from    = m_items[0].Key;
            m_to      = m_items[m_items.Count - 1].Key;
            m_ticks   = new UnilateralTickCollection <DateTime>(m_items);
            m_minimum = double.PositiveInfinity;
            m_maximum = double.NegativeInfinity;
            foreach (var element in m_items)
            {
                if (element.Value < m_minimum)
                {
                    m_minimum = element.Value;
                }
                if (element.Value > m_maximum)
                {
                    m_maximum = element.Value;
                }
            }
        }
Пример #8
0
        private static void RunTest(List <KeyValuePair <DateTime, double> > bids, List <KeyValuePair <DateTime, double> > asks, UnilateralTickCollection <DateTime> ticks, Action <DateTime, double, double, UnilateralTickCollection <DateTime> > func)
        {
            int progress = 0;

            Console.WriteLine("Progress = {0} %", progress);
            for (int index = 0; index < bids.Count; index += cStep)
            {
                KeyValuePair <DateTime, double> bid = bids[index];
                KeyValuePair <DateTime, double> ask = asks[index];
                DateTime time = bid.Key;
                func(time, bid.Value, ask.Value, ticks);

                int newProgress = index * 100 / bids.Count;
                if (newProgress != progress)
                {
                    progress = newProgress;
                    Console.WriteLine("Progress = {0} %", progress);
                }
            }
        }