Пример #1
0
        private void positionOpened(Position position)
        {
            Strategy        strategy = position.Owner as Strategy;
            PerformanceInfo spi      = strategy.PerformanceInfo as PerformanceInfo;

            spi.openPositions.Add(position);

            PositionMetaInfo pmi = new PositionMetaInfo();

            pmi.openTime       = commonContext.MarketMeter.GetMarketTime(position.Instrument);
            pmi.openTrend      = commonContext.MarketMeter.GetMarketTrend(position.Instrument, strategy.DefaultPeriod);
            pmi.openVolatility = commonContext.MarketMeter.GetMarketVolatility(position.Instrument, strategy.DefaultPeriod);

            position.MetaInfo = pmi;
        }
Пример #2
0
        private void positionClosed(Position position)
        {
            Strategy        strategy = position.Owner as Strategy;
            PerformanceInfo spi      = strategy.PerformanceInfo as PerformanceInfo;

            spi.openPositions.Remove(position);
            spi.closedPositions.Add(position);

            int profit = position.GetProfitLoss();

            if (profit > 0)
            {
                spi.totalWin += profit;
                spi.winningPositionCount++;

                if (profit > spi.largestWin)
                {
                    spi.largestWin = profit;
                }
            }
            else if (profit < 0)
            {
                profit = -profit;

                spi.totalLoss += profit;
                spi.loosingPositionCount++;

                if (profit > spi.largestLoss)
                {
                    spi.largestLoss = profit;
                }
            }

            if (profit != 0)
            {
                //a position is decided to be closed (closers list and closeWeight is updated elsewhere)
                //update TSVR of closers
                PositionMetaInfo pmi = position.MetaInfo as PositionMetaInfo;

                updateReputation(strategy);

                spi.archive.SubmitPerformance(profit,
                                              position.PositionType,
                                              pmi.openTime,
                                              pmi.openTrend,
                                              pmi.openVolatility);
            }
        }