Example #1
0
        /// <summary>
        /// Constructor of ManagementPeriodUnitFee object
        /// </summary>
        /// <param name="calculatedAmount">The (total) value calculated</param>
        /// <param name="prevCalcAmount">The value already charged</param>
        /// <param name="feeType">The type of MgtFee</param>
        public ManagementPeriodUnitFee(IManagementPeriodUnit parent, FeeType feeType, Money amount, IFeeCalcVersion calcSource)
        {
            this.Parent = parent;
            this.FeeType = feeType;
            this.Amount = amount;

            if (calcSource != null)
                calcSourceKey = calcSource.Key;
        }
Example #2
0
        /// <summary>
        /// Calculate kickback on a unit
        /// </summary>
        /// <param name="session">The dal session.</param>
        /// <param name="unit">The unit for which the fee is calculated.</param>
        /// <param name="feeTypeKickBack">FeeType of type KickBack.</param>
        /// <param name="message">returns stuff when fu</param>
        /// <returns></returns>
        public static bool CalculateKickBackOnUnit(IDalSession session, IManagementPeriodUnit unit, FeeType feeTypeKickBack, out string message)
        {
            bool success = false;
            message = "";

            if (unit.Account != null && unit.Account.AccountType == AccountTypes.Customer)
            {
                ICustomerAccount account = (ICustomerAccount)unit.Account;
                if (account.UseKickback)
                {
                    IRemisierHistory remisierHistory = account.CurrentRemisierDetails;
                    if (remisierHistory != null && remisierHistory.KickBack > 0)
                    {
                        if (feeTypeKickBack == null)
                            feeTypeKickBack = (FeeType)session.GetObjectInstance(typeof(FeeType), (int)FeeTypes.KickbackFee);

                        if (unit.AverageHoldings != null && unit.AverageHoldings.Count > 0)
                        {
                            Money totalKickBackFee = null;
                            foreach (IAverageHolding holding in unit.AverageHoldings)
                            {
                                Money avgAmount = holding.AverageValue;
                                if (avgAmount != null && avgAmount.IsNotZero)
                                {
                                    Money kickbackFee = avgAmount * ((remisierHistory.KickBack / 100M) * (unit.Days / 365M) * feeTypeKickBack.FeeTypeSign);

                                    if (kickbackFee != null && kickbackFee.IsNotZero)
                                    {
                                        totalKickBackFee += kickbackFee;
                                        holding.FeeItems.AddFeeItem(feeTypeKickBack, kickbackFee, unit, null, remisierHistory.KickBack);
                                        unit.FeesCalculated = FeesCalculatedStates.Yes;
                                        unit.Message = "";
                                    }
                                }
                            }
                            if (unit.FeesCalculated != FeesCalculatedStates.Yes && (totalKickBackFee == null || totalKickBackFee.IsZero))
                            {
                                unit.FeesCalculated = FeesCalculatedStates.Irrelevant;
                                unit.Message = "Calculated kickback amount is either zero or too small";
                            }
                            success = true;
                        }
                    }
                    else
                        message = "No kickback percentage found";
                }
                else
                {
                    unit.FeesCalculated = FeesCalculatedStates.Irrelevant;
                    success = true;
                }
            }
            return success;
        }
Example #3
0
        /// <summary>
        /// Constructor of AverageHoldingFee object
        /// </summary>
        /// <param name="parent">The holding this fee item belongs to</param>
        /// <param name="unit">The holding this fee item belongs to</param>
        /// <param name="feeType">The type of MgtFee</param>
        /// <param name="calculatedAmount">The (total) value calculated</param>
        /// <param name="prevCalcAmount">The value already charged</param>
        /// <param name="calcSource">The source of the calculation</param>
        /// <param name="feePercentageUsed">The fee Percentage Used in the calculation</param>
        public AverageHoldingFee(IAverageHolding parent, IManagementPeriodUnit unit, FeeType feeType, Money calculatedAmount, Money prevCalcAmount, IFeeCalcVersion calcSource, decimal feePercentageUsed)
        {
            this.Parent = parent;
            this.Unit = unit;
            this.FeeType = feeType;
            this.Amount = calculatedAmount - prevCalcAmount;
            this.CalculatedAmount = calculatedAmount;
            this.FeePercentageUsed = feePercentageUsed;

            if (calcSource != null)
            {
                this.calcSource = calcSource;
                calcSourceKey = calcSource.Key;
            }
        }
