/// <summary> /// Initializes a new instance of the <see cref="T:B4F.TotalGiro.PortfolioComparer.PortfolioComparer">PortfolioComparer</see> class. /// </summary> /// <param name="setting">The settings used in the portfolio comparer</param> /// <param name="feeFactory">An instance of the <see cref="T:B4F.TotalGiro.Fees.FeeFactory">FeeFactory</see> class</param> public PortfolioComparer(PortfolioCompareSetting setting, IFeeFactory feeFactory) { if (setting == null) throw new ApplicationException("Can not do a Portfolio check without an initialized PortfolioCompareSetting object"); if (setting.Instruction == null || setting.Instruction.Account == null) throw new ApplicationException(string.Format("Not possible to instantiate a comparer class when account is null.")); this.setting = setting; this.feeFactory = feeFactory; if (Account.ModelPortfolio == null) throw new ApplicationException(string.Format("Not possible to compare to model for account {0}: Model is null", Account.DisplayNumberWithName)); }
public void PerformAction(InstructionEngineActions action, IInstruction instruction) { RebalanceResults result; PortfolioCompareAction pfAction; string instructionMessage = ""; string tempMessage = ""; switch (action) { case InstructionEngineActions.PlaceSizeBaseCloseOrders: pfAction = PortfolioCompareAction.CloseOrders; break; case InstructionEngineActions.RunRebalance: pfAction = PortfolioCompareAction.Rebalance; break; case InstructionEngineActions.BuyModel: pfAction = PortfolioCompareAction.BuyModel; break; case InstructionEngineActions.PlaceCashFundOrders: pfAction = PortfolioCompareAction.CashFundOrders; break; case InstructionEngineActions.PlaceFreeUpCashFundOrder: placeCashFundOrder((ICashWithdrawalInstruction)instruction); return; case InstructionEngineActions.CreateFreeUpCashRebalanceInstruction: createRebalanceInstruction((ICashWithdrawalInstruction)instruction); return; case InstructionEngineActions.CreateMoneyTransferOrder: createMoneyTransferOrder((ICashWithdrawalInstruction)instruction); return; case InstructionEngineActions.LiquidatePortfolio: liquidatePortfolio((IClientDepartureInstruction)instruction); return; case InstructionEngineActions.SettleAccount: settleAccount((IClientDepartureInstruction)instruction); return; case InstructionEngineActions.TransferAllCash: transferAllCash((IClientDepartureInstruction)instruction); return; case InstructionEngineActions.TerminateAccount: terminateAccount((IClientDepartureInstruction)instruction); return; default: throw new ApplicationException("Unknown action"); } PortfolioCompareSetting setting = new PortfolioCompareSetting(pfAction, instruction, this.engineParams); PortfolioComparer.PortfolioComparer comparer = new PortfolioComparer.PortfolioComparer(setting, getFeeFactory(FeeFactoryInstanceTypes.Commission)); IList updateableOrders = comparer.CompareToModel(out result); instruction.SetInstructionMessage((int)result); if (updateableOrders != null && updateableOrders.Count > 0) { switch (action) { case InstructionEngineActions.PlaceSizeBaseCloseOrders: instructionMessage = string.Format("{0} sizebased orders were created for instruments that are not in the modelportfolio.", updateableOrders.Count.ToString()); break; case InstructionEngineActions.RunRebalance: case InstructionEngineActions.BuyModel: tempMessage = getNumberofMonetaryOrders(updateableOrders, true); if (tempMessage != "0") tempMessage = string.Format(" and {0} monetary order(s)", tempMessage); else tempMessage = string.Empty; instructionMessage = string.Format("{0} amountbased orders {1} are created during rebalance", getNumberofMonetaryOrders(updateableOrders, false), tempMessage); break; case InstructionEngineActions.PlaceCashFundOrders: instructionMessage = string.Format("{0} cash management fund order(s) were created.", updateableOrders.Count.ToString()); break; } instruction.UpdateableOrders = updateableOrders; instruction.Message = instructionMessage; } }
private bool checkSizeBasedCloseOrders(IInstruction instruction) { if (instruction.InstructionType == InstructionTypes.BuyModel) return false; // Check whether instruments exist in the portfolio that do not exist in the modelportfolio PortfolioCompareSetting setting = new PortfolioCompareSetting(PortfolioCompareAction.CloseOrders, instruction, this.engineParams); PortfolioComparer.PortfolioComparer comparer = new PortfolioComparer.PortfolioComparer(setting, null); return comparer.CheckInstrumentsNotInModel(); }