public void ShouldNotAddLiquidityMandateAsAdditionalMandateinPositionVM()
        {
            IFundsProcessor fundsProcessor = new FundProcessor();

            PositionVM inputPosition = new PositionVM
            {
                Code     = "Pos1",
                Name     = "Position1",
                Value    = 12345,
                Mandates = null
            };

            PositionVM outputPosition = new PositionVM
            {
                Code     = "Pos1",
                Name     = "Position1",
                Value    = 12345,
                Mandates = new List <MandateVM>
                {
                    new MandateVM {
                        Allocation = .105m, name = "Mandate1", Value = 1296
                    },
                    new MandateVM {
                        Allocation = .205m, name = "Mandate2", Value = 2531
                    },
                    new MandateVM {
                        Allocation = .305m, name = "Mandate3", Value = 3765
                    },
                    new MandateVM {
                        Allocation = .109m, name = "Mandate4", Value = 1346
                    }
                }
            };

            FundOfMandates fundOfMandates = new FundOfMandates
            {
                InstrumentCode      = "Pos1",
                InstrumentName      = "FundOfMandates1",
                LiquidityAllocation = 0,
                Mandates            = new Mandate[]
                {
                    new Mandate {
                        Allocation = 10.5m, MandateId = "Mandate1", MandateName = "Mandate1"
                    },
                    new Mandate {
                        Allocation = 20.5m, MandateId = "Mandate2", MandateName = "Mandate2"
                    },
                    new Mandate {
                        Allocation = 30.5m, MandateId = "Mandate3", MandateName = "Mandate3"
                    },
                    new Mandate {
                        Allocation = 10.9m, MandateId = "Mandate4", MandateName = "Mandate4"
                    }
                }
            };


            fundsProcessor.GetCalculatedMandates(inputPosition, fundOfMandates).Should().NotBeNull().And.BeOfType <PositionVM>().And.BeEquivalentTo(outputPosition);
        }
        public void ShouldNotMakeAnyChangesToPositionVMSinceInstrumentCodeDoNotMatch()
        {
            IFundsProcessor fundsProcessor = new FundProcessor();

            PositionVM inputPosition = new PositionVM
            {
                Code     = "Pos1",
                Name     = "Position1",
                Value    = 12345,
                Mandates = null
            };

            PositionVM outputPosition = new PositionVM
            {
                Code     = "Pos1",
                Name     = "Position1",
                Value    = 12345,
                Mandates = null
            };

            FundOfMandates fundOfMandates = new FundOfMandates
            {
                InstrumentCode      = "Pos2",
                InstrumentName      = "FundOfMandates1",
                LiquidityAllocation = 0,
                Mandates            = new Mandate[]
                {
                    new Mandate {
                        Allocation = 10.5m, MandateId = "Mandate1", MandateName = "Mandate1"
                    },
                    new Mandate {
                        Allocation = 20.5m, MandateId = "Mandate2", MandateName = "Mandate2"
                    },
                    new Mandate {
                        Allocation = 30.5m, MandateId = "Mandate3", MandateName = "Mandate3"
                    },
                    new Mandate {
                        Allocation = 10.9m, MandateId = "Mandate4", MandateName = "Mandate4"
                    }
                }
            };


            fundsProcessor.GetCalculatedMandates(inputPosition, fundOfMandates).Should().NotBeNull().And.BeOfType <PositionVM>().And.BeEquivalentTo(outputPosition);
        }
        /// <summary>
        /// THIS METHOD IS USED TO UPDATE POSITION VIEWMODEL TO MAP CORRESPONDING MANDATES WITH IT PRESENT UNDER PASSED FUNDOFMANDATE.
        /// METHOD USE POSITION VIEW MODEL AND FUNDOFMANDATE OBJECTS AND RETURN UPDATED POSITIONVM BACK TO CLIENT.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="fundOfmandates"></param>
        /// <returns></returns>
        public PositionVM GetCalculatedMandates(PositionVM position, FundOfMandates fundOfmandates)
        {
            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
                {
                    name       = x.MandateName,
                    Value      = Math.Round((position.Value * x.Allocation) / 100),
                    Allocation = x.Allocation / 100
                })
                );

                if (fundOfmandates.LiquidityAllocation > 0)
                {
                    var newMandate = new MandateVM
                    {
                        name = "Liquidity",
                        //NOT VERY CLEAR OF THE LOGIC MENTIONED IN THE WORD DOC SHARED WITH EXERCISE. IT SAYS SUBSTRACT FROM POSITION VALUE BUT THE EXAMPLE IN THE DOC SHOWS THAT ITS STRAIGHT POSITION.VALUE * LIQUIDITY ALLOCATION.
                        //SO COMENTING THE BELOW LINE OF CODE AND KEEPING IT SIMPLE BASED ON EXAMPLE
                        //Value = (position.Value - ((position.Value * fundOfmandates.LiquidityAllocation) / 100)),
                        Value      = Math.Round((position.Value * fundOfmandates.LiquidityAllocation) / 100),
                        Allocation = fundOfmandates.LiquidityAllocation / 100
                    };

                    position.Mandates.Add(newMandate);
                }
            }
            else
            {
                //Maybe we can Log something here as needed..
            }

            return(position);
        }
        public void ShouldAddLiquidityMandateAsAdditionalMandateinPositionVM()
        {
            IFundsProcessor fundsProcessor = new FundProcessor();

            PositionVM inputPosition = new PositionVM
            {
                Code     = "Pos1",
                Name     = "Position1",
                Value    = 12345,
                Mandates = null
            };

            PositionVM outputPosition = new PositionVM
            {
                Code     = "Pos1",
                Name     = "Position1",
                Value    = 12345,
                Mandates = new List <MandateVM>
                {
                    new MandateVM {
                        Allocation = .105m, name = "Mandate1", Value = 1296
                    },
                    new MandateVM {
                        Allocation = .205m, name = "Mandate2", Value = 2531
                    },
                    new MandateVM {
                        Allocation = .305m, name = "Mandate3", Value = 3765
                    },
                    new MandateVM {
                        Allocation = .109m, name = "Mandate4", Value = 1346
                    },
                    new MandateVM {
                        Allocation = .025m, name = "Liquidity", Value = 309
                    }
                }
            };

            FundOfMandates fundOfMandates = new FundOfMandates
            {
                InstrumentCode      = "Pos1",
                InstrumentName      = "FundOfMandates1",
                LiquidityAllocation = 2.5m,
                Mandates            = new Mandate[]
                {
                    new Mandate {
                        Allocation = 10.5m, MandateId = "Mandate1", MandateName = "Mandate1"
                    },
                    new Mandate {
                        Allocation = 20.5m, MandateId = "Mandate2", MandateName = "Mandate2"
                    },
                    new Mandate {
                        Allocation = 30.5m, MandateId = "Mandate3", MandateName = "Mandate3"
                    },
                    new Mandate {
                        Allocation = 10.9m, MandateId = "Mandate4", MandateName = "Mandate4"
                    }
                }
            };


            var outputPos = fundsProcessor.GetCalculatedMandates(inputPosition, fundOfMandates);

            outputPos.Should().NotBeNull().And.BeOfType <PositionVM>().And.BeEquivalentTo(outputPosition);
            outputPos.Mandates.Should().HaveCount(5, "Because Liquidity should get added since we pass Liquidity allocation more than 0");
        }
