/// <summary> /// Calculates Mandates of perticular postion, considering position code should match with instrument code of fundsofmandate data /// if position code doesn't match with any of instrument code then do nothing. /// </summary> /// <param name="positionCode">The position code.</param> /// <param name="positionValue">The position value.</param> /// <param name="fundsOfMandatesData">List of fundsofmandate</param> /// <returns>returns list of mandateVM</returns> public List <MandateVM> CalculateMandate(string positionCode, decimal positionValue, FundsOfMandatesData fundsOfMandatesData) { List <MandateVM> mandates = new List <MandateVM>(); foreach (var fundOfMandates in fundsOfMandatesData?.FundsOfMandates) { if (fundOfMandates.InstrumentCode.Equals(positionCode)) { decimal liqudityAllocation = 1; decimal liquidityValue = positionValue; foreach (var mandate in fundOfMandates.Mandates) { mandates.Add(new MandateVM() { Name = mandate.MandateName, Allocation = mandate.Allocation / 100, Value = Math.Round((mandate.Allocation * positionValue) / 100) }); liqudityAllocation = liqudityAllocation - mandate.Allocation / 100; liquidityValue = liquidityValue - Math.Round((mandate.Allocation * positionValue) / 100); } if (fundOfMandates.LiquidityAllocation > 0) { MandateVM liquidityMandateVM = new MandateVM() { Allocation = liqudityAllocation, Name = "Liquidity", Value = liquidityValue }; mandates.Add(liquidityMandateVM); } } } return(mandates); }
public async Task <PositionVM> GetCalculatedMandates(PositionVM posObj, FundOfMandates fundobj) { try { if (posObj.Code == fundobj.InstrumentCode) { List <MandateVM> MandateListObj = new List <MandateVM>(); foreach (var mandate in fundobj.Mandates) { MandateVM MandateObj = new MandateVM(); MandateObj.Name = mandate.MandateName; MandateObj.Allocation = mandate.Allocation; MandateObj.Value = Math.Round(posObj.Value * (mandate.Allocation / 100)); MandateListObj.Add(MandateObj); } posObj.Mandates = MandateListObj; if (fundobj.LiquidityAllocation > 0) { MandateVM Liquidity = new MandateVM(); Liquidity.Name = "Liquidity"; Liquidity.Allocation = fundobj.LiquidityAllocation; Liquidity.Value = Math.Round((posObj.Value - MandateListObj.Select(x => x.Value).Sum()) * (fundobj.LiquidityAllocation)); MandateListObj.Add(Liquidity); } } return(await Task.Run(() => { return posObj; })); } catch (Exception ex) { throw new Exception(ex.ToString()); } }
/// <summary> /// Get Calculated Mandates /// </summary> /// <param name="portfolioVM"></param> /// <param name="fundsOfMandates"></param> /// <returns></returns> public List <PositionVM> GetCalculatedMandates(PortfolioVM portfolioVM, List <FundOfMandates> fundsOfMandates) { portfolioVM.Positions.ForEach(position => { FundOfMandates fund = fundsOfMandates.Where(funds => funds.InstrumentCode == position.Code).FirstOrDefault(); if (fund != null) { position.Mandates = new List <MandateVM>(); fund.Mandates.ToList().ForEach(mandate => { MandateVM mandateVM = new MandateVM(); mandateVM.Name = mandate.MandateName; mandateVM.Allocation = (mandate.Allocation / 100); mandateVM.Value = (mandate.Allocation / 100) * position.Value; position.Mandates.Add(mandateVM); }); if (fund.LiquidityAllocation > 0) { position.Mandates.Add(new MandateVM { Name = "Liquidity", Allocation = (fund.LiquidityAllocation / 100), Value = (fund.LiquidityAllocation / 100) * position.Value }); } } }); return(portfolioVM.Positions); }
/// <summary> ///Method to calculate the Mandates position under the fundofmandates /// </summary> /// <param name="position"></param> /// <param name="fundOfmandates"></param> /// <returns></returns> public PositionVM GetCalculatedMandates(PositionVM position, FundOfMandates fundOfmandates) { try { if (position.Code == fundOfmandates.InstrumentCode && fundOfmandates.Mandates != null && fundOfmandates.Mandates.Length > 0) { position.Mandates = new List <MandateVM>(); position.Mandates.AddRange ( fundOfmandates.Mandates.ToList().Select(x => new MandateVM { Allocation = x.Allocation / 100, Name = x.MandateName, Value = Math.Round((position.Value * x.Allocation) / 100) }) ); if (fundOfmandates.LiquidityAllocation > 0) { var newMandate = new MandateVM { Allocation = fundOfmandates.LiquidityAllocation / 100, Name = "Liquidity", Value = Math.Round((position.Value * fundOfmandates.LiquidityAllocation) / 100), }; position.Mandates.Add(newMandate); } } return(position); } catch (Exception ex) { throw ex; } }