Added function to get possible moneyness for a given maturity/tenor pair
@@ -15,6 +15,8 @@ import java.util.function.DoubleUnaryOperator;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
+import org.apache.commons.math3.util.Pair;
+
import net.finmath.functions.AnalyticFormulas;
import net.finmath.marketdata.model.AnalyticModel;
import net.finmath.marketdata.products.Swap;
@@ -68,6 +70,7 @@ public class SwaptionDataLattice implements Serializable {
private final Map<DataKey, Double> entryMap = new HashMap<>();
private transient Map<Integer, int[][]> keyMap;
+ private transient Map<Pair<Integer, Integer>, int[]> reverseKeyMap;
/**
* Create the lattice.
@@ -354,6 +357,41 @@ public class SwaptionDataLattice implements Serializable {
return Collections.unmodifiableMap(keyMap);
}
+ /**
+ * Get a view of the locations of swaptions in this lattice.
+ * The keys of the map are pairs of maturities and tenors for which there are swaptions.
+ * The entries for each pair consist of an array of possible moneyness values, sorted in ascending order.
+ *
+ * @return The view of recorded swaptions.
+ */
+ public Map<Pair<Integer, Integer>, int[]> getMoneynessPerGridNode() {
+
+ //See if the map has already been instantiated.
+ if(reverseKeyMap != null) {
+ return Collections.unmodifiableMap(reverseKeyMap);
+ }
+
+ //Otherwise create the map and return it.
+ Map<Pair<Integer, Integer>, Set<Integer>> newMap = new HashMap<>();
+
+ for(DataKey key : entryMap.keySet()) {
+ Pair<Integer, Integer> maturityTenorPair = new Pair<Integer, Integer>(key.maturity, key.tenor);
+ if(! newMap.containsKey(maturityTenorPair)) {
+ newMap.put(maturityTenorPair, new HashSet<Integer>());
+ }
+ newMap.get(maturityTenorPair).add(key.moneyness);
+ }
+
+ Map<Pair<Integer, Integer>, int[]> reverseKeyMap = new TreeMap<>();
+ for(Pair<Integer, Integer> maturityTenorPair : newMap.keySet()) {
+ int[] values = newMap.get(maturityTenorPair).stream().sorted().mapToInt(Integer::intValue).toArray();
+
+ reverseKeyMap.put(maturityTenorPair, values);
+ }
+ this.reverseKeyMap = reverseKeyMap;
+ return Collections.unmodifiableMap(reverseKeyMap);
+ }
+
/**
* Return all levels of moneyness for which data exists.
*
