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

net.finmath.time.TimeDiscretization Maven / Gradle / Ivy

Go to download

finmath lib is a Mathematical Finance Library in Java. It provides algorithms and methodologies related to mathematical finance.

There is a newer version: 6.0.19
Show newest version
/*
 * (c) Copyright Christian P. Fries, Germany. All rights reserved. Contact: [email protected].
 *
 * Created on 20.04.2008
 */
package net.finmath.time;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

/**
 * This class represents a set of discrete points in time.
 * 
* It handles the mapping from time indices to time points and back. * It uses a time tick size ("quantum") of 1.0 / (365.0 * 24.0) (which corresponds to one hour if 1.0 is a non-leap-year): * Times are rounded to the nearest multiple of 1.0 / (365.0 * 24.0). * * Objects of this class are immutable. * * @author Christian Fries * @version 1.5 */ public class TimeDiscretization implements Serializable, TimeDiscretizationInterface { private static final long serialVersionUID = 6880668325019167781L; private final double[] timeDiscretization; private final double timeTickSize = 1.0 / (365.0 * 24.0); public enum ShortPeriodLocation { SHORT_PERIOD_AT_START, SHORT_PERIOD_AT_END } /** * Constructs a time discretization from a given set of doubles. * * @param times Given array or arguments list of discretization points. */ public TimeDiscretization(double... times) { super(); this.timeDiscretization = times.clone(); java.util.Arrays.sort(this.timeDiscretization); } /** * Constructs a time discretization from a given set of Doubles. * * @param times Given array or arguments list of discretization points */ public TimeDiscretization(Double[] times) { super(); this.timeDiscretization = new double[times.length]; for(int timeIndex=0; timeIndex timeDiscretization) { super(); this.timeDiscretization = new double[timeDiscretization.size()]; for(int timeIndex=0; timeIndexfor(i=0; i ≤ timeSteps; i++) timeDiscretization[i] = initial + i * deltaT;
* * @param initial First discretization point. * @param numberOfTimeSteps Number of time steps. * @param deltaT Time step size. */ public TimeDiscretization(double initial, int numberOfTimeSteps, double deltaT) { super(); timeDiscretization = new double[numberOfTimeSteps+1]; for(int timeIndex=0; timeIndex getAsArrayList() { ArrayList times = new ArrayList(timeDiscretization.length); for (double aTimeDiscretization : timeDiscretization) times.add(aTimeDiscretization); return times; } @Override public TimeDiscretizationInterface getTimeShiftedTimeDiscretization(double timeShift) { double[] newTimeDiscretization = new double[timeDiscretization.length]; for(int timeIndex=0; timeIndex iterator() { return this.getAsArrayList().iterator(); } @Override public String toString() { return "TimeDiscretization [timeDiscretization=" + Arrays.toString(timeDiscretization) + ", timeTickSize=" + timeTickSize + "]"; } private double roundToTimeTickSize(double time) { return Math.rint(time/timeTickSize)*timeTickSize; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy