Example usage for java.lang Math PI

List of usage examples for java.lang Math PI

Introduction

In this page you can find the example usage for java.lang Math PI.

Prototype

double PI

To view the source code for java.lang Math PI.

Click Source Link

Document

The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.

Usage

From source file:com.opengamma.analytics.financial.model.option.pricing.fourier.FFTPricer.java

/**
 * Price a European option across a range of strikes using a FFT. The terminal price is assumed to be of the form S = F*exp(x), where F is the forward,
 * and x is a random variable with a known characteristic function.
 * @param forward The forward value of the underlying
 * @param discountFactor /*from   www .  j a  va2 s  .co m*/
 * @param t Time to expiry
 * @param isCall true for call 
 * @param ce The Characteristic Exponent (log of characteristic function) of the returns of the underlying
 * @param lowestStrike The lowest strike to return (the actual value will depend on the set up, but is guaranteed to be less than this) 
 * @param highestStrike The highest strike to return (the actual value will depend on the set up, but is guaranteed to be greater than this) 
 * @param minStrikesDisplayed minimum number of strikes returned (actual number depends on set up) 
 * @param limitSigma An estimate of the implied vol used to calculate limits in the numerical routines 
 * @param alpha Regularization factor. Values of 0 or -1 are not allowed. -0.5 is recommended  
 * @param tol Tolerance - smaller values give higher accuracy 
 * @return array of arrays of strikes and prices 
 */
public double[][] price(final double forward, final double discountFactor, final double t, final boolean isCall,
        final MartingaleCharacteristicExponent ce, final double lowestStrike, final double highestStrike,
        final int minStrikesDisplayed, final double limitSigma, final double alpha, final double tol) {

    Validate.notNull(ce, "characteristic exponent");
    Validate.isTrue(tol > 0.0, "need tol > 0");
    Validate.isTrue(alpha != 0.0 && alpha != -1.0, "alpha cannot be -1 or 0");
    Validate.isTrue(highestStrike >= lowestStrike, "need highestStrike >= lowestStrike");
    //   Validate.isTrue(lowestStrike <= forward, "need lowestStrike <= forward");
    //    Validate.isTrue(highestStrike >= forward, "need highestStrike >= forward");
    Validate.isTrue(limitSigma > 0.0, "need limitSigma > 0");

    double kMax;
    final double limitSigmaRootT = limitSigma * Math.sqrt(t);
    final double atm = NORMAL.getCDF(limitSigmaRootT / 2.0);

    if (alpha > 0) {
        kMax = -Math.log((2 * atm - 1) * tol) / alpha;
    } else if (alpha < -1.0) {
        kMax = Math.log((2 * atm - 1) * tol) / (1 + alpha);
    } else {
        kMax = -Math.log(2 * (1 - atm) * tol) * Math.max(-1.0 / alpha, 1 / (1 + alpha));
    }

    final EuropeanCallFourierTransform psi = new EuropeanCallFourierTransform(ce);
    final Function1D<ComplexNumber, ComplexNumber> psiFunction = psi.getFunction(t);
    final double xMax = LIMIT_CALCULATOR.solve(psiFunction, alpha, tol);

    double deltaK;
    if (highestStrike == lowestStrike) {
        deltaK = Math.PI / xMax;
    } else {
        deltaK = Math.min(Math.log(highestStrike / lowestStrike) / (minStrikesDisplayed - 1), Math.PI / xMax);
    }

    final double log2 = Math.log(2);
    final int twoPow = (int) Math.ceil(Math.log(kMax / deltaK) / log2);

    final int n = (int) Math.pow(2, twoPow);
    final double delta = 2 * Math.PI / n / deltaK;
    final int m = (int) (xMax * deltaK * n / 2 / Math.PI);

    final int nLowStrikes = (int) Math.max(0, Math.ceil(Math.log(forward / lowestStrike) / deltaK));
    final int nHighStrikes = (int) Math.max(0, Math.ceil(Math.log(highestStrike / forward) / deltaK));

    return price(forward, discountFactor, t, isCall, ce, nLowStrikes, nHighStrikes, alpha, delta, n, m);
}

From source file:PointTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 14000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(getApplicationBounds());
    objTrans.addChild(rotator);//from  w  w  w  .  j av a2  s  .c om

    Switch switchGroup = new Switch();
    switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE);

    switchGroup.addChild(createPoints(1, 5, false));
    switchGroup.addChild(createPoints(1, 5, true));
    switchGroup.addChild(createPoints(8, 10, false));
    switchGroup.addChild(createPoints(8, 10, true));

    switchGroup.addChild(createPoints(2, 5, false));
    switchGroup.addChild(createPoints(2, 5, true));
    switchGroup.addChild(createPoints(2, 20, false));
    switchGroup.addChild(createPoints(2, 20, true));

    // create a SwitchValueInterpolator to
    // cycle through the child nodes in the Switch Node
    Alpha switchAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 15000, 0, 0, 0, 0, 0);

    SwitchValueInterpolator switchInterpolator = new SwitchValueInterpolator(switchAlpha, switchGroup);
    switchInterpolator.setSchedulingBounds(getApplicationBounds());
    switchInterpolator.setEnable(true);

    // WARNING: do not add the SwitchValueInterpolator to the Switch Node!
    objRoot.addChild(switchInterpolator);

    objTrans.addChild(switchGroup);
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:org.mili.jmibs.jfree.JFreeChartBarIterationIntervalBenchmarkSuiteResultRenderer.java

