Exemplo n.º 1
0
        public void TestAddEntryWithDuplicateParticipantId()
        {
            var market = new Market("race");

            market.Add(new Entry(new Participant("1", "Bart"), 10m));
            market.Add(new Entry(new Participant("1", "Nelson"), 11m));
        }
Exemplo n.º 2
0
        public void TestAddMultipleEntriesWithTheSamePrice()
        {
            var market = new Market("race");

            market.Add(new Entry(new Participant("1", "Bart"), 10m));
            market.Add(new Entry(new Participant("2", "Nelson"), 10m));
            var entries = market.Entries.ToArray();

            Assert.AreEqual(2, entries.Length);
            Assert.AreEqual(10m, entries[0].Price);
            Assert.AreEqual("Bart", entries[0].Participant.Name);
            Assert.AreEqual(10m, entries[1].Price);
            Assert.AreEqual("Nelson", entries[1].Participant.Name);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the instance of the <see cref="MarketHoursDatabase"/> class produced by reading in the market hours
        /// data found in /Data/market-hours/
        /// </summary>
        /// <param name="dataFolder">Path to the data folder</param>
        /// <returns>A <see cref="MarketHoursDatabase"/> class that represents the data in the market-hours folder</returns>
        public static MarketHoursDatabase FromDataFolder(string dataFolder)
        {
            lock (DataFolderMarketHoursDatabaseLock)
            {
                if (_dataFolderMarketHoursDatabase == null)
                {
                    var path = Path.Combine(dataFolder, "market-hours", "market-hours-database.json");
                    _dataFolderMarketHoursDatabase = FromFile(path);

                    // Add markets not already present
                    Market.Reset();
                    var listing = _dataFolderMarketHoursDatabase.ExchangeHoursListing;
                    int code    = 0;
                    foreach (var item in listing)
                    {
                        SecurityDatabaseKey security = item.Key;
                        string market = security.Market;
                        if (Market.Encode(market) == null)
                        {
                            while (Market.Decode(code) != null)
                            {
                                code++;
                            }

                            // be sure to add a reference to the unknown market, otherwise we won't be able to decode it coming out
                            Market.Add(market, code);
                            code++;
                        }
                    }
                }
            }
            return(_dataFolderMarketHoursDatabase);
        }
Exemplo n.º 4
0
        public virtual bool Register(SettingModel settings)
        {
            // Get name of virtual class
            string name = GetType().Name.ToLowerInvariant();

            // Make sure provider is registered
            if (Market.Encode(name) == null)
            {
                // be sure to add a reference to the unknown market, otherwise we won't be able to decode it coming out
                int code = 0;
                while (Market.Decode(code) != null)
                {
                    code++;
                }

                Market.Add(name, code);
            }

            // Make sure Market Hours Database exist
            string folder = Path.Combine(settings.DataFolder, "market-hours");

            Directory.CreateDirectory(folder);
            string path = Path.Combine(folder, "market-hours-database.json");

            if (!File.Exists(path))
            {
                var    emptyExchangeHours = new Dictionary <SecurityDatabaseKey, MarketHoursDatabase.Entry>();
                string jsonString         = JsonConvert.SerializeObject(new MarketHoursDatabase(emptyExchangeHours));
                File.WriteAllText(path, jsonString);
            }

            return(true);
        }
Exemplo n.º 5
0
        public void Should_let_take_and_add_gems_to_market()
        {
            completeMarket.TakeGems(Gems.Ruby, Gems.Ruby);
            CheckMarket(completeMarket, new int[] { 7, 5, 7, 7, 7 }, 5);
            completeMarket.TakeGems(Gems.Ruby, Gems.Ruby);
            CheckMarket(completeMarket, new int[] { 7, 3, 7, 7, 7 }, 5);

            ShouldThrow(() => completeMarket.TakeGems(Gems.Gold));
            ShouldThrow(() => completeMarket.TakeGems(Gems.Ruby, Gems.Ruby));
            ShouldThrow(() => completeMarket.TakeGems(Gems.Emerald, Gems.Ruby));
            ShouldThrow(() => completeMarket.TakeGems(Gems.Emerald));

            completeMarket.TakeGems(Gems.Ruby, Gems.Diamond, Gems.Emerald);
            CheckMarket(completeMarket, new int[] { 6, 2, 7, 7, 6 }, 5);
            completeMarket.TakeGold();
            CheckMarket(completeMarket, new int[] { 6, 2, 7, 7, 6 }, 4);
            completeMarket.TakeGems(Gems.Ruby, Gems.Diamond, Gems.Sapphire);
            CheckMarket(completeMarket, new int[] { 5, 1, 7, 6, 6 }, 4);
            completeMarket.TakeGems(Gems.Diamond, Gems.Diamond);
            CheckMarket(completeMarket, new int[] { 3, 1, 7, 6, 6 }, 4);
            completeMarket.TakeGems(Gems.Ruby, Gems.Emerald, Gems.Sapphire);
            CheckMarket(completeMarket, new int[] { 3, 0, 7, 5, 5 }, 4);

            ShouldThrow(() => completeMarket.TakeGems(Gems.Ruby, Gems.Emerald, Gems.Sapphire));
            ShouldThrow(() => completeMarket.TakeGems(Gems.Diamond, Gems.Diamond));

            completeMarket.Add(Gems.Diamond, Gems.Ruby);

            completeMarket.TakeGems(Gems.Ruby, Gems.Emerald, Gems.Sapphire);
            completeMarket.TakeGems(Gems.Diamond, Gems.Diamond);
        }
Exemplo n.º 6
0
        private void SaveMarket(object itemObject)
        {
            MarketViewModel item = itemObject as MarketViewModel;

            if (item != null && item.IsValid)
            {
                Market.Add(item);
            }
            Back();
        }
Exemplo n.º 7
0
        public void TestAddEntry()
        {
            var market = new Market("race");

            market.Add(new Entry(new Participant("1", "Bart"), 10m));
            var entries = market.Entries.ToArray();

            Assert.AreEqual(1, entries.Length);
            Assert.AreEqual(10, entries[0].Price);
        }
Exemplo n.º 8
0
        private static void RegisterProvider(Type provider)
        {
            string name = provider.Name.ToLowerInvariant();

            if (Market.Encode(name) == null)
            {
                // be sure to add a reference to the unknown market, otherwise we won't be able to decode it coming out
                int code = 0;
                while (Market.Decode(code) != null)
                {
                    code++;
                }

                Market.Add(name, code);
            }
        }
Exemplo n.º 9
0
        public static void Setup(TestContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Add a reference to the unknown market
            int code = 0;

            while (Market.Decode(code) != null)
            {
                code++;
            }

            Market.Add(_market, code);
        }
Exemplo n.º 10
0
        private static bool RegisterProvider(SettingModel settings, IProvider provider)
        {
            string name = provider.GetType().Name.ToLowerInvariant();

            if (Market.Encode(name) == null)
            {
                // be sure to add a reference to the unknown market, otherwise we won't be able to decode it coming out
                int code = 0;
                while (Market.Decode(code) != null)
                {
                    code++;
                }

                Market.Add(name, code);
            }

            provider.Register(settings);
            return(true);
        }
Exemplo n.º 11
0
        private void GenMar()
        {
            DataTable marTable = _ds.Tables["Mar"];

            mar = new Market()
            {
                AggRo = new List <TimeValue>()
            };

            mar.Ro = x =>
            {
                if (mar.AggRo.Count == 1)
                {
                    return(mar.AggRo[0].value);
                }
                for (int i = 1; i < mar.AggRo.Count; i++)
                {
                    if (x < mar.AggRo[i].Time)
                    {
                        return(mar.AggRo[i - 1].value);
                    }
                }
                return(mar.AggRo[mar.AggRo.Count - 1].value);
            };

            foreach (DataRow dr in marTable.Rows)
            {
                MarketSegment ms = new MarketSegment()
                {
                    MSID        = Convert.ToInt32(dr["ID"]),
                    Description = dr["Des"].ToString(),
                    Retreat     = Convert.ToDouble(dr["Retreat"]),
                    AggLamada   = new List <TimeValue>()
                };

                ms.Lamada = x =>
                {
                    if (ms.AggLamada.Count == 1)
                    {
                        return(ms.AggLamada[0].value);
                    }
                    for (int i = 1; i < ms.AggLamada.Count; i++)
                    {
                        if (x < ms.AggLamada[i].Time)
                        {
                            return(ms.AggLamada[i - 1].value);
                        }
                    }
                    return(ms.AggLamada[ms.AggLamada.Count - 1].value);
                };

                string   c  = dr["ConSet"].ToString();
                string   p  = dr["PreVec"].ToString();
                string[] cc = c.Split(',');
                string[] pp = p.Split(',');

                for (int i = 0; i < cc.Length; i++)
                {
                    Route  temp      = pathList.Find(r => r.RouteID == Convert.ToInt32(cc[i]));
                    double tempvalue = Convert.ToDouble(pp[i]);
                    if (temp != null)
                    {
                        ms.ConsiderationDic.Add(temp, tempvalue);
                    }
                }
                mar.Add(ms);
            }
        }
Exemplo n.º 12
0
        public void GenMarket()
        {
            mar = new Market()
            {
                AggRo = new List <TimeValue>()
            };
            mar.Ro = x =>
            {
                if (mar.AggRo.Count == 1)
                {
                    return(mar.AggRo[0].value);
                }
                for (int i = 1; i < mar.AggRo.Count; i++)
                {
                    if (x < mar.AggRo[i].Time)
                    {
                        return(mar.AggRo[i - 1].value);
                    }
                }
                return(mar.AggRo[mar.AggRo.Count - 1].value);
            };
            DataTable dt = _ds.Tables["Market"];

            foreach (DataRow dr in dt.Rows)
            {
                MarketSegment ms = new MarketSegment()
                {
                    MSID      = Convert.ToInt32(dr["ID"]),
                    OriSta    = dr["O"].ToString(),
                    DesSta    = dr["D"].ToString(),
                    Retreat   = Convert.ToDouble(dr["Retreat"]),
                    Transfer  = Convert.ToInt32(dr["TRANSFER"]),
                    AggLamada = new List <TimeValue>()
                };
                ms.Lamada = x =>
                {
                    if (ms.AggLamada.Count == 1)
                    {
                        return(ms.AggLamada[0].value);
                    }
                    for (int i = 1; i < ms.AggLamada.Count; i++)
                    {
                        if (x < ms.AggLamada[i].Time)
                        {
                            return(ms.AggLamada[i - 1].value);
                        }
                    }
                    return(ms.AggLamada[ms.AggLamada.Count - 1].value);
                };
                for (int s = 6; s < dt.Columns.Count; s++)
                {
                    ms.AggLamada.Add(new TimeValue()
                    {
                        value = Convert.ToDouble(dr[s])
                    });
                }
                mar.Add(ms);
            }
            int ss = 0;

            for (int i = 0; i < dt.Columns.Count - 6; i++)
            {
                double total  = (mar as List <MarketSegment>).Sum(s => s.AggLamada[i].value);
                int    d      = number_of_intervals((Int32)Math.Ceiling(total), 0.1);
                double Lamada = total / d;

                mar.AggRo.Add(new TimeValue()
                {
                    Time = ss, value = Lamada
                });
                foreach (MarketSegment ms in mar)
                {
                    ms.AggLamada[i].Time  = ss;
                    ms.AggLamada[i].value =
                        ((ms.AggLamada[i].value / d) * Math.Exp(-ms.AggLamada[i].value / d)) / Lamada;
                }
                ss += d;
            }
            TimeHorizon = ss;
        }