Skip to content
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

Indicator and BarSerie should not be responsible for managing constants nor series #1144

Open
sgflt opened this issue Apr 7, 2024 · 2 comments · May be fixed by #1147
Open

Indicator and BarSerie should not be responsible for managing constants nor series #1144

sgflt opened this issue Apr 7, 2024 · 2 comments · May be fixed by #1147
Labels
enhancement Issue describing or discussing an enhancement for this library

Comments

@sgflt
Copy link
Contributor

sgflt commented Apr 7, 2024

Is your feature request related to a problem? Please describe.
Interface changes made in 1d36ab3
in my opinion break single responsibility principle and cause performance issues, circa 5% slow down.

These methods are not related to BarSerie, but number type used in BarSerie, which should not leak to interface, because it is implementation detail.

    /**
     * @return the related bar series
     */
    BarSeries getBarSeries();

    /**
     * @return the Num of 0
     */
    default Num zero() {
        return getBarSeries().zero();
    }

    /**
     * @return the Num of 1
     */
    default Num one() {
        return getBarSeries().one();
    }

    /**
     * @return the Num of 100
     */
    default Num hundred() {
        return getBarSeries().hundred();
    }

    /**
     * @return the {@link Num Num extending class} for the given {@link Number}
     */
    default Num numOf(Number number) {
        return getBarSeries().numOf(number);
    }

Describe the solution you'd like
Remove these methods form Indicator nad BarSerie interfaces and provide closer encapsulation for used datatype,
which may provide constants ZERO, HUNDRED, ONE etc. in specific data type and save about 5 % of runtime.

BarSerie and Indicator may provide method NumFactory numFactory() for parsing nonconstant values.

From my perspective this proposal also cleans internal implementation flow. From barSerie.giveMeNumber to barSerie.giveMeFactory.giveMeYourNumberWhichMayBeCached.

From User perspective it elimitatest question "Why BarSerie returns numbers?".

@sgflt sgflt added the enhancement Issue describing or discussing an enhancement for this library label Apr 7, 2024
@sgflt
Copy link
Contributor Author

sgflt commented Apr 10, 2024

Tests becomes more intuitive:

int i = 20;
List<Bar> data = new ArraList<>();
// close, volume
data.add(new MockBar(ZonedDateTime.now().minusSeconds(i--), 6, 100, numFactory));
data.add(new MockBar(ZonedDateTime.now().minusSeconds(i--), 7, 105, numFactory));
....
data.add(new MockBar(ZonedDateTime.now().minusSeconds(i--), 9, 95, numFactory));
data.add(new MockBar(ZonedDateTime.now().minusSeconds(i--), 11, 110, numFactory));

BarSeries data = new BaseBarSeries(data);
ClosePriceIndicator close = new ClosePriceIndicator(data);

in my 1.0 draft:

var data = new MockBarSeriesBuilder().withNumFactory(numFactory).build();
int i = 20;
data.barBuilder().endTime(ZonedDateTime.now().minusSeconds(i--)).closePrice(6).volume(100).add();
data.barBuilder().endTime(ZonedDateTime.now().minusSeconds(i--)).closePrice(7).volume(105).add();
...
data.barBuilder().endTime(ZonedDateTime.now().minusSeconds(i--)).closePrice(11).volume(110).add();
data.barBuilder().endTime(ZonedDateTime.now().minusSeconds(i)).closePrice(10).volume(95).add();

var close = new ClosePriceIndicator(data);

@sgflt
Copy link
Contributor Author

sgflt commented Apr 10, 2024

Before:

new MockBarSeries(numFunction, 100, 95, 80, 70, 60, 50)

After:

new MockBarSeriesBuilder().withNumFactory(numFactory).withData(100, 95, 80, 70, 60, 50).build()

@sgflt sgflt linked a pull request Apr 10, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issue describing or discussing an enhancement for this library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant