-
Notifications
You must be signed in to change notification settings - Fork 693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing TimeSeriesBuilder, Num, DoubleNum and BigDecimalNum #161
Conversation
With this PR ta4j will support using Double as elementary operations type. It is possible to determine the underlying data type during time series creation ## new - Class `Num`: Abstraction of a Number operations in the spirit of ta4j - Class `AbstractNum`: Abstraction of a Number instance - Class: `DoubleNum`: Implementation of Num, uses Double as delegate - Class: `BigDecimalNum`: uses BigDecimal as delegate - Class: `TimeSeriesBuilder`: facilitate creation of BaseTimeSeries ## changed - `TimeSeries` : addBar(..) functions to store a Bar directly in series - `TimeSeries` : valueOf(Number) function to get Num implementation of series - `TimeSeries` : getNumFunction() returns the used function to transform - 'CachedIndicator': valueOf(Number) function to get Num implementation of series Changes in all Indicators and test files: - changed Decimal to Num - changed generating a new value Decimal.valueOf(i)) to valueOf(i) - all indicators extends the CachedIndicator - all indicators needs a reference to its/a time series ## Note: - During the time series creation one can choose the underlying data type. Not in the Bar and not in the indicators.Indicators should only store the logic and use the Num abstraction to describe this logic. - Parameters of indicators should be primitive (int, double). There is no need for (32bit) precision for parameters. They will be transformed in the constructor (via runtime) to the corresponding Num implementation. - Do not use static Num values in indicator, timeSeries or bars, because the underlying Num implementation is defined during runtime. If necessary store static int or double values and transform them in the constructor. - Transform Numbers (int, double,..) with help of valueOf function of the Indicator or the TimeSeries. - Add bars directly to the TimeSeries with help of the new addBar(..) functions.
# Conflicts: # ta4j-core/src/main/java/org/ta4j/core/BaseStrategy.java # ta4j-core/src/main/java/org/ta4j/core/BaseTimeSeries.java # ta4j-core/src/main/java/org/ta4j/core/Decimal.java # ta4j-core/src/main/java/org/ta4j/core/indicators/UlcerIndexIndicator.java # ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/ConvergenceDivergenceIndicator.java # ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/FixedIndicator.java # ta4j-core/src/main/java/org/ta4j/core/indicators/statistics/PearsonCorrelationIndicator.java # ta4j-core/src/main/java/org/ta4j/core/indicators/volume/ChaikinOscillatorIndicator.java # ta4j-core/src/test/java/org/ta4j/core/XlsTestsUtils.java # ta4j-core/src/test/java/org/ta4j/core/indicators/ATRIndicatorTest.java # ta4j-core/src/test/java/org/ta4j/core/indicators/EMAIndicatorTest.java # ta4j-core/src/test/java/org/ta4j/core/indicators/MMAIndicatorTest.java # ta4j-core/src/test/java/org/ta4j/core/indicators/RSIIndicatorTest.java # ta4j-core/src/test/java/org/ta4j/core/indicators/SMAIndicatorTest.java # ta4j-core/src/test/java/org/ta4j/core/indicators/adx/ADXIndicatorTest.java # ta4j-core/src/test/java/org/ta4j/core/indicators/adx/MinusDIIndicatorTest.java # ta4j-core/src/test/java/org/ta4j/core/indicators/adx/PlusDIIndicatorTest.java # ta4j-examples/src/main/java/ta4jexamples/Quickstart.java # ta4j-examples/src/main/java/ta4jexamples/bots/TradingBotOnMovingTimeSeries.java
Good to see this moving along! Excited to get back in sync and do some comparative perf testing. |
- Changed valueOf(Number) to numOf(Number) - No need for AbstractNum class - Num interface with default functions (replace Number extending and some defaults like isNaN -> always false except for NaN implementation - Not all Indicators extends the CachedIndicator, but the AbstractIndicator because we need always a TimeSeries - Added example program with new Nums and TimeSeriesBuilder
* Started replacing TimeSeries creation in Testfiles with TimeSeriesBuilder to manage NumFunction of the series via TaTestUtils
Hey @team172011
|
@damir78 if (!(divisor instanceof DoubleNum)){
throw new IllegalArgumentException(String.format(
"The underlying data types '%s' and '%s' are not the same"
,this.getClass(), divisor.getClass()));
} it does not matter if the exception has been thrown because of false if statement or because of failed cast regarding 2., I think the |
* Started replacing TimeSeries creation in Testfiles with TimeSeriesBuilder to manage NumFunction of the series via TaTestUtils
... for DoubleNum and for BigDecimalNum.
Should TestUtils.BIG_DECIMAL_OFFSET be renamed to TestUtils.NUM_OFFSET? Similarly, the javadoc comments should probably be changed from Decimal to Num. These are inconsequential items but they are quite misleading as-is. Great work here, and sorry to be annoying. :-) |
@edlins you are right. Your concern also points out that we need different offsets for DoubleNum and DecimalNum or a special test case for BigDecimalNum that checks its high precision |
If you like, sure. I'd just give it a generic name and let people adjust it for their purposes. But I don't see a reason to object unless it makes writing test cases more complicated for newer developers. |
merged, resolved and manually pushed to develop |
(permanently updated..)
With this PR ta4j will support using Double as elementary operations
type. It is possible to determine the underlying data type during
time series creation
BigDecimal
tests passedDouble
tests passednew
Num
: Abstraction of number operations in the spirit of ta4jNaN
Implementation ofNum
, represents static Not a Number instanceDoubleNum
: Implementation ofNum
, usesDouble
as delegateBigDecimalNum
: Implementation ofNum uses
, usesBigDecimal
as delegateTimeSeriesBuilder
: facilitate creation and transport of parameters ofBaseTimeSeries
changed
TimeSeries
: addBar(..) functions to store a Bar directly in seriesTimeSeries
: numOf(Number) function to get Num implementation of seriesTimeSeries
: function() returns the used function to transform Numbers into NumsCachedIndicator
: numOf(Number), numOf function of the underlyingTimeSeries
Changes in all Indicators and test files:
parameterized
AbstractIndicatorTest
andAbstractCriterionTest
for testingDoubleNum
anBigDecimalNum
changed Decimal to Num
changed generating a new value Decimal.valueOf(i)) to numOf(i) conditional of class instance
all indicators needs a reference to its/a time series
Note:
Not in the Bar and not in the indicators.Indicators should only store
the logic and use the Num abstraction to describe this logic.
need for (32bit) precision for parameters. They will be transformed in
the constructor (via runtime) to the corresponding Num implementation.
the underlying Num implementation is defined during runtime. If necessary
store static int or double values and transform them in the constructor.
Indicator or the TimeSeries.
TimeSeries
with help of the new addBar(..)functions.
Create TimeSeries:
Num and valueOf in indicator:
Testfile with extending AbstractIndicatorTest (supports excel sheet validation, custom asserts and tests DoubleNum and BigDecimalNum)