Example #4
0
        public IFeeCalcVersion[] FindCalculations(IManagementPeriodUnit unit)
        {
            IFeeCalcVersion[] calculations = null;
            Dictionary<FeeTypes, List<IFeeRule>> rulesDictionary = new Dictionary<FeeTypes, List<IFeeRule>>();

            IModelHistory modelHistory = null;
            if (unit.IsPeriodEnd)
                modelHistory = unit.Account.ModelPortfolioChanges.GetItemByDate(unit.EndDate);
            else
                modelHistory = unit.Account.ModelPortfolioChanges.GetItemByDate(Util.GetLastDayOfMonth(unit.Period));

            if (modelHistory != null && modelHistory.ModelPortfolio != null)
            {
                unit.ModelPortfolio = modelHistory.ModelPortfolio;
                unit.IsExecOnlyCustomer = modelHistory.IsExecOnlyCustomer;
            }

            // First reset the weights back to 0
            foreach (IFeeRule rule in rules) { rule.Weight = 0; }

            // Calculate the weight
            foreach (IFeeRule rule in rules)
            {
                if (rule.CalculateWeight(unit))
                {
                    FeeTypes key = rule.FeeCalculation.FeeType.Key;
                    if (!rulesDictionary.ContainsKey(key))
                        rulesDictionary.Add(key, new List<IFeeRule>());
                    rulesDictionary[key].Add(rule);
                }
            }
            if (rulesDictionary.Count > 0)
            {
                calculations = new IFeeCalcVersion[rulesDictionary.Keys.Count];
                int i = 0;
                foreach (FeeTypes key in rulesDictionary.Keys)
                {
                    rulesDictionary[key].Sort(new FeeRule.MySorter(FeeRule.MySorter.SortOrder.Descending));
                    calculations[i] = rulesDictionary[key][0].FeeCalculation.Versions.GetItemByPeriod(unit.Period);
                    i++;
                }
            }
            return calculations;
        }
Example #5
0
 public override void Calculate(IManagementPeriodUnit unit)
 {
     if (!NoFees && FixedSetup != null && FixedSetup.IsNotZero)
     {
         // If Per Instrument -> loop through avgHoldings
         if (Parent.FeeType.CalcBasis == FeeCalcBasis.Instrument)
         {
             if (unit.AverageHoldings != null && unit.AverageHoldings.Count > 0)
             {
                 foreach (IAverageHolding holding in unit.AverageHoldings)
                 {
                     if (isHoldingIncluded(holding))
                         holding.FeeItems.AddFeeItem(Parent.FeeType, FixedSetupMonthly, unit, this, 0M);
                 }
             }
         }
         else
         {
             // Per Account -> do not call it per holding
             unit.FeeItems.AddFeeItem(Parent.FeeType, FixedSetupMonthly, this);
         }
     }
 }
Example #6
0
 private bool runCalculateFeesForUnit(IDalSession session, FeeFactory feeFactory, IManagementPeriodUnit unit, out string message)
 {
     bool success = false;
     message = "";
     try
     {
         switch (unit.ManagementPeriod.ManagementType)
         {
             case B4F.TotalGiro.Accounts.ManagementPeriods.ManagementTypes.ManagementFee:
                 unit.Success = feeFactory.CalculateFeePerUnit(session, unit);
                 break;
             case B4F.TotalGiro.Accounts.ManagementPeriods.ManagementTypes.KickBack:
                 unit.Success = calculateKickBackOnUnit(session, unit, out message);
                 break;
         }
         if (!string.IsNullOrEmpty(message))
             unit.Message = message;
         success = session.Update(unit);
     }
     catch (Exception ex)
     {
         message = Util.GetMessageFromException(ex);
         string logMessage = string.Format("Error in runCalculateFeesForUnit -> unit: {0}; {1}", unit.Key, message);
         log.Error(logMessage);
     }
     return success;
 }
