|
From: Márcio V. d. S. <mv...@us...> - 2007-06-08 19:21:18
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/tracker/bollingerbands In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv12077/src/test/net/sf/tail/indicator/tracker/bollingerbands Added Files: BollingerBandsUpperIndicatorTest.java BollingerBandsMiddleIndicatorTest.java BollingerBandsLowerIndicatorTest.java Log Message: Refatoração de pacotes e MaximumDrawnDown --- NEW FILE: BollingerBandsMiddleIndicatorTest.java --- package net.sf.tail.indicator.tracker.bollingerbands; import static org.junit.Assert.assertEquals; import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.indicator.tracker.SMAIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsMiddleIndicator; import net.sf.tail.sample.SampleTimeSeries; import org.junit.Before; import org.junit.Test; public class BollingerBandsMiddleIndicatorTest { private TimeSeries data; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2 }); } @Test public void testBollingerBandsMiddleUsingSMA() throws Exception { SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3); BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); for (int i = 0; i < data.getSize(); i++) { assertEquals(sma.getValue(i), bbmSMA.getValue(i)); } } @Test public void testBollingerBandsLowerShouldWorkJumpingIndexes() { SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3); BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); assertEquals(sma.getValue(6), bbmSMA.getValue(6)); assertEquals(sma.getValue(0), bbmSMA.getValue(0)); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3); BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); bbmSMA.getValue(3000); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(BollingerBandsMiddleIndicatorTest.class); } } --- NEW FILE: BollingerBandsLowerIndicatorTest.java --- package net.sf.tail.indicator.tracker.bollingerbands; import static org.junit.Assert.assertEquals; import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.helper.StandardDeviationIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.indicator.tracker.SMAIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsLowerIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsMiddleIndicator; import net.sf.tail.sample.SampleTimeSeries; import org.junit.Before; import org.junit.Test; public class BollingerBandsLowerIndicatorTest { private TimeSeries data; private int timeFrame; private ClosePriceIndicator closePrice; private SMAIndicator sma; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2 }); timeFrame = 3; closePrice = new ClosePriceIndicator(data); sma = new SMAIndicator(closePrice, timeFrame); } @Test public void testBollingerBandsLowerUsingSMAAndStandardDeviation() throws Exception { BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); BollingerBandsLowerIndicator bblSMA = new BollingerBandsLowerIndicator(bbmSMA, standardDeviation); assertEquals(1d, bblSMA.getValue(0)); assertEquals(0.08, bblSMA.getValue(1), 0.01); assertEquals(-0.82, bblSMA.getValue(2), 0.01); assertEquals(0.17, bblSMA.getValue(3), 0.01); assertEquals(1.70, bblSMA.getValue(4), 0.01); assertEquals(2.03, bblSMA.getValue(5), 0.01); assertEquals(1.17, bblSMA.getValue(6), 0.01); } @Test public void testBollingerBandsLowerShouldWorkJumpingIndexes() { BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); BollingerBandsLowerIndicator bblSMA = new BollingerBandsLowerIndicator(bbmSMA, standardDeviation); assertEquals(1.17, bblSMA.getValue(6), 0.01); assertEquals(0.08, bblSMA.getValue(1), 0.01); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); BollingerBandsLowerIndicator bblSMA = new BollingerBandsLowerIndicator(bbmSMA, standardDeviation); bblSMA.getValue(data.getSize()); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(BollingerBandsLowerIndicatorTest.class); } } --- NEW FILE: BollingerBandsUpperIndicatorTest.java --- package net.sf.tail.indicator.tracker.bollingerbands; import static org.junit.Assert.assertEquals; import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.helper.StandardDeviationIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.indicator.tracker.SMAIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsMiddleIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsUpperIndicator; import net.sf.tail.sample.SampleTimeSeries; import org.junit.Before; import org.junit.Test; public class BollingerBandsUpperIndicatorTest { private TimeSeries data; private int timeFrame; private ClosePriceIndicator closePrice; private SMAIndicator sma; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2 }); timeFrame = 3; closePrice = new ClosePriceIndicator(data); sma = new SMAIndicator(closePrice, timeFrame); } @Test public void testBollingerBandsUpperUsingSMAAndStandardDeviation() throws Exception { BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); BollingerBandsUpperIndicator bbuSMA = new BollingerBandsUpperIndicator(bbmSMA, standardDeviation); assertEquals(1.0, bbuSMA.getValue(0),0.01); assertEquals(2.91, bbuSMA.getValue(1),0.01); assertEquals(4.82, bbuSMA.getValue(2),0.01); assertEquals(5.82, bbuSMA.getValue(3),0.01); assertEquals(4.96, bbuSMA.getValue(4),0.01); assertEquals(5.29, bbuSMA.getValue(5),0.01); assertEquals(6.82, bbuSMA.getValue(6),0.01); assertEquals(5.96, bbuSMA.getValue(7),0.01); assertEquals(6.82, bbuSMA.getValue(8),0.01); assertEquals(4.96, bbuSMA.getValue(9),0.01); } @Test public void testBollingerBandsUpperShouldWorkJumpingIndexes() { BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); BollingerBandsUpperIndicator bbuSMA = new BollingerBandsUpperIndicator(bbmSMA, standardDeviation); assertEquals(4.96, bbuSMA.getValue(9),0.01); assertEquals(4.96, bbuSMA.getValue(4),0.01); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); BollingerBandsUpperIndicator bbuSMA = new BollingerBandsUpperIndicator(bbmSMA, standardDeviation); bbuSMA.getValue(data.getSize()); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(BollingerBandsUpperIndicatorTest.class); } } |