public void TradeDateEvent(PostingEngineEnvironment env, Transaction element) { if (element.AccrualId == null) { // We have just cash here so what do we do ? CommonRules.GenerateTradeDateJournals(env, element); return; } var accrual = env.Accruals.ContainsKey(element.AccrualId) ? env.Accruals[element.AccrualId] : null; if (accrual != null) { AccrualPayment(env, element, accrual); return; } return; }
internal void TradeDateEvent(PostingEngineEnvironment env, Transaction element) { double multiplier = 1.0; if (env.SecurityDetails.ContainsKey(element.BloombergCode)) { multiplier = env.SecurityDetails[element.BloombergCode].Multiplier; } double fxrate = 1.0; // Lets get fx rate if needed if (!element.SettleCurrency.Equals(env.BaseCurrency)) { fxrate = Convert.ToDouble(FxRates.Find(env.ValueDate, element.SettleCurrency).Rate); } if (element.IsCredit() || element.IsDebit()) { if (element.TransactionCategory == "Cash Dividends") { // We have a Cash Dividend, so how do we treat this return; } } if (element.IsBuy() || element.IsShort()) { if (element.Quantity == 0) { // TODO: Need to review this as we need to see if there is a parent, and what the parents actuall is return; } var tl = env.GenerateOpenTaxLot(element, fxrate); } else if (element.IsSell() || element.IsCover()) { // Get Matching Lots var taxLotMethodology = ConfigurationManager.AppSettings["TaxMethod"].ToString(); var workingQuantity = element.Quantity; if (taxLotMethodology.Equals("MINTAX")) { while (workingQuantity != 0.0) { var localOpenTaxLots = env.Methodology.GetOpenLots(env, element, workingQuantity); var lot = localOpenTaxLots[0]; if (!env.TaxLotStatus.ContainsKey(lot.Trade.LpOrderId)) { // TODO: For this open lot there should be a corresponding open to env.AddMessage($"Unable to Find Tax Lot for {lot.Trade.Symbol}::{lot.Trade.Side}::{lot.Trade.Status}"); //Logger.Warn($"Unable to Find Tax Lot for {element.Symbol}::{element.Side}::{element.Status}"); continue; } var taxlotStatus = env.TaxLotStatus[lot.Trade.LpOrderId]; if (taxlotStatus != null && taxlotStatus.Quantity != 0 && !taxlotStatus.Status.ToLowerInvariant().Equals("closed")) { Logger.Info($"Relieving Tax Lot {taxlotStatus.Symbol}::{taxlotStatus.TradePrice}::{taxlotStatus.TradeDate.ToString("MM-dd-yyyy")}::{taxlotStatus.OpenId}::{lot.TaxLiability}::{lot.TaxRate.Rate}::{lot.PotentialPnl}"); // Does the open Lot fully fullfill the quantity ? if (Math.Abs(taxlotStatus.Quantity) >= Math.Abs(workingQuantity)) { // Lets generate all the journal entries we need GenerateJournals(env, lot, taxlotStatus, element, workingQuantity, fxrate, multiplier); break; } else { var quantity = taxlotStatus.Quantity; GenerateJournals(env, lot, taxlotStatus, element, taxlotStatus.Quantity * -1, fxrate, multiplier); workingQuantity += quantity; } } } } else { var openLots = env.Methodology.GetOpenLots(env, element, workingQuantity); foreach (var lot in openLots) { if (workingQuantity == 0) { break; } if (!env.TaxLotStatus.ContainsKey(lot.Trade.LpOrderId)) { // TODO: For this open lot there should be a corresponding open to env.AddMessage($"Unable to Find Tax Lot for {lot.Trade.Symbol}::{lot.Trade.Side}::{lot.Trade.Status}"); //Logger.Warn($"Unable to Find Tax Lot for {element.Symbol}::{element.Side}::{element.Status}"); continue; } var taxlotStatus = env.TaxLotStatus[lot.Trade.LpOrderId]; if (taxlotStatus != null && taxlotStatus.Quantity != 0 && !taxlotStatus.Status.ToLowerInvariant().Equals("closed")) { Logger.Info($"Relieving Tax Lot {taxlotStatus.TradeDate.ToString("MM-dd-yyyy")}::{taxlotStatus.Symbol}::{taxlotStatus.OpenId}::{lot.TaxLiability}::{lot.TaxRate.Rate}::{lot.PotentialPnl}"); // Does the open Lot fully fullfill the quantity ? if (Math.Abs(taxlotStatus.Quantity) >= Math.Abs(workingQuantity)) { // Lets generate all the journal entries we need GenerateJournals(env, lot, taxlotStatus, element, workingQuantity, fxrate, multiplier); break; } else { var quantity = taxlotStatus.Quantity; GenerateJournals(env, lot, taxlotStatus, element, taxlotStatus.Quantity * -1, fxrate, multiplier); workingQuantity += quantity; } } } } } else { // We have a Debit / Credit Dividends } CommonRules.GenerateTradeDateJournals(env, element); }