Example #7
0
 private bool calculateKickBackOnUnit(IDalSession session, IManagementPeriodUnit unit, out string message)
 {
     if (this.feeTypeKickBack == null)
         this.feeTypeKickBack = (FeeType)session.GetObjectInstance(typeof(FeeType), (int)FeeTypes.KickbackFee);
     return FeeFactory.CalculateKickBackOnUnit(session, unit, this.feeTypeKickBack, out message);
 }
Example #8
0
 public void RunCalculateFeesForUnit(IDalSession session, IManagementPeriodUnit unit)
 {
     string message;
     FeeFactory feeFactory = FeeFactory.GetInstance(session, FeeFactoryInstanceTypes.Fee);
     bool success = runCalculateFeesForUnit(session, feeFactory, unit, out message);
     if (!success)
         throw new ApplicationException(message);
 }
Example #9
0
        public override void Calculate(IManagementPeriodUnit unit)
        {
            // If Per Instrument -> loop through avgHoldings
            if (Parent.FeeType.CalcBasis == FeeCalcBasis.Instrument)
            {
                if (unit.AverageHoldings != null && unit.AverageHoldings.Count > 0)
                {
                    foreach (IAverageHolding holding in unit.AverageHoldings)
                    {
                        if (isHoldingIncluded(holding))
                        {
                            Money calcFee = null;
                            Money avgAmount = holding.AverageValue;
                            decimal feePercentageUsed = 0M;

                            if (avgAmount != null && avgAmount.IsNotZero)
                            {
                                if (!avgAmount.Underlying.Equals(Parent.FeeCurrency))
                                    throw new ApplicationException("The average value is not in the same currency as the fee currency");

                                FeeLines.ArrangeLines();

                                foreach (FeeCalcLine line in FeeLines)
                                {
                                    if (line.Envelops(avgAmount))
                                    {
                                        feePercentageUsed = line.FeePercentage;
                                        calcFee = addFixMinMax(line.Calculate(avgAmount, unit.Days));
                                        break;
                                    }
                                }
                            }

                            if (calcFee != null && calcFee.IsNotZero)
                                holding.FeeItems.AddFeeItem(Parent.FeeType, calcFee, unit, this, feePercentageUsed);
                        }
                    }
                }
            }
            else
            {
                // Per Account -> do not call it per holding
                Money fee = addFixMinMax(null);
                if (fee != null && fee.IsNotZero)
                    unit.FeeItems.AddFeeItem(Parent.FeeType, fee, this);
            }
        }
Example #10
0
 public abstract void Calculate(IManagementPeriodUnit unit);
Example #11
0
 /// <summary>
 /// Constructor of AverageHoldingFee object
 /// </summary>
 /// <param name="parent">The holding this fee item belongs to</param>
 /// <param name="unit">The holding this fee item belongs to</param>
 /// <param name="feeType">The type of MgtFee</param>
 /// <param name="calculatedAmount">The (total) value calculated</param>
 /// <param name="calcSource">The source of the calculation</param>
 /// <param name="feePercentageUsed">The fee Percentage Used in the calculation</param>
 public AverageHoldingFee(IAverageHolding parent, IManagementPeriodUnit unit, FeeType feeType, Money calculatedAmount, IFeeCalcVersion calcSource, decimal feePercentageUsed)
     : this(parent, unit, feeType, calculatedAmount, null, calcSource, feePercentageUsed)
 {
 }
