All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.finmath.plots.demo.Plot2DDemo3 Maven / Gradle / Ivy

Go to download

finmath lib plot extensions provide convenient plotting methods by providing consistent wrappers to plot libraries (like JFreeChart or JavaFX).

The newest version!
/*
 * (c) Copyright Christian P. Fries, Germany. All rights reserved. Contact: [email protected].
 *
 * Created on 21 May 2018
 */

package net.finmath.plots.demo;

import java.awt.Color;
import java.awt.Rectangle;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.function.DoubleUnaryOperator;

import net.finmath.marketdata.model.curves.Curve;
import net.finmath.marketdata.model.curves.locallinearregression.CurveEstimation;
import net.finmath.plots.GraphStyle;
import net.finmath.plots.Named;
import net.finmath.plots.Plot2D;
import net.finmath.plots.Plotable2D;
import net.finmath.plots.PlotableFunction2D;
import net.finmath.plots.PlotablePoints2D;
import net.finmath.plots.Point2D;

/**
 * Plots the regression estimation of a curve.
 *
 * @author Christian Fries
 */
public class Plot2DDemo3 {

	/**
	 * Run the demo.
	 *
	 * @param args Not used.
	 * @throws Exception Exception from the graphics backend.
	 */
	public static void main(final String[] args) throws Exception {

		final LocalDate date = LocalDate.now();

		final Plot2D plot = new Plot2D(new ArrayList());
		plot
		.setXAxisLabel("time")
		.setYAxisLabel("value")
		.setIsLegendVisible(true)
		.show();

		for(int bandwidthIndex=20; bandwidthIndex>=0; bandwidthIndex--) {
			final double bandwidth = 10.0+bandwidthIndex*5;

			final Random random = new Random(3141);
			final int numberOfSamplePoints = 100;
			final double[] xValues = new double[numberOfSamplePoints];
			final double[] yValues = new double[numberOfSamplePoints];
			for(int i=0; i {
				return regressionCurve.getValue(x);
			};

			final List series = new ArrayList();
			for(int i=0; i plotables = Arrays.asList(
					new PlotableFunction2D(0.0, 360.0, 1000, new Named("Regression Curve", function), null),
					new PlotablePoints2D("Values", series, new GraphStyle(new Rectangle(2, 2), null, Color.BLUE))
					);

			plot
			.setTitle("Local Linear Regression (bandwidth = " + bandwidth + ")")
			.update(plotables);

			Thread.sleep(500);
		}

		// plot.saveAsPDF(new File("LocalLinearRegression-" + bandwidth + ".pdf"), 800, 600);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy