Skip to content

Commit 5aa5904

Browse files
committed
Synchronize code repos
Notable changes include: - **Time Representation:** Shifting from microsecond to nanosecond precision for timestamps enhances accuracy and aligns with modern timekeeping practices. - **Candle Data:** Adding turnover and trades to the Candle interface provides a more comprehensive representation of price bars. - **Financial Indicators:** Refactoring and introducing new indicators like FramaTrendWhispers and AverageTrueRange expands the analytical capabilities. - **Performance Optimization:** Utilizing optimized parsing techniques like JavaDoubleParser and FromString enhances data processing speed. - **Code Structure:** Refactoring classes and interfaces, such as introducing IdentityType and InstrumentType, improves code organization and clarity. - **New Features:** Introducing concepts like MarketMessageSource and AlgorithmWorker lays the groundwork for more sophisticated trading simulations.
1 parent ea59c48 commit 5aa5904

File tree

154 files changed

+6590
-756
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+6590
-756
lines changed

.run/rebuild-and-run.run.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22
<configuration default="false" name="rebuild-and-run" type="MavenRunConfiguration" factoryName="Maven">
33
<MavenSettings>
44
<option name="myGeneralSettings" />
5-
<option name="myRunnerSettings" />
5+
<option name="myRunnerSettings">
6+
<MavenRunnerSettings>
7+
<option name="delegateBuildToMaven" value="false" />
8+
<option name="environmentProperties">
9+
<map />
10+
</option>
11+
<option name="jreName" value="graalvm-22" />
12+
<option name="mavenProperties">
13+
<map />
14+
</option>
15+
<option name="passParentEnv" value="true" />
16+
<option name="runMavenInBackground" value="true" />
17+
<option name="skipTests" value="false" />
18+
<option name="vmOptions" value="" />
19+
</MavenRunnerSettings>
20+
</option>
621
<option name="myRunnerParameters">
722
<MavenRunnerParameters>
823
<option name="cmdOptions" />
@@ -17,6 +32,7 @@
1732
<option value="-X" />
1833
</list>
1934
</option>
35+
<option name="multimoduleDir" />
2036
<option name="pomFileName" />
2137
<option name="profilesMap">
2238
<map />

chartsy-benchmarking/src/main/java/one/chartsy/benchmarking/GenericBenchmark.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import one.chartsy.data.ExtendedCandle;
1111
import one.chartsy.data.SimpleCandle;
1212
import one.chartsy.random.RandomWalk;
13-
import one.chartsy.simulation.time.SimulationClock;
13+
import one.chartsy.simulation.time.PlaybackClock;
1414
import one.chartsy.time.Chronological;
1515
import org.openjdk.jmh.annotations.*;
1616
import org.openjdk.jmh.profile.StackProfiler;
@@ -69,7 +69,7 @@ public static class BenchmarkState
6969
PriorityMap<Chronological, Candle> map = new PriorityMap<>();
7070
PriorityQueue<Chronological> queue = new PriorityQueue<>();
7171
volatile int index;
72-
SimulationClock simClock = new SimulationClock(ZoneId.systemDefault(), Chronological.now());
72+
PlaybackClock simClock = new PlaybackClock(ZoneId.systemDefault(), Chronological.now());
7373
Class[] classes = new Class[] {Chronological.class, Candle.class, ExtendedCandle.class, SimpleCandle.class, AbstractCandle.class};
7474

7575
@Setup(Level.Trial) public void

chartsy-benchmarking/src/main/java/one/chartsy/benchmarking/Main4.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import one.chartsy.data.structures.PriorityMap;
99
import one.chartsy.data.*;
1010
import one.chartsy.random.RandomWalk;
11-
import one.chartsy.simulation.time.SimulationClock;
11+
import one.chartsy.simulation.time.PlaybackClock;
1212
import one.chartsy.time.Chronological;
1313
import org.openjdk.jmh.annotations.*;
1414
import org.openjdk.jmh.profile.StackProfiler;
@@ -65,7 +65,7 @@ public static class BenchmarkState
6565
PriorityMap<Chronological, Candle> map = new PriorityMap<>();
6666
PriorityQueue<Chronological> queue = new PriorityQueue<>();
6767
int index;
68-
SimulationClock simClock = new SimulationClock(ZoneId.systemDefault(), Chronological.now());
68+
PlaybackClock simClock = new PlaybackClock(ZoneId.systemDefault(), Chronological.now());
6969
Class[] classes = new Class[] {Chronological.class, Candle.class, ExtendedCandle.class, SimpleCandle.class, AbstractCandle.class};
7070

