Esempio n. 1
0
        public void WeekStats_ProvidedRecordsEachWeekDayWithTotal400Secs_Returns400SecsAsField()
        {
            //arrange
            var input = new[] {
                new TrackRecord
                {
                    StartDate = new DateTime(2014, 8, 18, 1, 0, 0),
                    EndDate   = new DateTime(2014, 8, 18, 1, 0, 40)
                },
                new TrackRecord
                {
                    StartDate = new DateTime(2014, 8, 19, 2, 0, 40),
                    EndDate   = new DateTime(2014, 8, 19, 2, 1, 40)
                },
                new TrackRecord
                {
                    StartDate = new DateTime(2014, 8, 20, 2, 0, 40),
                    EndDate   = new DateTime(2014, 8, 20, 2, 1, 40)
                },
                new TrackRecord
                {
                    StartDate = new DateTime(2014, 8, 21, 2, 0, 40),
                    EndDate   = new DateTime(2014, 8, 21, 2, 1, 40)
                },
                new TrackRecord
                {
                    StartDate = new DateTime(2014, 8, 22, 2, 0, 40),
                    EndDate   = new DateTime(2014, 8, 22, 2, 1, 40)
                },
                new TrackRecord
                {
                    StartDate = new DateTime(2014, 8, 23, 2, 0, 40),
                    EndDate   = new DateTime(2014, 8, 23, 2, 1, 40)
                },
                new TrackRecord
                {
                    StartDate = new DateTime(2014, 8, 24, 2, 0, 40),
                    EndDate   = new DateTime(2014, 8, 24, 2, 1, 40)
                }
            };

            //act

            var result = StatsCalculator.CalculateStats(input, new DateTime(2014, 8, 18), new DateTime(2014, 8, 25));

            //assert
            Assert.AreEqual(400, result);
        }
Esempio n. 2
0
        static void Main()
        {
            //Main program
            string[] ContinueOptions = new string[] { "Y", "N" };
            bool     ContinueProgram = true;

            while (ContinueProgram)
            {
                bool   FileNameValid = false;
                string FileName      = "";
                while (!FileNameValid)
                {
                    System.Console.Write("Enter a filename: ");
                    FileName = System.Console.ReadLine();
                    if (FileHandler.FileExists(FileName))
                    {
                        break;
                    }
                    System.Console.WriteLine("Invalid filename");
                }
                string[] FileContents = FileHandler.ReadFileToArray(FileName);
                double[] Values       = new double[0];
                //For every line from the file, check it is a double and if so, expand the double array and put it in
                foreach (string Line in FileContents)
                {
                    if (IsDouble(Line))
                    {
                        System.Array.Resize <double>(ref Values, Values.Length + 1);
                        Values[Values.Length - 1] = double.Parse(Line);
                    }
                }
                string Output = "No usable data";
                //Only work on arrays with something in
                if (Values.Length > 0)
                {
                    Output = "-----" + FileName + "-----\n\n" + "Mean: " + StatsCalculator.CalculateMean(Values).ToString() + "\nStandard Deivation: " +
                             StatsCalculator.CalculateStdDev(Values).ToString() + "\nStandard Error: " + StatsCalculator.CalculateStdErr(Values).ToString();
                }
                System.Console.WriteLine(Output);
                string ContinueChoice = TakeStringInput(ContinueOptions, "Restart program? (Y/N): ");
                if (ContinueChoice.ToLower() == "n")
                {
                    ContinueProgram = true;
                }
                System.Console.Clear();
            }
        }
        private void updateProfitsPerMonth()
        {
            ProfitsPerMonth = StatsCalculator.GetProfitsByMonths(Profits, Data);

            double sum   = 0;
            int    n     = 0;
            var    means = new List <double>();

            foreach (var p in ProfitsPerMonth)
            {
                sum += p.Percent;
                n++;
                means.Add(Math.Round(sum / n, 2));
            }

            MeanProfitsPerMonth = means;
        }
Esempio n. 4
0
        public void MonthStats_ProvidedRecordsEachMonthDayWithTotal1860Secs_Returns1860SecsAsField()
        {
            var inputList = new List <TrackRecord>();

            for (int i = 0; i < 31; i++)
            {
                inputList.Add(new TrackRecord
                {
                    StartDate = new DateTime(2014, 8, i + 1, 2, 0, 40),
                    EndDate   = new DateTime(2014, 8, i + 1, 2, 1, 40)
                });
            }
            //act

            var result = StatsCalculator.CalculateStats(inputList, new DateTime(2014, 8, 1), new DateTime(2014, 9, 1));

            //assert
            Assert.AreEqual(1860, result);
        }
Esempio n. 5
0
        public void WeekStats_ProvidedTodaysRecordsWithTotal100Secs_Returns100SecsAsField()
        {
            //arrange
            var input = new[] { new TrackRecord
                                {
                                    StartDate = new DateTime(2014, 8, 19, 1, 0, 0),
                                    EndDate   = new DateTime(2014, 8, 19, 1, 0, 40)
                                },
                                new TrackRecord
                                {
                                    StartDate = new DateTime(2014, 8, 19, 2, 0, 40),
                                    EndDate   = new DateTime(2014, 8, 19, 2, 1, 40)
                                } };

            //act

            var result = StatsCalculator.CalculateStats(input, new DateTime(2014, 8, 18), new DateTime(2014, 8, 25));

            //assert
            Assert.AreEqual(100, result);
        }
