Beispiel #1
0
  public void testSignalGenerationSize() throws Exception {
    Rule buySell = new BuySellNextDayRule(account, asset, conditions);
    Session session = buySell.generateSignals(today.minusDays(5), today.minusDays(2));
    assertEquals(2, session.getTrades().size());

    account = new Account(new BigDecimal(1000), today.minusDays(6));

    buySell = new BuySellNextDayRule(account, asset, conditions);

    assertEquals(
        2, buySell.generateSignals(today.minusDays(5), today.minusDays(1)).getTrades().size());
  }
Beispiel #2
0
  public void quitsIfInsufficientFunds() throws Exception {
    account = new Account(new BigDecimal(1), today.minusDays(6));
    Rule buyAndHold = new BuyAndHoldRule(account, asset, conditions);

    assertEquals(
        0, buyAndHold.generateSignals(today.minusDays(5), today.minusDays(4)).getTrades().size());
  }
Beispiel #3
0
 public void testOnlyShorting() throws Exception {
   Rule noTrades = new OnlyShortRule(account, asset, conditions);
   Session session = noTrades.generateSignals(today.minusDays(5), today.minusDays(1));
   assertEquals(1, session.getTrades().size());
 }
Beispiel #4
0
 public void testNotEnteringMarket() throws Exception {
   Rule noTrades = new NeverEnterMarketRule(account, asset, conditions);
   assertEquals(
       0, noTrades.generateSignals(today.minusDays(5), today.minusDays(1)).getTrades().size());
 }
Beispiel #5
0
 public void testCloseLastTrade() throws Exception {
   Rule buySell = new BuySellNextDayRule(account, asset, conditions);
   Session signals = buySell.generateSignals(today.minusDays(5), today.minusDays(2));
   assertTrue(signals.lastTrade().isClosed());
   assertEquals(today.minusDays(2), signals.lastTrade().getClose());
 }
Beispiel #6
0
  public void testDontEmitMultipleIdenticalSignals() throws Exception {
    Rule buyAndHold = new BuyAndHoldRule(account, asset, conditions);

    assertEquals(
        1, buyAndHold.generateSignals(today.minusDays(5), today.minusDays(3)).getTrades().size());
  }