net.finmath.timeseries.TimeSeriesFromArray Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of finmath-lib Show documentation
Show all versions of finmath-lib Show documentation
finmath lib is a Mathematical Finance Library in Java.
It provides algorithms and methodologies related to mathematical finance.
package net.finmath.timeseries;
import java.util.Iterator;
/**
* A discrete time series.
*
* @author Christian Fries
* @version 1.0
*/
public class TimeSeriesFromArray implements TimeSeries {
private final double[] times;
private final double[] values;
public TimeSeriesFromArray(final double[] times, final double[] values) {
super();
this.times = times;
this.values = values;
}
@Override
public double getTime(final int index) {
return times[index];
}
@Override
public double getValue(final int index) {
return values[index];
}
@Override
public int getNumberOfTimePoints() {
return times.length;
}
@Override
public Iterable getValues() {
return new Iterable() {
private int index = 0;
@Override
public Iterator iterator() {
return new Iterator() {
@Override
public boolean hasNext() {
return index < TimeSeriesFromArray.this.getNumberOfTimePoints();
}
@Override
public Double next() {
return TimeSeriesFromArray.this.getValue(index++);
}
};
}
};
}
}