Esempio n. 6
0
        public void DayStats_ProvidedTodaysRecordsWithTotal100SecsForTodayAndLastEndsNextDay_Returns100SecsAsField()
        {
            //arrange
            var input = new[] { new TrackRecord
                                {
                                    StartDate = new DateTime(2014, 8, 18, 23, 54, 00),
                                    EndDate   = new DateTime(2014, 8, 19, 0, 0, 40)
                                },
                                new TrackRecord
                                {
                                    StartDate = new DateTime(2014, 8, 19, 23, 59, 0),
                                    EndDate   = new DateTime(2014, 8, 20, 2, 1, 40)
                                } };

            //act

            var result = StatsCalculator.CalculateStats(input, new DateTime(2014, 8, 19), new DateTime(2014, 8, 20));

            //assert
            Assert.AreEqual(100, result);
        }
Esempio n. 7
0
        public void WeekStats_ProvidedRecordsDifferentDaysLastEndNextWeekWithTotalForWeek100Secs_Returns100SecsAsField()
        {
            //arrange
            var input = new[] { new TrackRecord
                                {
                                    StartDate = new DateTime(2014, 8, 18, 0, 1, 0),
                                    EndDate   = new DateTime(2014, 8, 18, 0, 1, 40)
                                },
                                new TrackRecord
                                {
                                    StartDate = new DateTime(2014, 8, 24, 23, 59, 00),
                                    EndDate   = new DateTime(2014, 8, 25, 2, 1, 40)
                                } };

            //act

            var result = StatsCalculator.CalculateStats(input, new DateTime(2014, 8, 18), new DateTime(2014, 8, 25));

            //assert
            Assert.AreEqual(100, result);
        }
 private double calculateSharpeRatio()
 {
     return(StatsCalculator.CalculateSharpeRatio(Data, Flows, RISK_FREE_RATE));
 }
 private void updateDollarBHs(IEnumerable <Rate> ratesUSD)
 {
     DollarBHs = StatsCalculator.GetDollarBHs(ratesUSD, Profits, Flows);
 }
 private void updateSavingsPerMonth()
 {
     Savings = StatsCalculator.GetSavingsPerMonth(Data, Flows, RISK_FREE_RATE);
 }
Esempio n. 11
0
 /// <summary>Constructor</summary>
 public Main()
 {
     Calculator         = new StatsCalculator();
     averageIrises      = new List <Iris>();
     euclideanDistances = new Dictionary <List <string>, double>();
 }
Esempio n. 12
0
 public static IPokemonStats CreateStats(IPokemonStats pokemonBaseStats, int level)
 {
     return(StatsCalculator.GetCalculatedStats(pokemonBaseStats, level));
 }
Esempio n. 13
0
        public AccountData(User user,
                           IEnumerable <BalancesRow> balances,
                           IEnumerable <FlowRow> flows)
        {
            UserName = user.Name;
            Flows    = flows.Where(o => o.User.Id == user.Id).ToArray();
            var startDate = Flows.Min(o => o.DateTimeStamp);

            var ratios = new Dictionary <DateTime, double>();
            var dbs    = balances.OrderBy(o => o.DateTimeStamp).ToDictionary(o => o.DateTimeStamp, o => o.Balance);

            Balances = new Dictionary <DateTime, double>();

            double   ownMoney    = 0;
            double   othersMoney = 0;
            DateTime date        = DateTime.MinValue;

            foreach (var d in dbs.Keys)
            {
                var currFlows = flows.Where(o => o.DateTimeStamp <= d && o.DateTimeStamp > date);
                var currBal   = dbs[d] - currFlows.Sum(o => o.Payment);
                var profit    = d == dbs.Min(o => o.Key) ? 0 : currBal - (othersMoney + ownMoney);
                var currRatio = d == dbs.Min(o => o.Key) ? 0 : ownMoney / (othersMoney + ownMoney);
                ownMoney    += profit * currRatio;
                othersMoney += profit * (1 - currRatio);

                foreach (var f in currFlows)
                {
                    if (f.User.Id == user.Id)
                    {
                        ownMoney += f.Payment;
                    }
                    else
                    {
                        othersMoney += f.Payment;
                    }
                }
                ratios.Add(d, ownMoney / (othersMoney + ownMoney));
                if (startDate <= d)
                {
                    Balances.Add(d, ownMoney);
                }
                date = d;
            }

            var ownFlowsSum = Flows.Where(o => o.Payment > 0).Sum(o => o.Payment);

            SharedRatio = Math.Round(ratios[balances.Last().DateTimeStamp] * 100, 2);
            Money       = Math.Round(ownMoney, 2);
            OthersMoney = Math.Round(othersMoney, 2);

            var lastMonthBalance = dbs.LastOrDefault(o => o.Key < date && o.Key.Month != date.Month);
            var lastMonthInOut   = Flows.Where(o => o.DateTimeStamp > lastMonthBalance.Key).Sum(o => o.Payment);

            TotalProfit = Math.Round(Money - ownFlowsSum, 2);
            if (TotalProfit > 0)
            {
                Money -= Math.Round(TotalProfit * (Benefit / 100), 2);
            }

            TotalProfitPercent = Math.Round(100 * TotalProfit / ownFlowsSum, 2);

            ProfitsPerMonth = StatsCalculator.GetProfitsByMonths(StatsCalculator.GetProfits(Balances, Flows), Balances);

            var lastMonthProfit = ProfitsPerMonth.Last();

            LastMonthProfit  = Math.Round(lastMonthProfit.Value * (1 - Benefit / 100), 2);
            LastMonthPercent = Math.Round(lastMonthProfit.Percent * (1 - Benefit / 100), 2);
        }