Exemplo n.º 1
0
    protected object GetPositions(int competitionId)
    {
        var positions         = Sql.GetPosition(Context.User.Identity.Name, Master.SelectedUniverseId, competitionId).ToDictionary(x => x.Key, x => x.Value);
        var simulationResults = PricerHelper.GetVars(Master.GetCompetitionName(), positions, new List <double> {
            0, 0.1, 0.5, 0.9, 1
        });

        return
            (JavaScriptSerializer.SerializeObject(simulationResults));
    }
Exemplo n.º 2
0
    public string GetVar()
    {
        var positions         = Sql.GetPosition(Context.User.Identity.Name, SelectedUniverseId, GetCompetitionId()).Where(x => x.Value != 0).ToDictionary(x => x.Key, x => x.Value);
        var simulationResults = PricerHelper.GetVars(GetCompetitionName(), positions, new List <double> {
            0, 0.1, 0.5, 0.9, 1
        });
        var worst10 = simulationResults.Last().Worst10;

        _cashToInvest = Money + worst10;

        return(worst10.ToString("#,##0", NumberFormatInfo));
    }
Exemplo n.º 3
0
        private bool UserHasEnoughForSwap(Entities context, string user, Team buyTeam, int buyQuantity, Team sellTeam,
                                          int sellQuantity, int price, int universeId, int competitionId, int universeCompetitionId)
        {
            var positions = Sql.GetPosition(user, universeId, competitionId);

            positions[buyTeam]  += buyQuantity;
            positions[sellTeam] -= sellQuantity;
            positions            = positions.Where(x => x.Value != 0).ToDictionary(x => x.Key, x => x.Value);
            var worstScenario = PricerHelper.GetWorstScenario(context.Competitions.First(x => x.Id == competitionId).Name, positions, 0.1);
            var userMoney     = context.Moneys.First(x => x.User == user && x.IdUniverseCompetition == universeCompetitionId);

            return(userMoney.Money1 + price + worstScenario >= 0);
        }
Exemplo n.º 4
0
        private void GetCashInfos(Entities context, string user, int universeId, int competitionId, int universeCompetitionId, string connectionId)
        {
            var positions         = Sql.GetPosition(user, universeId, competitionId).Where(x => x.Value != 0).ToDictionary(x => x.Key, x => x.Value);
            var simulationResults = PricerHelper.GetVars(context.Competitions.First(x => x.Id == competitionId).Name, positions,
                                                         new List <double> {
                0, 0.1, 0.5, 0.9, 1
            });
            var worst10 = simulationResults.Last().Worst10;
            var money   =
                context.Moneys.First(x => x.IdUniverseCompetition == universeCompetitionId && x.User == user).Money1;

            Clients.Client(connectionId)
            .updateCashInfos(string.Format("Cash Available : {0} $", money.ToString("#,##0", NumberFormatInfo)),
                             string.Format("Max Exposition : {0} $", worst10.ToString("#,##0", NumberFormatInfo)),
                             string.Format("Cash To Invest : {0} $", (money + worst10).ToString("#,##0", NumberFormatInfo)));
        }
Exemplo n.º 5
0
    protected object GetPricing()
    {
        Dictionary <int, double> prices = null;
        Dictionary <int, string> names  = new Dictionary <int, string>();

        using (var context = new Entities())
        {
            var id          = Master.GetCompetitionId();
            var competition = context.Competitions.First(x => id == x.Id);
            var strength    = new Dictionary <Team, double>();
            foreach (var team in context.Teams.Where(x => x.IdCompetition == competition.Id && x.RealTeam.HasValue && x.RealTeam.Value))
            {
                strength[team] = team.Strength ?? 1;
                names[team.Id] = team.Name;
            }
            prices = PricerHelper.Price(competition.Name, strength);
        }
        return(JavaScriptSerializer.SerializeObject(prices.Where(x => x.Value > 0).Select(x => new PricingInfo {
            Team = names[x.Key], Price = x.Value
        }).ToList()));
    }
Exemplo n.º 6
0
        private bool UserHasEnough(Entities context, string user, Team team, int quantity, int price, string side, int universeId, int competitionId, int universeCompetitionId)
        {
            var positions      = Sql.GetPosition(user, universeId, competitionId);
            var signedQuantity = (side == "SELL" ? -1 : 1) * quantity;

            positions[team] += signedQuantity;
            positions        = positions.Where(x => x.Value != 0).ToDictionary(x => x.Key, x => x.Value);
            var worstScenario = PricerHelper.GetWorstScenario(context.Competitions.First(x => x.Id == competitionId).Name, positions, 0.1);
            var userMoney     = context.Moneys.First(x => x.User == user && x.IdUniverseCompetition == universeCompetitionId);

            var expo = -signedQuantity * price + worstScenario;

            if (userMoney.Money1 + expo >= 0)
            {
                return(true);
            }

            positions[team] -= signedQuantity;
            var currentScenario = PricerHelper.GetWorstScenario(context.Competitions.First(x => x.Id == competitionId).Name, positions, 0.1);

            return(expo > currentScenario);
        }