public void TradeDateEvent(PostingEngineEnvironment env, Transaction element) { var accrual = env.FindAccruals(element.AccrualId); var allocations = env.FindAllocations(element.AccrualId); var allocation = allocations.Where(i => !i.Symbol.Equals(element.Symbol)).FirstOrDefault(); //Console.WriteLine(element.Symbol); if (element.Symbol.Equals("ZZ_INVESTOR_CONTRIBUTIONS")) { } if (element.Status.Equals("Cancelled")) { env.AddMessage($"Entry has been cancelled {element.LpOrderId} :: {element.Side}"); return; } // Need to consider both if (element.TradeDate.Date != element.SettleDate.Date) { env.AddMessage($"Journal needs to be checked {element.LpOrderId}, {element.TradeDate}, {element.SettleDate}"); return; } var accountToFrom = GetFromToAccount(element); if (accountToFrom.To == null) { env.AddMessage($"Unable to identify From/To accounts for trade {element.OrderSource} :: {element.Side}"); return; } new AccountUtils().SaveAccountDetails(env, accountToFrom.From); new AccountUtils().SaveAccountDetails(env, accountToFrom.To); double fxrate = 1.0; if (!element.SettleCurrency.Equals(env.BaseCurrency)) { fxrate = Convert.ToDouble(FxRates.Find(env.ValueDate, element.SettleCurrency).Rate); } var moneyUSD = element.LocalNetNotional * fxrate; if (element.LocalNetNotional != 0.0) { var symbol = allocation != null ? allocation.Symbol : element.ParentSymbol; var securityId = allocation != null ? allocation.SecurityId : element.SecurityId; if (symbol == null) { symbol = element.Symbol; } var debit = new Journal(element) { Symbol = symbol, SecurityId = securityId, Account = accountToFrom.From, When = env.ValueDate, FxRate = fxrate, CreditDebit = env.DebitOrCredit(accountToFrom.From, moneyUSD), Value = moneyUSD, Event = Event.JOURNAL, Fund = env.GetFund(element), }; var credit = new Journal(element) { Symbol = symbol, SecurityId = securityId, Account = accountToFrom.To, When = env.ValueDate, FxRate = fxrate, CreditDebit = env.DebitOrCredit(accountToFrom.To, moneyUSD), Value = moneyUSD, Event = Event.JOURNAL, Fund = env.GetFund(element), }; env.Journals.Add(debit); env.Journals.Add(credit); } return; }
public void SettlementDateEvent(PostingEngineEnvironment env, Transaction element) { var accrual = env.FindAccruals(element.AccrualId); var allocations = env.FindAllocations(element.AccrualId); var allocation = allocations.Where(i => !i.Symbol.Equals(element.Symbol)).FirstOrDefault(); if (element.Status.Equals("Cancelled")) { env.AddMessage($"Entry has been cancelled {element.LpOrderId} :: {element.Side}"); return; } // If they are the same we need to do nothing if (element.TradeDate.Date == element.SettleDate.Date) { //env.AddMessage($"Journal needs to be checked {element.LpOrderId}, {element.TradeDate}, {element.SettleDate}"); return; } var accountToFrom = GetSettlementFromToAccount(element); if (accountToFrom.To == null) { env.AddMessage($"Unable to identify From/To accounts for trade {element.OrderSource} :: {element.Side}"); return; } new AccountUtils().SaveAccountDetails(env, accountToFrom.From); new AccountUtils().SaveAccountDetails(env, accountToFrom.To); double fxrate = 1.0; if (!element.SettleCurrency.Equals(env.BaseCurrency)) { fxrate = Convert.ToDouble(FxRates.Find(env.ValueDate, element.SettleCurrency).Rate); } var moneyUSD = element.LocalNetNotional * fxrate; if (element.LocalNetNotional != 0.0) { var symbol = allocation != null ? allocation.Symbol : element.ParentSymbol; var securityId = allocation != null ? allocation.SecurityId : element.SecurityId; if (symbol == null) { symbol = element.Symbol; } var debit = new Journal(accountToFrom.From, "journal", env.ValueDate) { Symbol = symbol, SecurityId = allocation != null ? allocation.SecurityId : element.SecurityId, Source = element.LpOrderId, Quantity = element.Quantity, FxCurrency = element.SettleCurrency, FxRate = fxrate, CreditDebit = env.DebitOrCredit(accountToFrom.From, moneyUSD), Value = moneyUSD, Fund = env.GetFund(element), }; var credit = new Journal(accountToFrom.To, "journal", env.ValueDate) { Symbol = symbol, SecurityId = allocation != null ? allocation.SecurityId : element.SecurityId, Source = element.LpOrderId, Quantity = element.Quantity, FxCurrency = element.SettleCurrency, FxRate = fxrate, CreditDebit = env.DebitOrCredit(accountToFrom.To, moneyUSD * -1), Value = moneyUSD * -1, Fund = env.GetFund(element), }; env.Journals.Add(debit); env.Journals.Add(credit); } return; }