コード例 #1
0
ファイル: TestBoxMath.cs プロジェクト: michaelwills/tradelink
        public void ClosePL()
        {
            decimal pl = .98m;

            Assert.That(BoxMath.ClosePT(lp, lc) == pl);
            Assert.That(BoxMath.ClosePT(sp, sc) == -pl);
            Assert.That(BoxMath.ClosePL(lp, lc) == pl * (lsize / 2)); // matches closing size
            Assert.That(BoxMath.ClosePL(sp, sc) == pl * ssize);
        }
コード例 #2
0
        public void Basics()
        {
            Position p = new Position(s);

            Assert.That(p.Size == 0);
            Assert.That(p.hasSymbol);
            Assert.That(p.AvgPrice == 0);
            Assert.That(p.Flat);
            Assert.That(p.isValid);
            Position p2 = new Position(s, 10, 100);

            p.Adjust(p2);
            Assert.That(p.Size == 100);
            Assert.That(p.hasSymbol);
            Assert.That(p.AvgPrice == 10);
            Assert.That(!p.Flat);
            Assert.That(p.Side);
            Assert.That(p.isValid);
            Position p3 = new Position(s, 0, 100);

            Assert.That(!p3.isValid);
            p3 = new Position(s, 10, 0);
            Assert.That(!p3.isValid);
            p3 = new Position(s, 12, 100);
            p.Adjust(p3);
            Assert.That(p.AvgPrice == 11);
            Assert.That(p.Side);
            Assert.That(p.isValid);
            Assert.That(!p.Flat);
            Assert.That(p.Size == 200);
            p.Adjust(new Trade(s, 13, -100, dt));
            Assert.That(p.AvgPrice == 11);
            Assert.That(p.Side);
            Assert.That(p.isValid);
            Assert.That(!p.Flat);
            Assert.That(p.Size == 100);
            Trade   lasttrade = new Trade(s, 12, -100, dt);
            decimal profitFromP2toLASTTRADE = BoxMath.ClosePL(p2, lasttrade);

            Assert.That(profitFromP2toLASTTRADE == (lasttrade.xprice - p2.AvgPrice) * Math.Abs(lasttrade.xsize));
        }