Example #1
0
    static string GetShortTitle(MarketState phase, string nicheName)
    {
        var description = "";

        switch (phase)
        {
        case MarketState.Death:
            description = $"{nicheName} are DYING.";
            break;

        case MarketState.Decay:
            description = $"{nicheName} are in DECAY.";
            break;

        case MarketState.Innovation:
            description = $"{nicheName} - future or just a moment?";
            break;

        case MarketState.MassGrowth:
        case MarketState.MassUsage:
            description = $"{nicheName} are EVERYWHERE.";
            break;

        case MarketState.Trending:
            description = $"{nicheName} are TRENDING.";
            break;
        }

        return($"TRENDS change: {description}");
    }
Example #2
0
    string GetMarketStateDescription(MarketState state)
    {
        switch (state)
        {
        case MarketState.Death:
            return("This market is DEAD. People don't need these apps anymore!");

        case MarketState.Decay:
            return("This market's peak has gone. Reduce your expenses and prepare for market death");

        case MarketState.Idle:
            return("We don't know if people need this or not. Maybe you'll be the innovator");

        case MarketState.Innovation:
            return("Some people had shown their interest in these apps! Be first in new market!");

        case MarketState.Trending:
            return("This market grows extremely fast");

        case MarketState.MassGrowth:
            return("People need these apps, but will it last long?");

        default:
            return("??? " + state.ToString());
        }
    }
 private void OnMarketStateChanged(MarketState marketState)
 {
     if (MarketStateChanged != null)
     {
         MarketStateChanged(this, marketState);
     }
 }
Example #4
0
        /// <summary>
        /// Simulate a day in the market.
        /// </summary>
        public void Simulate()
        {
            if (CurrentDate != EndDate)
            {
                CurrentDate = CurrentDate.AddDays(1);
                StockDay    = DataManager.IsStockDay(CurrentDate);

                // before we even bother with any calculations, we need to
                // make sure the stock market was open on this given day
                if (StockDay)
                {
                    UpdateMarketState();
                    StockDays.Add(CurrentDate);
                    Log("Stockday on " + CurrentDate + ", proceeding...");

                    // how has our equity changed over postmarket and premarket
                    for (int i = 0; i < Positions.Count; i++)
                    {
                        List <BarData> history = MarketState.FirstOrDefault(x => x.Key == Positions[i].Symbol).Value;

                        // how much has the stock changed in value overnight?
                        double change = history.Last().Open - history[history.Count - 2].Close;

                        // change our equity!
                        Equity += change * Positions[i].Shares;
                    }

                    // process orders
                    ProcessAllOrders();

                    // with our new positions, how will our equity change today?
                    for (int i = 0; i < Positions.Count; i++)
                    {
                        List <BarData> history = MarketState.FirstOrDefault(x => x.Key == Positions[i].Symbol).Value;

                        // how much has the stock changed in value overnight?
                        double change = history.Last().Close - history.Last().Open;

                        // change our equity!
                        Equity += change * Positions[i].Shares;

                        // update the position value
                        Positions[i].PriceHistory.Add(new Tuple <DateTime, double, double>(CurrentDate, history.Last().Close, change));
                    }

                    // allow the strategy to make calls for the next day
                    Strategy.Update(this);

                    // process all logs for the day
                    ProcessLogs();
                }

                EquityHistory.Add(new Tuple <DateTime, double>(CurrentDate, Equity));
                BuyingPowerHistory.Add(new Tuple <DateTime, double>(CurrentDate, BuyingPower));
            }
            else
            {
                throw new Exception("Simulation is already complete.");
            }
        }
Example #5
0
 public void OpenMarket()
 {
     if (MarketState != MarketState.Open)
     {
         _logger.LogCritical("Market opened.");
         MarketState = MarketState.Open;
     }
 }
Example #6
0
 public void CloseMarket()
 {
     if (MarketState != MarketState.Closed)
     {
         _logger.LogCritical("Market closed.");
         MarketState = MarketState.Closed;
     }
 }
    public void ReplaceNicheState(MarketState newPhase, int newDuration)
    {
        var index     = GameComponentsLookup.NicheState;
        var component = (NicheStateComponent)CreateComponent(index, typeof(NicheStateComponent));

        component.Phase    = newPhase;
        component.Duration = newDuration;
        ReplaceComponent(index, component);
    }