Esempio n. 5
0
        public void ShouldMapMandatesFromFundOfMandatesToMandateVM()
        {
            //GetCalculatedMandates
            IFileProcessing fileProcessing = new FileProcessor();

            PositionVM inputPosition = new PositionVM
            {
                Code     = "",
                Name     = "",
                Value    = 0,
                Mandates = new List <MandateVM>()
                {
                    new MandateVM {
                        Value = 0, name = "", Allocation = 0
                    },
                    new MandateVM {
                        Value = 0, name = "", Allocation = 0
                    },
                    new MandateVM {
                        Value = 0, name = "", Allocation = 0
                    },
                    new MandateVM {
                        Value = 0, name = "", Allocation = 0
                    },
                }
            };

            PositionVM outputPosition = new PositionVM
            {
                Code     = "",
                Name     = "",
                Value    = 0,
                Mandates = new List <MandateVM>()
                {
                    new MandateVM {
                        Value = 0, name = "", Allocation = 0
                    },
                    new MandateVM {
                        Value = 0, name = "", Allocation = 0
                    },
                    new MandateVM {
                        Value = 0, name = "", Allocation = 0
                    },
                    new MandateVM {
                        Value = 0, name = "", Allocation = 0
                    },
                }
            };

            List <Mandate> mandates = new List <Mandate>
            {
                new Mandate {
                    Allocation = 0, MandateId = 1, MandateName = ""
                },
                new Mandate {
                    Allocation = 0, MandateId = 1, MandateName = ""
                },
                new Mandate {
                    Allocation = 0, MandateId = 1, MandateName = ""
                },
                new Mandate {
                    Allocation = 0, MandateId = 1, MandateName = ""
                }
            };

            FundOfMandates fund = new FundOfMandates
            {
                InstrumentCode = "",
                InstrumentName = "",
                LiqAllocation  = 0,
                Mandates       = new Mandates {
                    MandateList = mandates.ToArray()
                }
            };

            //you can add code yourself from here. ie use correct objects -- call the actual method---use Fuuent assertions to check that output from method actually
            //returns correct PositionVM with correct set of mandates..
        }