Beispiel #1
0
        public override decimal Calculate(ITimeSeries series, ITradingRecord tradingRecord)
        {
            int numberOfProfitable = 0;

            foreach (Trade trade in tradingRecord.Trades)
            {
                int entryIndex = trade.GetEntry().getIndex();
                int exitIndex  = trade.GetExit().getIndex();

                decimal result;
                if (trade.GetEntry().isBuy())
                {
                    // buy-then-sell trade
                    result = series.GetBar(exitIndex).ClosePrice.DividedBy(series.GetBar(entryIndex).ClosePrice);
                }
                else
                {
                    // sell-then-buy trade
                    result = series.GetBar(entryIndex).ClosePrice.DividedBy(series.GetBar(exitIndex).ClosePrice);
                }
                if (result.IsGreaterThan(Decimals.ONE))
                {
                    numberOfProfitable++;
                }
            }
            return(((decimal)numberOfProfitable).DividedBy(tradingRecord.GetTradeCount()));
        }
Beispiel #2
0
 public void GetTradeCount()
 {
     Assert.AreEqual(0, emptyRecord.GetTradeCount());
     Assert.AreEqual(1, openedRecord.GetTradeCount());
     Assert.AreEqual(2, closedRecord.GetTradeCount());
 }
Beispiel #3
0
 public override decimal Calculate(ITimeSeries series, ITradingRecord tradingRecord)
 {
     return(tradingRecord.GetTradeCount());
 }