Example #12
0
 /// <summary>
 /// Calculate kickback on a unit
 /// </summary>
 /// <param name="session">The dal session.</param>
 /// <param name="unit">The unit for which the fee is calculated.</param>
 /// <param name="feeTypeKickBack">FeeType of type KickBack.</param>
 /// <returns></returns>
 public static bool CalculateKickBackOnUnit(IDalSession session, IManagementPeriodUnit unit)
 {
     string message;
     return CalculateKickBackOnUnit(session, unit, null, out message);
 }
Example #13
0
        /// <summary>
        /// The method used to calculate the fees
        /// </summary>
        /// <param name="session">The dal session.</param>
        /// <param name="unit">The unit for which the fee is calculated.</param>
        /// <returns>The MgtFee value.</returns>
        public bool CalculateFeePerUnit(IDalSession session, IManagementPeriodUnit unit)
        {
            bool result = false;

            if (feeRuleFinder == null)
                throw new ApplicationException("No fee rules instantiated.");

            if (unit.IsRelevantForFees)
            {
                if (unit.TotalValue != null && unit.TotalValue.IsNotZero)
                {
                    if (unit.ManagementFee != null && (unit.ManagementFee.IsStorno || unit.ManagementFee.StornoBooking != null))
                        unit.IsStornoed = true;

                    if (!(unit.ManagementFee == null || (unit.ManagementFee != null && (unit.ManagementFee.IsStorno || unit.ManagementFee.StornoBooking != null))))
                        throw new ApplicationException(string.Format("The unit {0} has already been calculated.", unit.Key.ToString()));

                    if (unit.AverageHoldings != null && unit.AverageHoldings.Count > 0)
                    {
                        // Get the CountDocumentsByPost for the unit
                        long count = session.Session.GetNamedQuery(
                            "B4F.TotalGiro.Reports.Documents.CountDocumentsSentByPost")
                            .SetInt32("accountId", unit.Account.Key)
                            .SetInt32("reportStatusId", (int)ReportStatuses.PrintSuccess)
                            .SetDateTime("startDate", unit.StartDate)
                            .SetDateTime("endDate", unit.EndDate.AddDays(1))
                            .UniqueResult<long>();
                        unit.DocumentsSentByPost = Convert.ToInt32(count);

                        // Get relevant Calculation Versions using Rules for the unit
                        IFeeCalcVersion[] calculations = feeRuleFinder.FindCalculations(unit);

                        if (calculations != null && calculations.Length > 0)
                        {
                            unit.RulesFound = calculations.Length;
                            // Loop through Calculations
                            foreach (FeeCalcVersion calc in calculations)
                                calc.Calculate(unit);
                            unit.FeesCalculated = FeesCalculatedStates.Yes;
                            result = true;
                        }
                        else
                        {
                            unit.RulesFound = 0;
                            unit.FeesCalculated = FeesCalculatedStates.Irrelevant;
                            unit.Message = "No fee rules matched";
                            result = true;
                        }
                    }
                }
                else
                {
                    unit.FeesCalculated = FeesCalculatedStates.Irrelevant;
                    unit.Message = "Total Value is 0 so fee will be 0 as well";
                    result = true;
                }
            }
            else
            {
                unit.FeesCalculated = FeesCalculatedStates.Irrelevant;
                result = true;
            }
            return result;
        }
Example #14
0
 public UnitFeePerPeriod(UnitFeeOverview parent, IManagementPeriodUnit unit)
 {
     this.Parent = parent;
     this.ModelPortfolio = unit.ModelPortfolio;
     this.Period = unit.Period;
     this.TotalValue = unit.TotalValue;
     this.IsStornoed = unit.IsStornoed;
     this.FeesCalculated = unit.FeesCalculated;
     this.Success = unit.Success;
     this.unitMessage = unit.Message;
     if (unit.ManagementFee != null)
         this.TradeID = unit.ManagementFee.Key;
     this.Unit = unit;
 }