Beispiel #1
0
        public void OpenPL()
        {
            decimal pl = .98m;

            Assert.That(BoxMath.OpenPT(last, entry, Long) == pl);
            Assert.That(BoxMath.OpenPT(last, entry, Short) == -pl);
            Assert.That(BoxMath.OpenPT(last, entry, lsize) == pl);
            Assert.That(BoxMath.OpenPT(last, entry, ssize) == -pl);
            Assert.That(BoxMath.OpenPT(last, lp) == pl);
            Assert.That(BoxMath.OpenPT(last, sp) == -pl);
            Assert.That(BoxMath.OpenPL(last, lp) == lp.Size * pl);
            Assert.That(BoxMath.OpenPL(last, sp) == sp.Size * pl);
        }
Beispiel #2
0
        decimal tl_gotSrvAcctOpenPLRequest(string s)
        {
            // make sure broker exists
            if (h == null)
            {
                return(0);
            }
            // prepare the account we're getting open pl for
            string acct = s == "" ? Broker.DEFAULTBOOK : s;
            // get trades from this account
            List <Trade> fills = h.SimBroker.GetTradeList(new Account(acct));
            // setup storage for positions we'll create from trades
            Dictionary <string, Position> posdict = new Dictionary <string, Position>();

            // go through every trade and populate the position
            foreach (Trade t in fills)
            {
                Position p = null;
                if (!posdict.TryGetValue(t.symbol, out p))
                {
                    posdict.Add(t.symbol, new Position(t));
                }
                else
                {
                    posdict[t.symbol].Adjust(t);
                }
            }
            // for every-non flat position, calculate the pl and add to the total
            decimal totalopenpl = 0;

            foreach (Position p in posdict.Values)
            {
                if (!p.Flat)
                {
                    totalopenpl += BoxMath.OpenPL(last[p.Symbol], p);
                }
            }
            return(totalopenpl);
        }