Skip to content

Commit

Permalink
FxSampler: enable math and financial samples
Browse files Browse the repository at this point in the history
  • Loading branch information
wirew0rm committed Jul 31, 2023
1 parent 4b920aa commit fb637bb
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
import java.util.Calendar;
import java.util.Map;

import fxsampler.SampleBase;
import io.fair_acc.chartfx.Chart;
import io.fair_acc.sample.chart.ChartSample;
import io.fair_acc.sample.financial.service.consolidate.OhlcvConsolidationAddon;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.FlowPane;
Expand Down Expand Up @@ -63,7 +66,7 @@
*
* @author afischer
*/
public abstract class AbstractBasicFinancialApplication extends Application {
public abstract class AbstractBasicFinancialApplication extends ChartSample {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractBasicFinancialApplication.class);

protected int prefChartWidth = 640; // 1024
Expand Down Expand Up @@ -92,42 +95,42 @@ public abstract class AbstractBasicFinancialApplication extends Application {

private boolean timerActivated = false;

@Override
public void start(final Stage primaryStage) {
ProcessingProfiler.setVerboseOutputState(true);
ProcessingProfiler.setLoggerOutputState(true);
ProcessingProfiler.setDebugState(false);

long startTime = ProcessingProfiler.getTimeStamp();
ProcessingProfiler.getTimeDiff(startTime, "adding data to chart");
startTime = ProcessingProfiler.getTimeStamp();

configureApp();
Scene scene = prepareScene();
ProcessingProfiler.getTimeDiff(startTime, "adding chart into StackPane");

startTime = ProcessingProfiler.getTimeStamp();
primaryStage.setTitle(this.getClass().getSimpleName());
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(this::closeDemo);
primaryStage.show();
ProcessingProfiler.getTimeDiff(startTime, "for showing");

// ensure correct state after restart demo
stopTimer();
}
//@Override
//public void start(final Stage primaryStage) {
// ProcessingProfiler.setVerboseOutputState(true);
// ProcessingProfiler.setLoggerOutputState(true);
// ProcessingProfiler.setDebugState(false);

// long startTime = ProcessingProfiler.getTimeStamp();
// ProcessingProfiler.getTimeDiff(startTime, "adding data to chart");
// startTime = ProcessingProfiler.getTimeStamp();

// configureApp();
// Scene scene = prepareScene();
// ProcessingProfiler.getTimeDiff(startTime, "adding chart into StackPane");

// startTime = ProcessingProfiler.getTimeStamp();
// primaryStage.setTitle(this.getClass().getSimpleName());
// primaryStage.setScene(scene);
// primaryStage.setOnCloseRequest(this::closeDemo);
// primaryStage.show();
// ProcessingProfiler.getTimeDiff(startTime, "for showing");

// // ensure correct state after restart demo
// stopTimer();
//}

protected void configureApp() {
// configure shared variables for application sample tests
}

protected void closeDemo(final WindowEvent evt) {
if (evt.getEventType().equals(WindowEvent.WINDOW_CLOSE_REQUEST) && LOGGER.isInfoEnabled()) {
LOGGER.atInfo().log("requested demo to shut down");
}
stopTimer();
Platform.exit();
}
//protected void closeDemo(final WindowEvent evt) {
// if (evt.getEventType().equals(WindowEvent.WINDOW_CLOSE_REQUEST) && LOGGER.isInfoEnabled()) {
// LOGGER.atInfo().log("requested demo to shut down");
// }
// stopTimer();
// Platform.exit();
//}

protected ToolBar getTestToolBar(Chart chart, AbstractFinancialRenderer<?> renderer, boolean replaySupport) {
ToolBar testVariableToolBar = new ToolBar();
Expand Down Expand Up @@ -177,14 +180,14 @@ protected ToolBar getTestToolBar(Chart chart, AbstractFinancialRenderer<?> rende
*
* @return prepared scene for sample app
*/
protected Scene prepareScene() {
public Node getChartPanel(Stage stage) {
// show all default financial color schemes
final FlowPane root = new FlowPane();
root.setAlignment(Pos.CENTER);
Chart[] charts = Arrays.stream(getDefaultColorSchemes()).map(this::getDefaultFinancialTestChart).toArray(Chart[] ::new);
root.getChildren().addAll(charts);

return new Scene(root, prefSceneWidth, prefSceneHeight);
return root;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Calendar;

import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
Expand All @@ -18,6 +19,7 @@
import io.fair_acc.dataset.spi.financial.OhlcvDataSet;
import io.fair_acc.dataset.spi.financial.api.attrs.AttributeKey;
import io.fair_acc.dataset.spi.financial.api.ohlcv.IOhlcvItem;
import javafx.stage.Stage;

/**
* Advanced configuration of Candlestick renderer. Support for PaintBars and extension points.
Expand All @@ -31,7 +33,7 @@ public class FinancialAdvancedCandlestickSample extends AbstractBasicFinancialAp
* Prepare charts to the root.
*/
@Override
protected Scene prepareScene() {
public Node getChartPanel(Stage stage) {
timeRange = "2020/06/24 0:00-2020/11/12 0:00";

final var chart = getDefaultFinancialTestChart(FinancialColorSchemeConstants.SAND);
Expand All @@ -44,7 +46,7 @@ protected Scene prepareScene() {
VBox.setVgrow(chart, Priority.SOMETIMES);
root.getChildren().addAll(testVariableToolBar, chart);

return new Scene(root, prefSceneWidth, prefSceneHeight);
return root;
}

protected void prepareRenderers(XYChart chart, OhlcvDataSet ohlcvDataSet, DefaultDataSet indiSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.List;

import javafx.geometry.HPos;
import javafx.scene.Scene;
import javafx.scene.Node;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
Expand Down Expand Up @@ -37,6 +37,7 @@
import io.fair_acc.sample.financial.service.period.IntradayPeriod;
import io.fair_acc.sample.financial.service.plan.MktOrderListTradePlan;
import io.fair_acc.sample.financial.service.plan.MktOrderListTradePlan.SimMktOrder;
import javafx.stage.Stage;

/**
* Tick OHLC/V realtime processing. Demonstration of re-sample data to 2M timeframe.
Expand All @@ -63,7 +64,8 @@ protected void configureApp() {
/**
* Prepare charts to the root.
*/
protected Scene prepareScene() {
@Override
public Node getChartPanel(Stage stage) {
String priceFormat = "%1.1f";
// simulate market orders list
List<SimMktOrder> orders = new ArrayList<>();
Expand Down Expand Up @@ -147,7 +149,7 @@ protected Scene prepareScene() {
VBox.setVgrow(chart, Priority.SOMETIMES);
root.getChildren().addAll(testVariableToolBar, chart);

return new Scene(root, prefSceneWidth, prefSceneHeight);
return root;
}

protected YRangeIndicator createRsLevel(Axis yAxis, double lowerBound, double upperBound, String description) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import java.util.Arrays;

import io.fair_acc.sample.chart.ChartSample;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.layout.VBox;

import javafx.stage.Stage;
import org.jtransforms.fft.DoubleFFT_1D;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.fair_acc.dataset.DataSet;
import io.fair_acc.dataset.spi.DefaultDataSet;
import io.fair_acc.math.MathBase;
import io.fair_acc.sample.math.utils.AbstractDemoApplication;
import io.fair_acc.sample.math.utils.DemoChart;
import io.fair_acc.math.spectra.SpectrumTools;

Expand All @@ -23,7 +24,7 @@
*
* @author rstein
*/
public class ComplexFourierSample extends AbstractDemoApplication {
public class ComplexFourierSample extends ChartSample {
private static final Logger LOGGER = LoggerFactory.getLogger(ComplexFourierSample.class);
private static final int MAX_POINTS = 512;
private static final double T_MAX = 1.0;
Expand Down Expand Up @@ -51,7 +52,7 @@ private static double[] computeSignal(final double T, final int nSamples) {
}

@Override
public Node getContent() {
public Node getChartPanel(Stage stage) {
initData();
final DemoChart chart1 = new DemoChart();
chart1.getXAxis().setName("time");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.fair_acc.sample.math;

import io.fair_acc.sample.chart.ChartSample;
import javafx.application.Application;
import javafx.scene.Node;

import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -13,23 +15,25 @@
import io.fair_acc.dataset.utils.LimitedQueue;
import io.fair_acc.math.DataSetMath;
import io.fair_acc.math.functions.SigmoidFunction;
import io.fair_acc.sample.math.utils.AbstractDemoApplication;
import io.fair_acc.sample.math.utils.DemoChart;

import java.util.Random;

/**
* Sample to illustrate averaging over several data sets with an IIR and FIR low-pass filter
*
* @author rstein
*/
public class DataSetAverageSample extends AbstractDemoApplication {
public class DataSetAverageSample extends ChartSample {
protected static final Random RANDOM = new Random(System.currentTimeMillis());
private static final Logger LOGGER = LoggerFactory.getLogger(DataSetAverageSample.class);
private static final int N_GRAPHS = 20;
private static final int N_SAMPLES = 100;
private DataSet oldAverageDataSet;
private final DataSet oldAverageDataSet2 = new DoubleErrorDataSet("var2");

@Override
public Node getContent() {
public Node getChartPanel(Stage stage) {
final DemoChart chart = new DemoChart(2);
chart.getRenderer(0).setPolyLineStyle(LineStyle.NONE);
chart.getRenderer(0).setErrorType(ErrorStyle.NONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@
import io.fair_acc.dataset.DataSet;
import io.fair_acc.math.DataSetMath;
import io.fair_acc.math.functions.GaussianFunction;
import io.fair_acc.sample.math.utils.AbstractDemoApplication;
import io.fair_acc.sample.chart.ChartSample;
import io.fair_acc.sample.math.utils.DemoChart;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.stage.Stage;

import java.util.Random;

/**
* Sample to illustrate low-pass and median filtering of a data set
*
* @author rstein
*
*/
public class DataSetFilterSample extends AbstractDemoApplication {
public class DataSetFilterSample extends ChartSample {
protected static final Random RANDOM = new Random(System.currentTimeMillis());
private static final int N_SAMPLES = 1000;
private static final double FILTER_BW = 0.2;

@Override
public Node getContent() {
public Node getChartPanel(Stage stage) {

final DemoChart chart = new DemoChart();
chart.getRenderer(0).setDrawMarker(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.fair_acc.sample.math;

import io.fair_acc.sample.chart.ChartSample;
import javafx.application.Application;
import javafx.scene.Node;

Expand All @@ -8,19 +9,22 @@
import io.fair_acc.dataset.spi.DefaultErrorDataSet;
import io.fair_acc.math.DataSetMath;
import io.fair_acc.math.functions.GaussianFunction;
import io.fair_acc.sample.math.utils.AbstractDemoApplication;
import io.fair_acc.sample.math.utils.DemoChart;
import javafx.stage.Stage;

import java.util.Random;

/**
* Sample to illustrate integral and differentiation of data sets low-pass filter
*
* @author rstein
*/
public class DataSetIntegrateDifferentiateSample extends AbstractDemoApplication {
public class DataSetIntegrateDifferentiateSample extends ChartSample {
protected static final Random RANDOM = new Random(System.currentTimeMillis());
private static final int N_SAMPLES = 100;

@Override
public Node getContent() {
public Node getChartPanel(Stage stage) {
final DemoChart chart = new DemoChart();
chart.getRenderer(0).setDrawMarker(false);
chart.getRenderer(0).setErrorType(ErrorStyle.ERRORSURFACE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
import io.fair_acc.dataset.spi.DoubleErrorDataSet;
import io.fair_acc.math.DataSetMath;
import io.fair_acc.math.functions.GaussianFunction;
import io.fair_acc.sample.math.utils.AbstractDemoApplication;
import io.fair_acc.sample.chart.ChartSample;
import io.fair_acc.sample.math.utils.DemoChart;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.stage.Stage;

import java.util.Random;

/**
* Sample to illustrate integral with limits filter
*
* @author rstein
*/
public class DataSetIntegrationWithLimitsSample extends AbstractDemoApplication {
public class DataSetIntegrationWithLimitsSample extends ChartSample {
protected static final Random RANDOM = new Random(System.currentTimeMillis());
private static final int N_SAMPLES = 41;

@Override
public Node getContent() {
public Node getChartPanel(Stage stage) {

final DemoChart chart = new DemoChart();
chart.getRenderer(0).setDrawMarker(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import io.fair_acc.math.DataSetMath;
import io.fair_acc.math.functions.TrigCosineFunction;
import io.fair_acc.math.functions.TrigSineFunction;
import io.fair_acc.sample.math.utils.AbstractDemoApplication;
import io.fair_acc.sample.chart.ChartSample;
import io.fair_acc.sample.math.utils.DemoChart;
import io.fair_acc.math.spectra.Apodization;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.util.Random;

/**
* example illustrating the Fast-Fourier transform and math operations directly on DataSet
Expand All @@ -21,12 +24,13 @@
*
* @author rstein
*/
public class DataSetSpectrumSample extends AbstractDemoApplication {
public class DataSetSpectrumSample extends ChartSample {
protected static final Random RANDOM = new Random(System.currentTimeMillis());
private static final int N_SAMPLES = 200;
private static boolean unequalSampling;

@Override
public Node getContent() {
public Node getChartPanel(Stage stage) {

final DemoChart chart = new DemoChart();
chart.getRenderer(0).setDrawMarker(false);
Expand Down
Loading

0 comments on commit fb637bb

Please sign in to comment.