public void GetPossibleNotionalByIndicatorTest()
        {
            string strategyName = "unittest_position";
            long maxNotional = 1000;

            StrategyManager.Ins().UnRegister(strategyName);
            AgentManager.Ins().Clear();

            STR_KtbSkel factory = new STR_KtbSkel();
            Input_KtbSkel input = new Input_KtbSkel();
            input.MaxNotional = maxNotional;
            input.Spot10yrCode = "KR1035027161";
            input.Future10yrCode = "167FC000";

            Serializer serializer = new Serializer(typeof(Input_KtbSkel));
            String jsonText = serializer.Serialize(input);

            STR_KtbSkel strategy = StrategyBuilder_KtbSkel.CreateStrategy(jsonText, strategyName);
            PrivateObject po = new PrivateObject(strategy);
            STR_KtbSkel_Accessor acc = new STR_KtbSkel_Accessor(po);
            acc.SetAccountOrderLimit();

            ProcessController_KtbSkel controller = acc.Controller;
            ProcessController_KtbSkel_Accessor accController = new ProcessController_KtbSkel_Accessor(
                new PrivateObject(controller));

            ProcessState_Default ps = accController._processState as ProcessState_Default;
            ProcessState_Default_Accessor psAcc = new ProcessState_Default_Accessor(
                new PrivateObject(ps));

            long notional = psAcc.GetPossibleNotionalByIndicator_Out(10F);
            Assert.AreEqual((-500), notional);

            Assert.AreEqual(false, accController.SortedPositionStack.IsFull(10F));

            notional = psAcc.GetPossibleNotionalByIndicator_Out(6F);
            Assert.AreEqual((-100), notional);
            Assert.AreEqual(false, accController.SortedPositionStack.IsFull(6F));

            notional = psAcc.GetPossibleNotionalByIndicator_Out(5F);
            Assert.AreEqual(0, notional);
            Assert.AreEqual(true, accController.SortedPositionStack.IsFull(5F));

            notional = psAcc.GetPossibleNotionalByIndicator_Out(3.0F);
            Assert.AreEqual(200, notional);
            Assert.AreEqual(true, accController.SortedPositionStack.IsFull(3F));

            notional = psAcc.GetPossibleNotionalByIndicator_Out(0F);
            Assert.AreEqual(500, notional);
            Assert.AreEqual(true, accController.SortedPositionStack.IsFull(0F));

            notional = psAcc.GetPossibleNotionalByIndicator_Out(-1F);
            Assert.AreEqual(500, notional);
            Assert.AreEqual(true, accController.SortedPositionStack.IsFull(-1F));
        }
        void Generate()
        {
            Input_KtbSkel input = new Input_KtbSkel();
            input.MaxNotional = 1000;
            input.Spot10yrCode = "KR1035027161";
            input.Future10yrCode = "167FC000";
            Serializer serializer = new Serializer(typeof(Input_KtbSkel));
            String jsonText = serializer.Serialize(input);

            STR_KtbSkel strategy = StrategyBuilder_KtbSkel.CreateStrategy(jsonText, "test ktb skel scenario");
            PrivateObject po = new PrivateObject(strategy);
            _accSTR_KtbSkel = new STR_KtbSkel_Accessor(po);
            _accSTR_KtbSkel.SetAccountOrderLimit();

            _accController = new ProcessController_KtbSkel_Accessor(
                new PrivateObject(_accSTR_KtbSkel.Controller));
        }
        void TestController_Raw(STR_KtbSkel_Accessor acc)
        {
            ProcessController_KtbSkel controller = acc.Controller;
            ProcessController_KtbSkel_Accessor accController = new ProcessController_KtbSkel_Accessor(
                new PrivateObject(controller));

            Assert.AreEqual(accController.DownBoundary, acc._downBoundary);
            Assert.AreEqual(accController.UpBoundary, acc._upBoundary);
            Assert.AreEqual(accController.MaxNotional, acc.MaxNotional);

            TestKtbSkelProcessConstructor_Raw(controller);
        }
        public void TestGetTargetNotional()
        {
            string strategyName = "unittest_position";
            long maxNotional = 1000;

            StrategyManager.Ins().UnRegister(strategyName);
            AgentManager.Ins().Clear();

            STR_KtbSkel factory = new STR_KtbSkel();
            Input_KtbSkel input = new Input_KtbSkel();
            input.MaxNotional = maxNotional;
            input.Spot10yrCode = "KR1035027161";
            input.Future10yrCode = "167FC000";

            Serializer serializer = new Serializer(typeof(Input_KtbSkel));
            String jsonText = serializer.Serialize(input);

            STR_KtbSkel strategy = StrategyBuilder_KtbSkel.CreateStrategy(jsonText, strategyName);
            PrivateObject po = new PrivateObject(strategy);
            STR_KtbSkel_Accessor acc = new STR_KtbSkel_Accessor(po);
            acc.SetAccountOrderLimit();

            ProcessController_KtbSkel controller = acc.Controller;
            ProcessController_KtbSkel_Accessor accController = new ProcessController_KtbSkel_Accessor(
                new PrivateObject(controller));

            ProcessState_Default ps = accController._processState as ProcessState_Default;
            ProcessState_Default_Accessor psAcc = new ProcessState_Default_Accessor(
                new PrivateObject(ps));

            acc._monitorEnter.ReadyBeforeGetIndicator();
            RawMarketData rmdSpot = acc._monitorEnter.SpotRmdThisTurn;
            RawMarketData rmdFuture = acc._monitorEnter.FutureRmdThisTurn;

            {
                rmdSpot.AskCount1 = 20;
                rmdSpot.BidCount1 = 50;
                rmdFuture.AskCount1 = 30;
                rmdFuture.BidCount1 = 40;

                long notional = psAcc.GetTargetNotional_Enter(0, rmdSpot, rmdFuture);
                Assert.AreEqual(0, notional);

                notional = psAcc.GetTargetNotional_Enter(-1, rmdSpot, rmdFuture);
                Assert.AreEqual(0, notional);

                notional = psAcc.GetTargetNotional_Enter(5.11F, rmdSpot, rmdFuture);
                Assert.AreEqual(10, notional);

                notional = psAcc.GetTargetNotional_Enter(10F, rmdSpot, rmdFuture);
                Assert.AreEqual(20, notional);

                rmdSpot.AskCount1 = 100;
                rmdSpot.BidCount1 = 100;

                notional = psAcc.GetTargetNotional_Enter(10F, rmdSpot, rmdFuture);
                Assert.AreEqual(40, notional);
            }

            {
                rmdSpot.AskCount1 = 10;
                rmdSpot.BidCount1 = 20;
                rmdFuture.AskCount1 = 30;
                rmdFuture.BidCount1 = 40;

                double indicator = 0F;

                long notional = psAcc.GetTargetNotional_Out(indicator, 0, rmdSpot, rmdFuture);
                Assert.AreEqual(0, notional);

                notional = psAcc.GetTargetNotional_Out(indicator, -1, rmdSpot, rmdFuture);
                Assert.AreEqual(0, notional);

                notional = psAcc.GetTargetNotional_Out(indicator, 10, rmdSpot, rmdFuture);
                Assert.AreEqual(10, notional);

                notional = psAcc.GetTargetNotional_Out(indicator, 100, rmdSpot, rmdFuture);
                Assert.AreEqual(20, notional);

                rmdSpot.AskCount1 = 100;
                rmdSpot.BidCount1 = 100;

                notional = psAcc.GetTargetNotional_Out(indicator, 100, rmdSpot, rmdFuture);

                // future 수량이 가장 적다.
                Assert.AreEqual(30, notional);

                indicator = 4.91; // 500억이 차 있으므로 10억이 된다.

                notional = psAcc.GetTargetNotional_Out(indicator, 100, rmdSpot, rmdFuture);

                // indicator 수량이 가장 적다.
                Assert.AreEqual(10, notional);

                indicator = 5F;
                notional = psAcc.GetTargetNotional_Out(indicator, 100, rmdSpot, rmdFuture);

                // indicator 수량이 0
                Assert.AreEqual(0, notional);

                indicator = 5.11;

                notional = psAcc.GetTargetNotional_Out(indicator, 100, rmdSpot, rmdFuture);
                // indicator 수량이 0
                Assert.AreEqual(0, notional);
            }
        }