public void TestSortedPositionStack_KtbSkel() { long maxNotional = 100; double downBoundary = 0F; double upBoundary = 10F; String spotCode = KtbSpotUtil.Ins().KtbSpot_10yr.Code; String futureCode = KtbFutureUtil.Ins().KtbFuture_10yr_1.Code; SortedPositionStack_KtbSkel target = new SortedPositionStack_KtbSkel(null, "unittest", spotCode, futureCode, maxNotional, downBoundary, upBoundary); Assert.AreEqual(target.MaxNotional, maxNotional); Assert.AreEqual(target.DownBoundary, downBoundary); Assert.AreEqual(target.UpBoundary, upBoundary); SortedPositionStack_KtbSkel_Accessor acc = new SortedPositionStack_KtbSkel_Accessor( new PrivateObject(target)); // 미만 CheckRateAndNotional(acc, -0.1F, 0.0F, 0, 0); CheckRateAndNotional(acc, -10.0F, 0.0F, 0, 0); // 정상상태 CheckRateAndNotional(acc, 0.0F, 0.0F, 0, 0); CheckRateAndNotional(acc, 1.0F, 0.1F, (long)(maxNotional * 0.1), 0); CheckRateAndNotional(acc, 3.0F, 0.3F, (long)(maxNotional * 0.3), 0); CheckRateAndNotional(acc, 10.0F, 1.0F, maxNotional, 0); // 오버 CheckRateAndNotional(acc, 11.0F, 1.0F, maxNotional, 0); CheckRateAndNotional(acc, 100.0F, 1.0F, maxNotional, 0); CheckRateAndNotional(acc, 0.1F, 0.01F, 0, 0); CheckRateAndNotional(acc, 0.25F, 0.025F, 0, 0); //push pos1 Position_KtbSkel pos1 = new Position_KtbSkel( spotCode, 10, 8889, futureCode, -10, 107.00); acc.Push(pos1); CheckRateAndNotional(acc, 0, 0, 0, 10); //push pos2 Position_KtbSkel pos2 = new Position_KtbSkel( spotCode, 20, 8888, futureCode, -20, 107.00); acc.Push(pos2); CheckRateAndNotional(acc, 0, 0, 0, 30); //push pos3 Position_KtbSkel pos3 = new Position_KtbSkel( spotCode, 30, 8887, futureCode, -30, 107.10); acc.Push(pos3); // pos3가 top CheckRateAndNotional(acc, 0, 0, 0, 60); TestErase_Raw(acc); TestReverseSweeperAfterTakeOverPosition(); }
void TestErase_Raw(SortedPositionStack_KtbSkel_Accessor acc) { Assert.AreEqual(acc._stack.Count, 3); { // 3억에서 1억만 지운다. Position_KtbSkel erase = new Position_KtbSkel( "", -10, 8899, "", 10, 107.0); acc.Erase(erase); CheckRateAndNotional(acc, 0, 0, 0, 50); } Assert.AreEqual(acc._stack.Count, 3); { // 3억을 지운다. Position_KtbSkel erase = new Position_KtbSkel( "", -30, 8899, "", 30, 107.0); acc.Erase(erase); CheckRateAndNotional(acc, 0, 0, 0, 20); } Assert.AreEqual(acc._stack.Count, 2); { // 1억을 지운다. Position_KtbSkel erase = new Position_KtbSkel( "", -10, 8899, "", 10, 107.0); acc.Erase(erase); CheckRateAndNotional(acc, 0, 0, 0, 10); } Assert.AreEqual(acc._stack.Count, 1); }
void TestTakeOverPosition() { string strategyName = "unittest_position"; long maxNotional = 100; double downBoundary = 0F; double upBoundary = 10F; 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 strategyAcc = new STR_KtbSkel_Accessor(po); strategyAcc.SetAccountOrderLimit(); ProcessController_KtbSkel controller = strategyAcc.Controller; String spotCode = KtbSpotUtil.Ins().KtbSpot_10yr.Code; String futureCode = KtbFutureUtil.Ins().KtbFuture_10yr_1.Code; SortedPositionStack_KtbSkel target = new SortedPositionStack_KtbSkel(controller, strategyName, spotCode, futureCode, maxNotional, downBoundary, upBoundary); SortedPositionStack_KtbSkel_Accessor acc = new SortedPositionStack_KtbSkel_Accessor( new PrivateObject(target)); acc._stack.Clear(); acc.DeleteTable(); int i = 1; Position_KtbSkel pos1 = new Position_KtbSkel( spotCode, 50 * i, 8888, futureCode, (-50) * i, 107.00); ++i; Position_KtbSkel pos2 = new Position_KtbSkel( spotCode, 50 * i, 8888, futureCode, (-50) * i, 107.04); ++i; Position_KtbSkel pos3 = new Position_KtbSkel( spotCode, 50 * i, 8888, futureCode, (-50) * i, 107.02); ++i; Position_KtbSkel pos4 = new Position_KtbSkel( spotCode, 50 * i, 8888, futureCode, (-50) * i, 107.03); acc.Push(pos1); acc.ToDB(); acc._stack.Clear(); acc.TakeOverPositionFromDB(); Assert.AreEqual(1, acc._stack.Count); acc.DeleteTable(); acc._stack.Clear(); acc.Push(pos1); acc.Push(pos2); acc.Push(pos3); acc.Push(pos4); acc.ToDB(); acc._stack.Clear(); Assert.AreEqual(0, acc._stack.Count); acc.TakeOverPositionFromDB(); Assert.AreEqual(4, acc._stack.Count); Assert.AreEqual(acc.Peek().SignedSpotCount, 100); }
void CheckRateAndNotional( SortedPositionStack_KtbSkel_Accessor acc, double indicator, double expectedRangeRate, long expectedTargetNotional, long expectedCurPositionNotional) { double actualRangeRate = acc.GetRangeRate(indicator); long actualTargetNotional = acc.GetTargetNotional(indicator); long actualCurPositionNotional = acc.GetCurPositionNotional(); Assert.AreEqual( Math.Round(expectedRangeRate, 4), Math.Round(actualRangeRate, 4)); Assert.AreEqual(expectedTargetNotional, actualTargetNotional); Assert.AreEqual(expectedCurPositionNotional, actualCurPositionNotional); }