Exemplo n.º 1
0
        private static List <AccountStats> AddAcountStatsForExistingUsers(List <TradeRecord> trades, int accountNumber, int leverage, ObjectId datasourceId, List <AccountStats> accountStats)
        {
            //try
            //{
            var dailyNavs   = unitOfWork.DailyEquityRepository.GetAll().Where(x => x.AccountNumber == accountNumber).FirstOrDefault();
            var datasource  = _eLTService.getDatasourceById(datasourceId);
            var timelineIds = GetTimelinesForExistingUser();

            foreach (int timeline in timelineIds)
            {
                var existingAccountStats = accountStats.Where(x => x.TimeLineId == timeline).FirstOrDefault();
                existingAccountStats.StatringBalance = AccountStatsCalculations.GetStartingBalanceByTimeline((int)timeline, dailyNavs, trades);
                existingAccountStats.Deposit         = AccountStatsCalculations.GetDepositsByTimeline((int)timeline, dailyNavs, trades);
                existingAccountStats.Withdrawn       = AccountStatsCalculations.GetWithdrawnByTimeline((int)timeline, dailyNavs, trades);
                existingAccountStats.ProfitLoss      = AccountStatsCalculations.GetProfitLossByTimeline((int)timeline, dailyNavs, trades);
                existingAccountStats.BestPL          = AccountStatsCalculations.CalculateBestPLForTimeline((int)timeline, trades);
                existingAccountStats.CreatedOn       = DateTime.UtcNow.ToString();
                existingAccountStats.DD         = dailyNavs == null ? 0 : AccountStatsCalculations.CalculateDDForTimeline((int)timeline, dailyNavs, trades);
                existingAccountStats.NAV        = dailyNavs == null ? 0 : AccountStatsCalculations.CalculateNavForTimeline((int)timeline, dailyNavs); //Math.Round(dailyNavs.NAVByDate[dailyNavs.NAVByDate.Count - 1].NAV, 2);
                existingAccountStats.ROI        = dailyNavs == null ? 0 : AccountStatsCalculations.CalculateROIForTimeline((int)timeline, dailyNavs, trades);
                existingAccountStats.SharpRatio = dailyNavs == null ? 0 : AccountStatsCalculations.CalculateSharpRatioForTimeline((int)timeline, dailyNavs, datasourceId, datasource, trades);
                existingAccountStats.AvgTrade   = dailyNavs == null ? 0 : AccountStatsCalculations.CalculateAvgTradesForTimeline((int)timeline, trades);
                existingAccountStats.WINRate    = AccountStatsCalculations.CalculateWINForTimeline((int)timeline, trades);
                existingAccountStats.WorstPL    = AccountStatsCalculations.CalculateWorstPLForTimeline((int)timeline, trades);
            }
            return(accountStats);
            //}
            //catch (Exception ex)
            //{
            //    throw;
            //}
        }
Exemplo n.º 2
0
        public static List <AccountStats> AddAcountStats(List <TradeRecord> trades, int accountNumber, int leverage, ObjectId datasourceId)
        {
            //try
            //{
            var dailyNavs        = unitOfWork.DailyEquityRepository.GetAll().Where(x => x.AccountNumber == accountNumber).FirstOrDefault();
            var AccountStatsList = new List <AccountStats>();
            var datasource       = _eLTService.getDatasourceById(datasourceId);

            foreach (TimeLineEnum timeline in Enum.GetValues(typeof(TimeLineEnum)))
            {
                if ((int)timeline == 45)
                {
                }
                AccountStats accountStats = new AccountStats();
                accountStats.AccountId       = timeline;
                accountStats.StatringBalance = AccountStatsCalculations.GetStartingBalanceByTimeline((int)timeline, dailyNavs, trades);
                accountStats.Deposit         = AccountStatsCalculations.GetDepositsByTimeline((int)timeline, dailyNavs, trades);
                accountStats.Withdrawn       = AccountStatsCalculations.GetWithdrawnByTimeline((int)timeline, dailyNavs, trades);
                accountStats.ProfitLoss      = AccountStatsCalculations.GetProfitLossByTimeline((int)timeline, dailyNavs, trades);
                accountStats.BestPL          = AccountStatsCalculations.CalculateBestPLForTimeline((int)timeline, trades);
                accountStats.CreatedBy       = accountNumber;
                accountStats.Leverage        = leverage;
                accountStats.CreatedOn       = DateTime.UtcNow.ToString();
                accountStats.DD         = dailyNavs == null ? 0 : AccountStatsCalculations.CalculateDDForTimeline((int)timeline, dailyNavs, trades);
                accountStats.NAV        = dailyNavs == null ? 0 : AccountStatsCalculations.CalculateNavForTimeline((int)timeline, dailyNavs); //Math.Round(dailyNavs.NAVByDate[dailyNavs.NAVByDate.Count - 1].NAV, 2);
                accountStats.ROI        = dailyNavs == null ? 0 : AccountStatsCalculations.CalculateROIForTimeline((int)timeline, dailyNavs, trades);
                accountStats.SharpRatio = dailyNavs == null ? 0 : AccountStatsCalculations.CalculateSharpRatioForTimeline((int)timeline, dailyNavs, datasourceId, datasource, trades);
                accountStats.AvgTrade   = dailyNavs == null ? 0 : AccountStatsCalculations.CalculateAvgTradesForTimeline((int)timeline, trades);
                accountStats.Status     = true;
                accountStats.TimeLineId = (int)timeline;
                //accountStats.UpdatedBy = MathCalculations.GenerateRandomNo(2);
                //accountStats.UpdatedOn = GenerateRandomDate();
                accountStats.WINRate = AccountStatsCalculations.CalculateWINForTimeline((int)timeline, trades);
                accountStats.WorstPL = AccountStatsCalculations.CalculateWorstPLForTimeline((int)timeline, trades);
                //_unitOfWork.AccountStatsRepository.Add(accountStats);
                AccountStatsList.Add(accountStats);
            }

            return(AccountStatsList);
            //}
            //catch (Exception ex)
            //{
            //    throw;
            //}
        }