Example #8
0
        private void OnMarketStateChanged(MarketState e)
        {
            var handler = MarketStateChanged;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Example #9
0
        public void WhenIInferTheMarketSStatus()
        {
            if (!ScenarioContext.Current.ContainsKey("Market"))
            {
                return;
            }

            Market market = ScenarioContext.Current["Market"] as Market;

            MarketState state = new MarketState(market, true);
        }
Example #10
0
        /// <summary>
        /// Using the current day, we update the market information.
        /// </summary>
        private void UpdateMarketState()
        {
            List <string> stocks = DataManager.GetStocks(HalfBake);

            MarketState.Clear();

            for (int i = 0; i < stocks.Count; i++)
            {
                MarketState.Add(stocks[i], DataManager.GetBars(stocks[i], StartDate, CurrentDate));
            }
        }
Example #11
0
        void CalculateLockedVolume(AccountEntry account, MarketState state)
        {
            foreach (var asset in this.assets.Values)
                asset.LockedVolume = 0D;

            var cashAccount = new CashAccountInfo(account, this.assets.Values);

            using (var calculator = new CashAccountCalculator(cashAccount, state))
            {
            }
        }
Example #12
0
 public void OpenMarket()
 {
     lock (marketStateLock)
     {
         if (MarketState != MarketState.Open)
         {
             timer = Observable.Timer(updateInterval, updateInterval, RxApp.MainThreadScheduler)
                     .Subscribe(_ => UpdateStockPrices());
             MarketState = MarketState.Open;
         }
     }
 }
Example #13
0
 public void Close()
 {
     // Ask salesmen to close their stall
     foreach (Person person in _people)
     {
         if (person is Salesman && person.Arrived)
         {
             ((Salesman)person).CloseStall();
         }
     }
     _state = MarketState.Closed;
     OnChanged(String.Format("Market at {0} has ended", _location));
 }
Example #14
0
 public void Close()
 {
     // Ask salesmen to close their stall
     foreach (Person person in _people)
     {
         if (person is Salesman && person.Arrived)
         {
             ((Salesman)person).CloseStall();
         }
     }
     _state = MarketState.Closed;
     OnChanged(String.Format("Market at {0} has ended", _location));
 }
        private void HandleMarketStateChanged(object sender, MarketState marketState)
        {
            switch (marketState)
            {
            case MarketState.Open:
                _clients.All.marketOpened();
                break;

            case MarketState.Closed:
                _clients.All.marketClosed();
                break;
            }
        }
Example #16
0
        private void BroadcastMarketStateChange(MarketState marketState)
        {
            switch (marketState)
            {
            case MarketState.Closed:
                Clients.All.marketClosed();
                break;

            case MarketState.Open:
                Clients.All.marketOpened();
                break;
            }
        }
Example #17
0
        public Task OpenMarket()
        {
            lock (_marketStateLock)
            {
                if (MarketState != MarketState.Open)
                {
                    _timerStockUpdate = new Timer(UpdateStockPrices, null, _updateInterval, _updateInterval);
                    MarketState       = MarketState.Open;
                    this.Callback?.OnMarketStateChanged(MarketState);
                }
            }

            return(Task.CompletedTask);
        }
        public void OpenMarket()
        {
            lock (_marketStateLock)
            {
                if (MarketState != MarketState.Open)
                {
                    _timer = new Timer(UpdateMarketDataPrices, null, _updateInterval, _updateInterval);

                    MarketState = MarketState.Open;

                    OnMarketStateChanged(MarketState.Open);
                }
            }
        }
Example #19
0
        public void OpenMarket()
        {
            lock (_marketStateLock)
            {
                if (MarketState != MarketState.Open)
                {
                    _timer = new Timer(UpdateStockPrices, null, _updateInterval, _updateInterval);

                    MarketState = MarketState.Open;

                    BroadcastMarketStateChange(MarketState.Open);
                }
            }
        }
Example #20
0
        public void OpenMarket()
        {
            lock (_marketStateLock)
            {
                if (MarketState != MarketState.Open)
                {
                    _timer = new Timer(UpdateStockPrices, null, _updateInterval, _updateInterval);

                    MarketState = MarketState.Open;

                    BroadcastMarketStateChange(MarketState.Open);
                }
            }
        }
Example #21
0
        public CashAssets(IEnumerable<AssetInfo> assets, AccountEntry account, MarketState state)
        {
            var query = assets.Select(o => new Asset(account)
            {
                Currency = o.Currency,
                Volume = o.Balance,
                DepositCurrency = o.Balance,
                Rate = 1
            });

            this.assets = query.ToDictionary(o => o.Currency);

            this.CalculateLockedVolume(account, state);
        }
Example #22
0
        void CalculateLockedVolume(AccountEntry account, MarketState state)
        {
            foreach (var asset in this.assets.Values)
            {
                asset.LockedVolume = 0D;
            }

            var cashAccount = new CashAccountInfo(account, this.assets.Values);

            var orders = cashAccount.Orders.ToList();

            using (var calculator = new CashAccountCalculator(cashAccount, state))
            {
            }
        }
Example #23
0
        public CashAssets(IEnumerable <AssetInfo> assets, AccountEntry account, MarketState state)
        {
            var query = assets.Select(o => new Asset(account)
            {
                Currency        = o.Currency,
                Volume          = o.Balance,
                LockedVolume    = o.LockedAmount,
                DepositCurrency = o.Balance,
                Rate            = 1
            });

            this.assets = query.ToDictionary(o => o.Currency);

            this.CalculateLockedVolume(account, state);
        }
        private void BroadcastMarketStateChange(MarketState marketState)
        {
            switch (marketState)
            {
            case MarketState.Open:
                Clients.All.marketStateChanged(marketState.ToString());
                break;

            case MarketState.Closed:
                Clients.All.marketStateChanged(marketState.ToString());
                break;

            default:
                break;
            }
        }
Example #25
0
        public void CloseMarket()
        {
            lock (marketStateLock)
            {
                if (MarketState == MarketState.Open)
                {
                    if (timer != null)
                    {
                        timer.Dispose();
                    }


                    MarketState = MarketState.Closed;
                }
            }
        }
        public static float GetMarketStatePriceModifier(MarketState phase)
        {
            switch (phase)
            {
            case MarketState.Innovation:    return(1);

            case MarketState.Trending:      return(0.8f);

            case MarketState.MassGrowth:    return(0.7f);

            case MarketState.MassUsage:     return(0.65f);

            case MarketState.Decay:         return(0.5f);

            default: return(0);
            }
        }
Example #27
0
        private string GetCurrentMenu(MarketState state, string reply = null)
        {
            var menu = new StringBuilder();

            LastState = State;
            State     = state;

            if (State != MarketState.View)
            {
                menu.AppendLine(GetReply(Check.NotNull(reply) ? reply : GetNextResponse()));
            }

            menu.AppendLine(GetMenuContent());
            menu.Append(GetMenuFooter());

            return(menu.ToString());
        }
Example #28
0
        public void CloseMarket()
        {
            lock (_marketStateLock)
            {
                if (MarketState == MarketState.Open)
                {
                    if (_timer != null)
                    {
                        _timer.Dispose();
                    }

                    MarketState = MarketState.Closed;

                    BroadcastMarketStateChange(MarketState.Closed);
                }
            }
        }
        public bool OpenMarket(DateTime startDate, DateTime endDate, int interval)
        {
            lock (_marketStateLock)
            {
                if (MarketState != MarketState.Open)
                {
                    LoadMarket(startDate, endDate, 10);

                    _timer = new Timer(UpdateMarketRates, null, interval, interval);

                    MarketState = MarketState.Open;

                    BroadcastMarketStateChange(MarketState.Open);
                }
            }
            return(true);
        }
Example #30
0
        private async Task BroadcastMarketStateChange(MarketState marketState)
        {
            switch (marketState)
            {
            case MarketState.Open:
                await Hub.Clients.All.SendAsync("marketOpened");

                break;

            case MarketState.Closed:
                await Hub.Clients.All.SendAsync("marketClosed");

                break;

            default:
                break;
            }
        }
Example #31
0
        private static int GetNichePeriodDurationInMonths(
            MarketState phase,
            bool isFastGrowingOnStart = false, bool isSlowlyDecaying = false)
        {
            switch (phase)
            {
            case MarketState.Innovation: return(8);

            case MarketState.Trending: return(24);

            case MarketState.MassGrowth: return(60);

            //case MarketState.MassUsage: return
            case MarketState.Decay: return(24);

            default: return(1);
            }
        }
Example #32
0
        public static MarketState GetMarketState(
            this List <CompiledScheduleTimeInterval> compiledSchedule, string marketId, DateTime currentDateTime)
        {
            var currentInterval = compiledSchedule
                                  .Where(x => IsBetween(currentDateTime, x.Start, x.End))
                                  .OrderByDescending(x => x.Schedule.Rank)
                                  .FirstOrDefault();

            var isEnabled = currentInterval?.Enabled() ?? true;

            var result = new MarketState
            {
                Id        = marketId,
                IsEnabled = isEnabled,
            };

            return(result);
        }
Example #33
0
        public Task CloseMarket()
        {
            lock (_marketStateLock)
            {
                if (MarketState == MarketState.Open)
                {
                    if (_timerStockUpdate != null)
                    {
                        _timerStockUpdate.Dispose();
                    }
                    _timerStockUpdate = null;
                    MarketState       = MarketState.Closed;
                    this.Callback?.OnMarketStateChanged(MarketState);
                }
            }

            return(Task.CompletedTask);
        }
Example #34
0
 public void CloseMarket()
 {
     if (MarketState == MarketState.Open || MarketState == MarketState.Opening)
     {
         lock (_marketStateLock)
         {
             if (MarketState == MarketState.Open || MarketState == MarketState.Opening)
             {
                 MarketState = MarketState.Closing;
                 if (_timer != null)
                 {
                     _timer.Dispose();
                 }
                 MarketState = MarketState.Closed;
                 BroadcastMarketStateChange(MarketState.Closed);
             }
         }
     }
 }
        public static int GetMarketGrowth(MarketState phase)
        {
            switch (phase)
            {
            case MarketState.Idle:
                return(0);

            case MarketState.Innovation:
                return(1);

            case MarketState.Trending:
                return(5);

            case MarketState.MassGrowth:
                return(7);
            }

            return(5);
        }
Example #36
0
        public void CloseMarket()
        {
            lock (marketStateLock)
            {
                if (MarketState == MarketState.Open)
                {
                    if (timer != null)
                    {
                        timer.Dispose();
                    }


                    MarketState = MarketState.Closed;
                }
            }
        }
Example #37
0
 public void OpenMarket()
 {
     lock (marketStateLock)
     {
         if (MarketState != MarketState.Open)
         {
             timer = Observable.Timer(updateInterval, updateInterval, RxApp.MainThreadScheduler)
                               .Subscribe(_ => UpdateStockPrices());
             MarketState = MarketState.Open;
         }
     }
 }
Example #38
0
 private static void BroadcastMarketStateChange(MarketState marketState)
 {
     var clients = GetClients();
     switch (marketState)
     {
         case MarketState.Open:
             clients.marketOpened();
             break;
         case MarketState.Closed:
             clients.marketClosed();
             break;
         case MarketState.Reset:
             clients.marketReset();
             break;
         default:
             break;
     }
 }
 public MarketStateChangeRequest(MarketState newState)
 {
     NewState = newState;
 }
 public MarketStateChange(MarketState currentState)
 {
     CurrentState = currentState;
 }
Example #41
0
 private void BroadcastMarketStateChange(MarketState marketState)
 {
     switch (marketState)
     {
         case MarketState.Open:
             Clients.All.marketOpened();
             break;
         case MarketState.Closed:
             Clients.All.marketClosed();
             break;
         default:
             break;
     }
 }
Example #42
0
 public void Open()
 {
     _state = MarketState.Open;
     OnChanged(String.Format("Market starts at {0}", _location));
 }