コード例 #1
0
ファイル: InstructionEngine.cs プロジェクト: kiquenet/B4F
        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;
            }
        }