7171
@Setup(Level.Trial) public void
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package one.chartsy.benchmarking.indicators;
2+
3+
import one.chartsy.SymbolResource;
4+
import one.chartsy.TimeFrame;
5+
import one.chartsy.data.CandleSeries;
6+
import one.chartsy.data.provider.DataProvider;
7+
import one.chartsy.data.provider.DataProviders;
8+
import one.chartsy.data.provider.file.FlatFileFormat;
9+
import one.chartsy.finance.FinancialIndicators;
10+
import one.chartsy.financial.ValueIndicatorSupport;
11+
import one.chartsy.financial.indicators.FractalDimension;
12+
import org.openjdk.jmh.annotations.Benchmark;
13+
import org.openjdk.jmh.annotations.BenchmarkMode;
14+
import org.openjdk.jmh.annotations.Level;
15+
import org.openjdk.jmh.annotations.Mode;
16+
import org.openjdk.jmh.annotations.OutputTimeUnit;
17+
import org.openjdk.jmh.annotations.Scope;
18+
import org.openjdk.jmh.annotations.Setup;
19+
import org.openjdk.jmh.annotations.State;
20+
import org.openjdk.jmh.infra.Blackhole;
21+
import org.openjdk.jmh.runner.Runner;
22+
import org.openjdk.jmh.runner.RunnerException;
23+
import org.openjdk.jmh.runner.options.Options;
24+
import org.openjdk.jmh.runner.options.OptionsBuilder;
25+
import org.openjdk.jmh.runner.options.TimeValue;
26+
27+
import java.io.IOException;
28+
import java.nio.file.Path;
29+
import java.util.concurrent.TimeUnit;
30+
31+
public class FractalDimensionBenchmark {
32+
33+
static DataProvider dataProvider;
34+
static {
35+
try {
36+
dataProvider = FlatFileFormat.FOREXTESTER.newDataProvider(Path.of("C:/Data/forextester.com/EURUSD.zip"));
37+
} catch (IOException e) {
38+
throw new RuntimeException(e);
39+
}
40+
}
41+
42+
@State(Scope.Benchmark)
43+
public static class BenchmarkState {
44+
public CandleSeries series;
45+
46+
@Setup(Level.Trial)
47+
public void setup() {
48+
this.series = DataProviders.getHistoricalCandles(dataProvider, SymbolResource.of("EURUSD", TimeFrame.Period.M1));
49+
System.out.println("SERIES LENGTH: " + this.series.length());
50+
}
51+
}
52+
53+
@Benchmark
54+
@BenchmarkMode(Mode.AverageTime)
55+
@OutputTimeUnit(TimeUnit.SECONDS)
56+
public void benchmarkFdi(BenchmarkState state, Blackhole blackhole) {
57+
var result = FinancialIndicators.fdi(state.series.closes(), 30);
58+
blackhole.consume(result);
59+
}
60+
61+
@Benchmark
62+
@BenchmarkMode(Mode.AverageTime)
63+
@OutputTimeUnit(TimeUnit.SECONDS)
64+
public void benchmarkFdiFast(BenchmarkState state, Blackhole blackhole) {
65+
var result = FinancialIndicators.fastFdi(state.series.closes(), 30);
66+
blackhole.consume(result);
67+
}
68+
69+
@Benchmark
70+
@BenchmarkMode(Mode.AverageTime)
71+
@OutputTimeUnit(TimeUnit.SECONDS)
72+
public void benchmarkNewAsSeries(BenchmarkState state, Blackhole blackhole) {
73+
double[] result = new double[state.series.length()];
74+
75+
var indicator = new FractalDimension(30);
76+
for (int i = state.series.length() - 1; i >= 0; i--) {
77+
indicator.accept(state.series.get(i).close());
78+
result[i] = indicator.getLast();
79+
}
80+
81+
blackhole.consume(result);
82+
}
83+
84+
@Benchmark
85+
@BenchmarkMode(Mode.AverageTime)
86+
@OutputTimeUnit(TimeUnit.SECONDS)
87+
public void benchmarkWithValueIndicatorSupportWithValueFunction(BenchmarkState state, Blackhole blackhole) {
88+
blackhole.consume(ValueIndicatorSupport.calculate(state.series.closes(), new FractalDimension(30), FractalDimension::getLast));
89+
}
90+
91+
@Benchmark
92+
@BenchmarkMode(Mode.AverageTime)
93+
@OutputTimeUnit(TimeUnit.SECONDS)
94+
public void benchmarkWithValueIndicatorSupportWithoutValueFunction(BenchmarkState state, Blackhole blackhole) {
95+
blackhole.consume(ValueIndicatorSupport.calculate(state.series.closes(), new FractalDimension(30)));
96+
}
97+
98+
public static void main(String[] args) throws RunnerException {
99+
Options opt = new OptionsBuilder()
100+
// Specify which benchmarks to run.
101+
// You can be more specific if you'd like to run only one benchmark per test.
102+
.include(FractalDimensionBenchmark.class.getName() + ".*")
103+
// Set the following options as needed
104+
.warmupTime(TimeValue.seconds(1))
105+
.warmupIterations(5)
106+
.measurementTime(TimeValue.seconds(10))
107+
.measurementIterations(10)
108+
.threads(1)
109+
.forks(1)
110+
.shouldFailOnError(true)
111+
.shouldDoGC(true)
112+
//.addProfiler(JavaFlightRecorderProfiler.class)
113+
.build();
114+
new Runner(opt).run();
115+
}
116+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package one.chartsy.benchmarking.indicators;
2+
3+
import one.chartsy.SymbolResource;
4+
import one.chartsy.TimeFrame;
5+
import one.chartsy.data.CandleSeries;
6+
import one.chartsy.data.provider.DataProvider;
7+
import one.chartsy.data.provider.DataProviders;
8+
import one.chartsy.data.provider.file.FlatFileFormat;
9+
import org.openjdk.jmh.annotations.Benchmark;
10+
import org.openjdk.jmh.annotations.BenchmarkMode;
11+
import org.openjdk.jmh.annotations.Level;
12+
import org.openjdk.jmh.annotations.Mode;
13+
import org.openjdk.jmh.annotations.OutputTimeUnit;
14+
import org.openjdk.jmh.annotations.Scope;
15+
import org.openjdk.jmh.annotations.Setup;
16+
import org.openjdk.jmh.annotations.State;
17+
import org.openjdk.jmh.infra.Blackhole;
18+
import org.openjdk.jmh.runner.Runner;
19+
import org.openjdk.jmh.runner.RunnerException;
20+
import org.openjdk.jmh.runner.options.Options;
21+
import org.openjdk.jmh.runner.options.OptionsBuilder;
22+
import org.openjdk.jmh.runner.options.TimeValue;
23+
24+
import java.io.IOException;
25+
import java.nio.file.Path;
26+
import java.util.concurrent.ThreadLocalRandom;
27+
import java.util.concurrent.TimeUnit;
28+
29+
public class TangentCalculationBenchmark {
30+
31+
@Benchmark
32+
@BenchmarkMode(Mode.AverageTime)
33+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
34+
public double benchmarkTangentCalculation() {
35+
ThreadLocalRandom random = ThreadLocalRandom.current();
36+
return Math.tan(random.nextDouble(0, 100.0));
37+
}
38+
39+
public static void main(String[] args) throws RunnerException {
40+
Options opt = new OptionsBuilder()
41+
// Specify which benchmarks to run.
42+
.include(TangentCalculationBenchmark.class.getName() + ".*")
43+
// Set the following options as needed
44+
.warmupTime(TimeValue.seconds(1))
45+
.warmupIterations(3)
46+
.measurementTime(TimeValue.seconds(10))
47+
.measurementIterations(10)
48+
.threads(1)
49+
.forks(1)
50+
.shouldFailOnError(true)
51+
.shouldDoGC(true)
52+
.build();
53+
new Runner(opt).run();
54+
}
55+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package one.chartsy.benchmarking.service.invoker;
2+
3+
import one.chartsy.core.event.AbstractInvoker;
4+
import org.openjdk.jmh.annotations.*;
5+
import org.openjdk.jmh.infra.Blackhole;
6+
import org.openjdk.jmh.profile.JavaFlightRecorderProfiler;
7+
import org.openjdk.jmh.runner.Runner;
8+
import org.openjdk.jmh.runner.RunnerException;
9+
import org.openjdk.jmh.runner.options.Options;
10+
import org.openjdk.jmh.runner.options.OptionsBuilder;
11+
import org.openjdk.jmh.runner.options.TimeValue;
12+
13+
import java.util.concurrent.TimeUnit;
14+
15+
public class AbstractInvoker1Benchmark {
16+
17+
public interface TestHandler1 {
18+
void handle1(String message, Blackhole blackhole);
19+
}
20+
21+
public interface TestHandler2 {
22+
void handle2(String message, Blackhole blackhole);
23+
}
24+
25+
public static class TestService1 implements TestHandler1, TestHandler2 {
26+
@Override
27+
public void handle1(String message, Blackhole blackhole) {
28+
blackhole.consume(message);
29+
}
30+
31+
@Override
32+
public void handle2(String message, Blackhole blackhole) {
33+
blackhole.consume(message);
34+
}
35+
}
36+
37+
public static class TestService2 implements TestHandler2, TestHandler1 {
38+
@Override
39+
public void handle2(String message, Blackhole blackhole) {
40+
blackhole.consume(message);
41+
}
42+
43+
@Override
44+
public void handle1(String message, Blackhole blackhole) {
45+
blackhole.consume(message);
46+
}
47+
}
48+
49+
public static class TestInvoker extends AbstractInvoker {
50+
private TestHandler1 handler1 = getListenerList(TestHandler1.class).fire();
51+
private TestHandler2 handler2 = getListenerList(TestHandler2.class).fire();
52+
53+
public TestInvoker(Object primaryService) {
54+
super(primaryService);
55+
}
56+
57+
public void invokeHandler(String message, Blackhole blackhole) {
58+
handler1.handle1(message, blackhole);
59+
handler2.handle2(message, blackhole);
60+
}
61+
}
62+
63+
@State(Scope.Benchmark)
64+
public static class BenchmarkState {
65+
public TestInvoker invoker;
66+
public TestService1 service1;
67+
public TestService2 service2;
68+
public String testMessage = "test message";
69+
70+
@Setup(Level.Trial)
71+
public void setup() {
72+
service1 = new TestService1();
73+
service2 = new TestService2();
74+
invoker = new TestInvoker(service1);
75+
invoker.addService(service1);
76+
invoker.addService(service2);
77+
}
78+
}
79+
80+
@Benchmark
81+
@BenchmarkMode(Mode.AverageTime)
82+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
83+
public void benchmarkInvokerMethodCall(BenchmarkState state, Blackhole blackhole) {
84+
state.invoker.invokeHandler(state.testMessage, blackhole);
85+
}
86+
87+
@Benchmark
88+
@BenchmarkMode(Mode.AverageTime)
89+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
90+
public void benchmarkDirectMethodCall(BenchmarkState state, Blackhole blackhole) {
91+
state.service1.handle1(state.testMessage, blackhole);
92+
state.service1.handle2(state.testMessage, blackhole);
93+
state.service2.handle2(state.testMessage, blackhole);
94+
state.service2.handle1(state.testMessage, blackhole);
95+
}
96+
97+
// public static class Main {
98+
public static void main(String[] args) throws RunnerException {
99+
Options opt = new OptionsBuilder()
100+
// Specify which benchmarks to run.
101+
// You can be more specific if you'd like to run only one benchmark per test.
102+
.include(AbstractInvoker1Benchmark.class.getName() + ".*")
103+
// Set the following options as needed
104+
.warmupTime(TimeValue.seconds(1))
105+
.warmupIterations(3)
106+
.measurementTime(TimeValue.seconds(3))
107+
.measurementIterations(10)
108+
.threads(1)
109+
.forks(1)
110+
.shouldFailOnError(true)
111+
.shouldDoGC(true)
112+
.addProfiler(JavaFlightRecorderProfiler.class)
113+
.build();
114+
new Runner(opt).run();
115+
}
116+
// }
117+
}

0 commit comments

Comments
 (0)