public void Evaluate() { var purchases = BuyBusiness.ListPendingEscrowResult(); foreach (var purchase in purchases) { try { var history = PortfolioHistoryBusiness.ListHistory(purchase.PortfolioId); if (history.Max(c => c.Date) < purchase.ExpirationDate.Value) { continue; } var projection = ProjectionBusiness.Get(purchase.ProjectionId); var dailyEstimatedPercentage = Util.Util.ConvertMonthlyToDailyRate(projection.ProjectionValue); var estimatedPercentage = Math.Pow(1.0 + dailyEstimatedPercentage, purchase.Days) - 1.0; var startDate = purchase.ExpirationDate.Value.AddDays(-purchase.Days); if (startDate < history.Min(c => c.Date)) { startDate = history.Min(c => c.Date); } var historyOfPeriod = history.Where(c => c.Date >= startDate && c.Date <= purchase.ExpirationDate.Value); var historyResult = PortfolioHistoryBusiness.GetHistoryResult(historyOfPeriod); var performedPercentage = historyResult.Value / 100.0; decimal buyerTokenAmount = 0, ownerTokenAmount = 0; if (estimatedPercentage > performedPercentage) { buyerTokenAmount = purchase.Price; } else { ownerTokenAmount = purchase.Price; } using (var transaction = new TransactionalDapperCommand()) { var escrowResult = new EscrowResult() { BuyId = purchase.Id, CreationDate = DateTime.UtcNow, BuyerTokenResult = buyerTokenAmount, OwnerTokenResult = ownerTokenAmount }; transaction.Insert(escrowResult); var trans = TransactionBusiness.SetNew(purchase.UserId); transaction.Insert(trans); var escrowResultTrans = EscrowResultTransactionBusiness.SetNew(escrowResult.Id, trans.Id); transaction.Insert(escrowResultTrans); transaction.Commit(); } } catch (Exception ex) { Logger.LogCritical(ex, $"Error on evaluate purchase {purchase.Id}"); } } }
public Projection CreateProjection(string email, int portfolioId, double projection, int risk, double?optimisticProjection, double?pessimisticProjection, Dictionary <int, double> distribution) { return(ProjectionBusiness.Create(email, portfolioId, projection, RiskType.Get(risk), optimisticProjection, pessimisticProjection, distribution)); }