private JFreeChart createChart(String title, CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(title, "Benchmark (Iteration/Interval)", "Time in ns",
            dataset, PlotOrientation.HORIZONTAL, true, true, false);
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);/*from  w ww . j  a  v  a 2 s  .c  o  m*/
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    return chart;
}

From source file:gdsc.smlm.function.PoissonGammaGaussianFunction.java

/**
 * Initialise the function.// w w w . j a va  2 s  .  c  o  m
 * <p>
 * The input parameters must be the full parameters for the non-linear function. Only those parameters with gradient
 * indices should be passed in to the functions to obtain the value (and gradient).
 * <p>
 * Note: Negative parameters are made absolute
 * 
 * @param alpha
 *            Inverse gain of the EMCCD chip
 * @param s
 *            The Gaussian standard deviation
 */
public PoissonGammaGaussianFunction(double alpha, double s) {
    this.alpha = Math.abs(alpha);
    this.sigma = Math.abs(s);
    twoSigma2 = 2 * s * s;
    sqrt2sigma2 = Math.sqrt(2 * s * s);
    sqrt2piSigma2 = Math.sqrt(2 * Math.PI * s * s);
}

From source file:org.jfree.demo.DrawStringDemo.java

/**
 * Receives property change events.//w  w w  .  j  ava2  s.co m
 *
 * @param event  the event.
 */
public void propertyChange(final PropertyChangeEvent event) {
    final int r = this.spinner.getValue();
    final double angle = Math.PI * 2.0 * (r / 360.0);
    this.drawStringPanel2.setAngle(angle);
    this.drawStringPanel2.invalidate();
    this.drawStringPanel2.repaint();
}

From source file:electrical_parameters.Rac_calculation.java

private double k_sk_d(double rho, double D, double f) {
    //        System.out.println("k_sk_d");
    //        System.out.println((pow(D,2)*Math.PI*EIR(rho,D,f))/(4*rho));
    return (pow(D, 2) * Math.PI * EIR(rho, D, f)) / (4 * rho);
}

From source file:org.jfree.chart.demo.CombinedXYPlotDemo4.java

/**
 * Creates a combined chart.//from  w  w w .j  a  v a 2  s  .  c  o  m
 *
 * @return The combined chart.
 */
private JFreeChart createCombinedChart() {

    // create subplot 1...
    final XYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // add secondary axis
    subplot1.setDataset(1, createDataset2());
    final NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    subplot1.setRangeAxis(1, axis2);
    subplot1.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    subplot1.setRenderer(1, new StandardXYItemRenderer());
    subplot1.mapDatasetToRangeAxis(1, 1);

    final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);

    // create subplot 2...
    final XYDataset data2 = createDataset2();
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot...
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
    plot.setGap(10.0);

    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}

From source file:Demo.LineGraph.java

private void InitChart() {
    JFreeChart chart = ChartFactory.createLineChart("Yield", "sample NB", "Probability", dataSet,
            PlotOrientation.VERTICAL, false, false, false);

    CategoryPlot plot = chart.getCategoryPlot();

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    plot.setDomainGridlinesVisible(true);
    plot.setNoDataMessage("no data");

    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();

    renderer.setBaseItemLabelsVisible(true);
    renderer.setSeriesPaint(0, Color.BLUE);

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);//from  w ww  . ja va 2  s . com

    renderer.setBaseItemLabelsVisible(true);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelFont(new Font("Times New Romain", 0, 10));
    plot.setRenderer(renderer);

    CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createDownRotationLabelPositions(Math.PI / 6.0));

    chartPane = new ChartPanel(chart);
}

From source file:com.csc.GUI.ProfileGUIPanel.java

private JFreeChart createBarChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Expenses Statistics", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from   w ww  .j  av a2  s.com*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}

From source file:SimpleDirLight.java

/**
 * This build the content branch of our scene graph. It creates a transform
 * group so that the shape is slightly tilted to reveal its 3D shape.
 * /*from  w  w  w.j av  a  2 s.  c om*/
 * @param shape
 *            Node that represents the geometry for the content
 * @return BranchGroup that is the root of the content branch
 */
protected BranchGroup buildContentBranch() {
    BranchGroup contentBranch = new BranchGroup();
    Transform3D rotateCube = new Transform3D();
    rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
    TransformGroup rotationGroup = new TransformGroup(rotateCube);
    contentBranch.addChild(rotationGroup);
    //Create a new appearance
    Appearance app = new Appearance();
    //Create the colours for the material
    Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);
    //Define the shininess
    float shininess = 20.0f;
    //Set the material of the appearance
    app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));
    //Create and add a new sphere using the appearance
    rotationGroup.addChild(new Sphere(2.0f, Sphere.GENERATE_NORMALS, 120, app));
    //Use the addLights function to add the lights to the branch
    addLights(contentBranch);
    //Return the root of the content branch
    return contentBranch;
}