generateInitialSettlementResult(InitialSettlementRequest initialSettlementRequest) {
+ logger.info("Generating initial settlement result, generateInitialSettlementResult");
+ InitialSettlementResult initialSettlementResult = settlementService.generateInitialSettlementResult(initialSettlementRequest);
+ return ResponseEntity.ok(initialSettlementResult);
+ }
+}
diff --git a/src/main/java/net/finmath/smartcontract/valuation/service/controllers/ValuationController.java b/src/main/java/net/finmath/smartcontract/valuation/service/controllers/ValuationController.java
index a58e57e30..7c290675e 100644
--- a/src/main/java/net/finmath/smartcontract/valuation/service/controllers/ValuationController.java
+++ b/src/main/java/net/finmath/smartcontract/valuation/service/controllers/ValuationController.java
@@ -8,8 +8,8 @@
package net.finmath.smartcontract.valuation.service.controllers;
import net.finmath.smartcontract.api.ValuationApi;
-import net.finmath.smartcontract.valuation.client.ValuationClient;
import net.finmath.smartcontract.model.*;
+import net.finmath.smartcontract.valuation.client.ValuationClient;
import net.finmath.smartcontract.valuation.implementation.MarginCalculator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/src/main/java/net/finmath/smartcontract/valuation/service/utils/SDCAbstractRounding.java b/src/main/java/net/finmath/smartcontract/valuation/service/utils/SDCAbstractRounding.java
new file mode 100644
index 000000000..266f13b7e
--- /dev/null
+++ b/src/main/java/net/finmath/smartcontract/valuation/service/utils/SDCAbstractRounding.java
@@ -0,0 +1,77 @@
+/**
+ * SDC Project
+ *
+ * @author Dietmar Schnabel
+ *
+ * This class implements some number rounding according to business conventions.
+ *
+ */
+ package net.finmath.smartcontract.valuation.service.utils;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+/**
+ * The Class SDCAbstractRounding
+ *
+ * Contains general rounding methods, as well as converting to strings.
+ */
+public abstract class SDCAbstractRounding {
+
+ protected int scale;
+ protected RoundingMode roundingMode;
+
+ private BigDecimal round(double variable) {
+ String s = Double.toString(variable);
+ return new BigDecimal(s).setScale(scale, roundingMode);
+ }
+
+ /**
+ * Round double.
+ *
+ * @param variable the double var
+ * @return the rounded double
+ */
+ public double roundDouble(double variable) {
+ return round(variable).doubleValue();
+ }
+
+ private String getAsIntString(BigDecimal variable) {
+ String margin = variable.toString();
+ return margin.replace(".","");
+ }
+
+ /**
+ * Returns an integer value, the double left shifted
+ *
+ * @param variable the double var
+ * @return the double as integer string
+ */
+ public String getRoundedValueAsIntegerString(double variable) {
+ BigDecimal x = round(variable);
+ return getAsIntString(x);
+ }
+
+ /**
+ * Gets the double from the left shifted integer String
+ *
+ * @param s the integer string
+ * @return the double
+ */
+ public double getDoubleFromIntegerString(String s) {
+ String sf = null;
+
+ if (s.length()==1) {
+ sf = "0.0" + s; //TODO introduce scale
+ } else if (s.length()==2) {
+ sf = "0." + s;
+ } else {
+ int i1 = s.length() - scale -1;
+ int i2 = s.length() -1;
+ sf = s.substring(0,i1+1) + "." + s.substring(i1+1,i2+1);
+ }
+
+ double x = Double.parseDouble(sf);
+ return roundDouble(x);
+ }
+}
diff --git a/src/main/java/net/finmath/smartcontract/valuation/service/utils/SDCRounding.java b/src/main/java/net/finmath/smartcontract/valuation/service/utils/SDCRounding.java
new file mode 100644
index 000000000..ec368895c
--- /dev/null
+++ b/src/main/java/net/finmath/smartcontract/valuation/service/utils/SDCRounding.java
@@ -0,0 +1,19 @@
+package net.finmath.smartcontract.valuation.service.utils;
+
+import java.math.RoundingMode;
+/**
+ * The Class SDCRounding.
+ *
+ * Concrete implementation of the SDCAbstractRounding class.
+ * Will be currency dependent.
+ * */
+public class SDCRounding extends SDCAbstractRounding {
+
+ private SDCRounding() { }
+
+ public SDCRounding(int sc, RoundingMode rc) {
+ scale = sc;
+ roundingMode = rc;
+ }
+
+}
diff --git a/src/main/java/net/finmath/smartcontract/valuation/service/utils/SettlementService.java b/src/main/java/net/finmath/smartcontract/valuation/service/utils/SettlementService.java
new file mode 100644
index 000000000..5341ca489
--- /dev/null
+++ b/src/main/java/net/finmath/smartcontract/valuation/service/utils/SettlementService.java
@@ -0,0 +1,229 @@
+package net.finmath.smartcontract.valuation.service.utils;
+
+import net.finmath.smartcontract.model.*;
+import net.finmath.smartcontract.product.SmartDerivativeContractDescriptor;
+import net.finmath.smartcontract.product.xml.SDCXMLParser;
+import net.finmath.smartcontract.product.xml.Smartderivativecontract;
+import net.finmath.smartcontract.settlement.Settlement;
+import net.finmath.smartcontract.settlement.SettlementGenerator;
+import net.finmath.smartcontract.valuation.implementation.MarginCalculator;
+import net.finmath.smartcontract.valuation.marketdata.data.MarketDataPoint;
+import net.finmath.smartcontract.valuation.marketdata.generators.MarketDataGeneratorLauncher;
+import net.finmath.smartcontract.valuation.marketdata.generators.MarketDataGeneratorScenarioList;
+import net.finmath.smartcontract.valuation.service.config.RefinitivConfig;
+import net.finmath.smartcontract.valuation.service.config.ValuationConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
+
+@Service
+public class SettlementService {
+ private static final Logger logger = LoggerFactory.getLogger(SettlementService.class);
+
+ private final MarginCalculator marginCalculator = new MarginCalculator();
+
+ private final RefinitivConfig refinitivConfig;
+ private final ValuationConfig valuationConfig;
+ private final MarketDataGeneratorScenarioList marketDataServiceScenarioList;
+
+ public SettlementService(RefinitivConfig refinitivConfig, ValuationConfig valuationConfig) {
+ this.refinitivConfig = refinitivConfig;
+ this.valuationConfig = valuationConfig;
+ this.marketDataServiceScenarioList = new MarketDataGeneratorScenarioList();
+ }
+
+ public RegularSettlementResult generateRegularSettlementResult(RegularSettlementRequest regularSettlementRequest) {
+ logger.info("Generating regular settlement result, liveData: {}, now parsing trade data", valuationConfig.isLiveMarketData());
+ SmartDerivativeContractDescriptor sdc = parseProductData(regularSettlementRequest.getTradeData());
+ logger.info("generateRegularSettlementResult - sdc trade id: {}, product marketdata provider: {}, valuation service marketdata provider: {}", sdc.getDltTradeId(), sdc.getMarketDataProvider(), valuationConfig.getLiveMarketDataProvider());
+ MarketDataList newMarketDataList = retrieveMarketData(sdc);
+ includeFixingsOfLastSettlement(regularSettlementRequest, newMarketDataList);
+ String newMarketDataString = SDCXMLParser.marshalClassToXMLString(newMarketDataList);
+ Settlement settlementLast = SDCXMLParser.unmarshalXml(regularSettlementRequest.getSettlementLast(), Settlement.class);
+ String marketDataLastString = SDCXMLParser.marshalClassToXMLString(settlementLast.getMarketData());
+ logger.info("generateRegularSettlementResult - newMarketDataString: {}", newMarketDataString);
+
+ // TODO Using now here is a bit strange in the unit test. Results will vary.
+ ZonedDateTime settlementTimeNext = ZonedDateTime.now().plusDays(1);
+
+ ValueResult settlementValueNext = getValuationValueAtTime(
+ newMarketDataString, regularSettlementRequest.getTradeData(), settlementTimeNext.toLocalDateTime());
+
+ Map marginValues = getMargin(marketDataLastString, newMarketDataString, regularSettlementRequest.getTradeData());
+ BigDecimal margin = marginValues.get("value");
+
+ String newSettlement = new SettlementGenerator()
+ .generateRegularSettlementXml(
+ newMarketDataString,
+ sdc,
+ margin)
+ .marginLimits(settlementLast.getMarginLimits())
+ .settlementNPV(getValue(newMarketDataString, regularSettlementRequest.getTradeData()))
+ .settlementNPVPrevious(settlementLast.getSettlementNPV())
+ .settlementTimeNext(settlementTimeNext)
+ .settlementNPVNext(settlementValueNext.getValue())
+ .settlementInfo(marginValues)
+ .build();
+
+ return new RegularSettlementResult()
+ .generatedRegularSettlement(newSettlement)
+ .currency(valuationConfig.getSettlementCurrency())
+ .marginValue(margin)
+ .valuationDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss")));
+ }
+
+ public InitialSettlementResult generateInitialSettlementResult(InitialSettlementRequest initialSettlementRequest) {
+ logger.info("Generating initial settlement result, liveData: {}, now parsing trade data", valuationConfig.isLiveMarketData());
+ SmartDerivativeContractDescriptor sdc = parseProductData(initialSettlementRequest.getTradeData());
+ logger.info("generateInitialSettlementResult- sdc trade id: {}, product marketdata provider: {}, valuation service marketdata provider: {}", sdc.getDltTradeId(), sdc.getMarketDataProvider(), valuationConfig.getLiveMarketDataProvider());
+ MarketDataList newMarketDataList = retrieveMarketData(sdc);
+ String newMarketDataString = SDCXMLParser.marshalClassToXMLString(newMarketDataList);
+ logger.debug("generateInitialSettlementResult- newMarketDataString: {}", newMarketDataString);
+
+ ZonedDateTime settlementTimeNext = ZonedDateTime.now().plusDays(1);
+
+ ValueResult settlementValueNext = getValuationValueAtTime(
+ newMarketDataString, initialSettlementRequest.getTradeData(), settlementTimeNext.toLocalDateTime());
+
+ List marginLimits = new ArrayList<>();
+ sdc.getCounterparties().forEach(party -> marginLimits.add(BigDecimal.valueOf(sdc.getMarginAccount(party.getId()))));
+
+ String newSettlement = new SettlementGenerator()
+ .generateInitialSettlementXml(newMarketDataString, sdc)
+ .marginLimits(marginLimits)
+ .settlementNPV(getValue(newMarketDataString, initialSettlementRequest.getTradeData()))
+ //.settlementValuePrevious(BigDecimal.ZERO)
+ .settlementTimeNext(settlementTimeNext)
+ .settlementNPVNext(settlementValueNext.getValue())
+ .settlementInfo(Map.of())
+ .build();
+
+ return new InitialSettlementResult()
+ .generatedInitialSettlement(newSettlement)
+ .currency(valuationConfig.getSettlementCurrency())
+ .marginValue(BigDecimal.ZERO)
+ .valuationDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss")));
+ }
+
+
+ private static SmartDerivativeContractDescriptor parseProductData(String tradeData) {
+ try {
+ return SDCXMLParser.parse(tradeData);
+ } catch (ParserConfigurationException | IOException | SAXException e) {
+ logger.error("error parsing product data ", e);
+ throw new SDCException(ExceptionId.SDC_XML_PARSE_ERROR, "product data format incorrect, could not parse xml", 400);
+ }
+ }
+
+ private MarketDataList retrieveMarketData(SmartDerivativeContractDescriptor sdc) {
+ AtomicReference marketDataList = new AtomicReference<>(new MarketDataList());
+ logger.info("retrieveMarketData started for trade: {}", sdc.getDltTradeId());
+
+ if (sdc.getMarketDataProvider().equals(valuationConfig.getLiveMarketDataProvider()) && valuationConfig.isLiveMarketData()) {
+ logger.info("using live market data provider");
+ marketDataList.set(MarketDataGeneratorLauncher.instantiateMarketDataGeneratorWebsocket(initConnectionProperties(), sdc));
+ } else if (sdc.getMarketDataProvider().equals(valuationConfig.getInternalMarketDataProvider())) {
+ logger.info("using internal market data provider");
+ //includes provider internal or no liveMarketData activated
+ final io.reactivex.rxjava3.functions.Consumer marketDataWriter = marketDataList::set;
+ marketDataServiceScenarioList.asObservable().subscribe(marketDataWriter, //onNext
+ throwable -> logger.error("unable to generate marketData from files ", throwable), //onError
+ () -> logger.info("on complete, simulated marketData generated from files")); //onComplete
+ } else {
+ logger.error("unable to retrieve marketData for {}", sdc.getDltTradeId());
+ throw new SDCException(ExceptionId.SDC_WRONG_INPUT,
+ "Product data XML is not compatible with valuation service configuration, see logs for further investigation", 400);
+ }
+ return marketDataList.get();
+ }
+
+ private Properties initConnectionProperties() {
+ try {
+ Properties connectionProperties = new Properties();
+ connectionProperties.put("USER", refinitivConfig.getUser());
+ connectionProperties.put("PASSWORD", refinitivConfig.getPassword());
+ connectionProperties.put("CLIENTID", refinitivConfig.getClientId());
+ connectionProperties.put("HOSTNAME", refinitivConfig.getHostName());
+ connectionProperties.put("PORT", refinitivConfig.getPort());
+ connectionProperties.put("AUTHURL", refinitivConfig.getAuthUrl());
+ connectionProperties.put("USEPROXY", refinitivConfig.getUseProxy());
+ connectionProperties.put("PROXYHOST", refinitivConfig.getProxyHost());
+ connectionProperties.put("PROXYPORT", refinitivConfig.getProxyPort());
+ connectionProperties.put("PROXYUSER", refinitivConfig.getProxyUser());
+ connectionProperties.put("PROXYPASS", refinitivConfig.getProxyPassword());
+
+ return connectionProperties;
+ } catch (NullPointerException e) {
+ logger.error("refinitiv connection properties not set", e);
+ throw new SDCException(ExceptionId.SDC_NO_DATA_FOUND, "missing connection properties", 400);
+ }
+ }
+
+ private ValueResult getValuationValueAtTime(String marketData, String tradeData, LocalDateTime valuationDate) {
+ try {
+ return marginCalculator.getValueAtEvaluationTime(marketData, tradeData, valuationDate);
+ } catch (Exception e) {
+ logger.error("unable to get valueAtTime for market data ", e);
+ throw new SDCException(ExceptionId.SDC_VALUE_CALCULATION_ERROR, "error in MarginCalculator getValueAtTime");
+ }
+ }
+
+ private BigDecimal getValue(String marketData, String tradeData) {
+ try {
+ return marginCalculator.getValue(marketData, tradeData).getValue();
+ } catch (Exception e) {
+ logger.error("unable to get value for market data ", e);
+ throw new SDCException(ExceptionId.SDC_VALUE_CALCULATION_ERROR, "error in MarginCalculator getValue");
+ }
+ }
+
+ private Map getMargin(String marketDataStart, String marketDataEnd, String tradeData) {
+ try {
+ return marginCalculator.getValues(marketDataStart, marketDataEnd, tradeData);
+ } catch (Exception e) {
+ logger.error("unable to get margin for market data ", e);
+ throw new SDCException(ExceptionId.SDC_VALUE_CALCULATION_ERROR, "error in MarginCalculator getMargin");
+ }
+ }
+
+ private void includeFixingsOfLastSettlement(RegularSettlementRequest regularSettlementRequest, MarketDataList newMarketDataList) {
+ //searching for Fixings in the sdc product data XML
+ Smartderivativecontract sdc = SDCXMLParser.unmarshalXml(regularSettlementRequest.getTradeData(), Smartderivativecontract.class);
+ Optional symbolsOptional = sdc.getSettlement().getMarketdata()
+ .getMarketdataitems().getItem().stream().filter(
+ item -> item.getType().get(0).equalsIgnoreCase(valuationConfig.getProductFixingType()))
+ .findAny();
+ List symbols;
+
+ if(symbolsOptional.isPresent()) {symbols = symbolsOptional.get().getSymbol();}
+ else {
+ logger.warn("no Fixings found in SDC product data XML, marketDataList not changed");
+ return;
+ }
+ logger.info("found symbols in product data XML: {}", symbols);
+
+ //matching symbols from product data xml to last settlement xml marketdataPoints
+ Settlement settlementLast = SDCXMLParser.unmarshalXml(regularSettlementRequest.getSettlementLast(), Settlement.class);
+ List fixingsLastSettlement = new ArrayList<>();
+ symbols.forEach(s -> settlementLast.getMarketData().getPoints().forEach(marketDataPoint -> {
+ if (marketDataPoint.getId().equalsIgnoreCase(s))
+ fixingsLastSettlement.add(marketDataPoint);
+ }));
+
+ //add matching marketdataPoints to the new marketdata
+ logger.info("add matching marketdataPoints to product symbols: {}", fixingsLastSettlement);
+ for (MarketDataPoint marketDataPoint : fixingsLastSettlement) {
+ newMarketDataList.add(marketDataPoint);
+ }
+ }
+}
diff --git a/src/main/java/net/finmath/smartcontract/valuation/service/websocket/handler/ValuationHandler.java b/src/main/java/net/finmath/smartcontract/valuation/service/websocket/handler/ValuationHandler.java
index 0dc42a6f3..84bef150b 100644
--- a/src/main/java/net/finmath/smartcontract/valuation/service/websocket/handler/ValuationHandler.java
+++ b/src/main/java/net/finmath/smartcontract/valuation/service/websocket/handler/ValuationHandler.java
@@ -2,13 +2,13 @@
import com.neovisionaries.ws.client.WebSocket;
import io.reactivex.rxjava3.core.Observable;
-import net.finmath.smartcontract.valuation.marketdata.generators.MarketDataGeneratorWebsocket;
-import net.finmath.smartcontract.valuation.marketdata.generators.WebSocketConnector;
-import net.finmath.smartcontract.valuation.marketdata.curvecalibration.CalibrationDataItem;
import net.finmath.smartcontract.model.ValueResult;
import net.finmath.smartcontract.product.SmartDerivativeContractDescriptor;
import net.finmath.smartcontract.product.xml.SDCXMLParser;
import net.finmath.smartcontract.valuation.implementation.MarginCalculator;
+import net.finmath.smartcontract.valuation.marketdata.curvecalibration.CalibrationDataItem;
+import net.finmath.smartcontract.valuation.marketdata.generators.MarketDataGeneratorWebsocket;
+import net.finmath.smartcontract.valuation.marketdata.generators.WebSocketConnector;
import org.springframework.web.socket.*;
import java.io.FileInputStream;
diff --git a/src/main/resources/SettlementExample.xml b/src/main/resources/SettlementExample.xml
new file mode 100644
index 000000000..d8bdda95a
--- /dev/null
+++ b/src/main/resources/SettlementExample.xml
@@ -0,0 +1,337 @@
+
+
+ ID-historical123
+ REGULAR
+ EUR
+ 49044.15
+ -50000
+ 50000
+ 20241118-152508
+ -752.94
+ 18937.55
+ 20241119-152506
+ -752.94
+
+ 20080502-170000
+ -
+ EUB6FIX6M
+ 0.0484
+ 20080502-170000
+
+ -
+ ESTRSWP3W
+ 0.04
+ 20080502-170000
+
+ -
+ ESTRSWP1W
+ 0.0398
+ 20080502-170000
+
+ -
+ ESTRSWP2W
+ 0.04
+ 20080502-170000
+
+ -
+ ESTRSWP1M
+ 0.0404
+ 20080502-170000
+
+ -
+ ESTRSWP2M
+ 0.0407
+ 20080502-170000
+
+ -
+ ESTRSWP3M
+ 0.0401
+ 20080502-170000
+
+ -
+ ESTRSWP4M
+ 0.0407
+ 20080502-170000
+
+ -
+ ESTRSWP5M
+ 0.0406
+ 20080502-170000
+
+ -
+ ESTRSWP6M
+ 0.0403
+ 20080502-170000
+
+ -
+ ESTRSWP7M
+ 0.0407
+ 20080502-170000
+
+ -
+ ESTRSWP8M
+ 0.0404
+ 20080502-170000
+
+ -
+ ESTRSWP9M
+ 0.0401
+ 20080502-170000
+
+ -
+ ESTRSWP10M
+ 0.0406
+ 20080502-170000
+
+ -
+ ESTRSWP11M
+ 0.04
+ 20080502-170000
+
+ -
+ EUB6SWP1Y
+ 0.0483
+ 20080502-170000
+
+ -
+ ESTRSWP12M
+ 0.0408
+ 20080502-170000
+
+ -
+ ESTRSWP15M
+ 0.0402
+ 20080502-170000
+
+ -
+ ESTRSWP18M
+ 0.0396
+ 20080502-170000
+
+ -
+ EUB6SWP2Y
+ 0.0457
+ 20080502-170000
+
+ -
+ ESTRSWP2Y
+ 0.0398
+ 20080502-170000
+
+ -
+ EUB6SWP3Y
+ 0.0445
+ 20080502-170000
+
+ -
+ ESTRSWP3Y
+ 0.0399
+ 20080502-170000
+
+ -
+ EUB6SWP4Y
+ 0.0442
+ 20080502-170000
+
+ -
+ ESTRSWP4Y
+ 0.0406
+ 20080502-170000
+
+ -
+ EUB6SWP5Y
+ 0.0442
+ 20080502-170000
+
+ -
+ ESTRSWP5Y
+ 0.0406
+ 20080502-170000
+
+ -
+ EUB6SWP6Y
+ 0.0446
+ 20080502-170000
+
+ -
+ ESTRSWP6Y
+ 0.0407
+ 20080502-170000
+
+ -
+ EUB6SWP7Y
+ 0.0453
+ 20080502-170000
+
+ -
+ ESTRSWP7Y
+ 0.0414
+ 20080502-170000
+
+ -
+ EUB6SWP8Y
+ 0.0451
+ 20080502-170000
+
+ -
+ ESTRSWP8Y
+ 0.0419
+ 20080502-170000
+
+ -
+ EUB6SWP9Y
+ 0.0462
+ 20080502-170000
+
+ -
+ ESTRSWP9Y
+ 0.0422
+ 20080502-170000
+
+ -
+ EUB6SWP10Y
+ 0.0466
+ 20080502-170000
+
+ -
+ ESTRSWP10Y
+ 0.0427
+ 20080502-170000
+
+ -
+ EUB6SWP11Y
+ 0.0472
+ 20080502-170000
+
+ -
+ EUB6SWP12Y
+ 0.047
+ 20080502-170000
+
+ -
+ EUB6SWP13Y
+ 0.0481
+ 20080502-170000
+
+ -
+ EUB6SWP14Y
+ 0.0481
+ 20080502-170000
+
+ -
+ EUB6SWP15Y
+ 0.048
+ 20080502-170000
+
+ -
+ EUB6SWP16Y
+ 0.0483
+ 20080502-170000
+
+ -
+ EUB6SWP17Y
+ 0.0483
+ 20080502-170000
+
+ -
+ EUB6SWP18Y
+ 0.0483
+ 20080502-170000
+
+ -
+ EUB6SWP19Y
+ 0.0493
+ 20080502-170000
+
+ -
+ EUB6SWP20Y
+ 0.0489
+ 20080502-170000
+
+ -
+ EUB6SWP21Y
+ 0.0489
+ 20080502-170000
+
+ -
+ EUB6SWP22Y
+ 0.0488
+ 20080502-170000
+
+ -
+ EUB6SWP23Y
+ 0.0485
+ 20080502-170000
+
+ -
+ EUB6SWP24Y
+ 0.0487
+ 20080502-170000
+
+ -
+ EUB6SWP25Y
+ 0.0493
+ 20080502-170000
+
+ -
+ EUB6SWP26Y
+ 0.0491
+ 20080502-170000
+
+ -
+ EUB6SWP27Y
+ 0.0483
+ 20080502-170000
+
+ -
+ EUB6SWP28Y
+ 0.049
+ 20080502-170000
+
+ -
+ EUB6SWP29Y
+ 0.0485
+ 20080502-170000
+
+ -
+ EUB6SWP30Y
+ 0.0483
+ 20080502-170000
+
+ -
+ EUB6SWP35Y
+ 0.0485
+ 20080502-170000
+
+ -
+ EUB6SWP40Y
+ 0.0477
+ 20080502-170000
+
+ -
+ EUB6SWP45Y
+ 0.0474
+ 20080502-170000
+
+ -
+ EUB6SWP50Y
+ 0.0481
+ 20080502-170000
+
+ -
+ EUB6SWP60Y
+ 0.047
+ 20080502-170000
+
+ -
+ EUB6FIX6M
+ 0.0521
+ 20080917-170000
+
+
+
+ -111894.26
+ -62850.11
+ 49044.15
+
+
diff --git a/src/main/resources/api.yml b/src/main/resources/api.yml
index 0cb03b656..a13c78214 100644
--- a/src/main/resources/api.yml
+++ b/src/main/resources/api.yml
@@ -504,12 +504,62 @@ paths:
schema:
$ref: "#/components/schemas/Error"
+
+ /settlement/generate-regular-settlement:
+ post:
+ summary: generate a regular settlement xml based on given settlement and product xml
+ operationId: generateRegularSettlementResult
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/RegularSettlementRequest"
+ responses:
+ "200":
+ description: regular settlement xml was created
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/RegularSettlementResult"
+ default:
+ description: unexpected error
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Error"
+
+ /settlement/generate-initial-settlement:
+ post:
+ summary: generate an initial settlement xml based on given product xml
+ operationId: generateInitialSettlementResult
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/InitialSettlementRequest"
+ responses:
+ "200":
+ description: initial settlement xml was created
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/InitialSettlementResult"
+ default:
+ description: unexpected error
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Error"
components:
schemas:
ValueResult:
$ref: "schemas/openapi-schemas/ValueResult.yml"
MarginResult:
$ref: "schemas/openapi-schemas/MarginResult.yml"
+ RegularSettlementResult:
+ $ref: "schemas/openapi-schemas/RegularSettlementResult.yml"
+ InitialSettlementResult:
+ $ref: "schemas/openapi-schemas/InitialSettlementResult.yml"
Error:
$ref: "schemas/openapi-schemas/Error.yml"
PlainSwapOperationResponse:
@@ -518,6 +568,10 @@ components:
$ref: "schemas/openapi-schemas/ValueRequest.yml"
MarginRequest:
$ref: "schemas/openapi-schemas/MarginRequest.yml"
+ RegularSettlementRequest:
+ $ref: "schemas/openapi-schemas/RegularSettlementRequest.yml"
+ InitialSettlementRequest:
+ $ref: "schemas/openapi-schemas/InitialSettlementRequest.yml"
PlainSwapOperationRequest:
$ref: "schemas/openapi-schemas/PlainSwapOperationRequest.yml"
CashflowPeriod:
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index fcccd0706..7e4791379 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -52,3 +52,22 @@ storage:
marketDataProviderConnectionPropertiesFile: '/config/market_data_connect.properties'
databaseConnectionPropertiesFile: '/config/database_connect.properties'
+valuation:
+ live-market-data: false
+ live-market-data-provider: "refinitiv"
+ internal-market-data-provider: "internal"
+ settlement-currency: "EUR"
+ product-fixing-type: "Fixing"
+
+refinitiv:
+ user: ${REFINITIV_USER}
+ password: ${REFINITIV_PASSWORD}
+ client-id: ${REFINITIV_CLIENT_ID}
+ host-name: ${REFINITIV_HOST_NAME}
+ port: 443
+ auth-url: "https://api.refinitiv.com:443/auth/oauth2/v1/token"
+ use-proxy: "FALSE"
+ proxy-host: ""
+ proxy-port: 9400
+ proxy-user: ""
+ proxy-password: ""
\ No newline at end of file
diff --git a/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract.xml b/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract.xml
index 49023694b..8fb83fdb8 100644
--- a/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract.xml
+++ b/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract.xml
@@ -4,6 +4,8 @@
ID-Test123
0x000000001
UTI12345
+ EUR
+ SDCPledgedBalance
net.finmath
@@ -490,9 +492,9 @@
-
+
diff --git a/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract.xsd b/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract.xsd
index 79d66e2b8..3c623aacb 100644
--- a/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract.xsd
+++ b/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract.xsd
@@ -11,6 +11,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract_simulated_historical_marketdata.xml b/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract_simulated_historical_marketdata.xml
index 1d42e096d..ac136ab78 100644
--- a/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract_simulated_historical_marketdata.xml
+++ b/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract_simulated_historical_marketdata.xml
@@ -4,6 +4,8 @@
ID-historical123
0x000000002
UTI12345
+ EUR
+ SDCNoPrefunding
net.finmath
@@ -430,9 +432,9 @@
-
+
diff --git a/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract_with_rics.xml b/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract_with_rics.xml
index abbfd4b6a..f5c6be6b1 100644
--- a/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract_with_rics.xml
+++ b/src/main/resources/net.finmath.smartcontract.product.xml/smartderivativecontract_with_rics.xml
@@ -1,7 +1,11 @@
+ ID-rics567
+ 0x000000006
UTI12345
+ EUR
+ SDCPledgedBalance
net.finmath
@@ -488,9 +492,9 @@
-
+
diff --git a/src/main/resources/net/finmath/smartcontract/valuation/client/settlement_testset_initial.xml b/src/main/resources/net/finmath/smartcontract/valuation/client/settlement_testset_initial.xml
index d19c957e9..a53f21a1a 100644
--- a/src/main/resources/net/finmath/smartcontract/valuation/client/settlement_testset_initial.xml
+++ b/src/main/resources/net/finmath/smartcontract/valuation/client/settlement_testset_initial.xml
@@ -4,6 +4,13 @@
-50000
50000
-5000
+ SDCTestTrade1
+ INITIAL
+ 20220908-170110
+ 12.25
+ 0
+ 20220909-170000
+ 17.11
20220908-170110
-
@@ -357,11 +364,4 @@
20220908-170110
- 20240314-170000
- 20240315-170000
- INITIAL
- 20000
- 20001
- 25000
- SDCTestTrade1
\ No newline at end of file
diff --git a/src/main/resources/net/finmath/smartcontract/valuation/client/settlement_testset_initial_historical.xml b/src/main/resources/net/finmath/smartcontract/valuation/client/settlement_testset_initial_historical.xml
new file mode 100644
index 000000000..a854d548a
--- /dev/null
+++ b/src/main/resources/net/finmath/smartcontract/valuation/client/settlement_testset_initial_historical.xml
@@ -0,0 +1,357 @@
+
+
+ EUR
+ -50000
+ 50000
+ -5000
+ SDCTestTrade1
+ INITIAL
+ 20240314-170000
+ 18937.55
+ 0
+ 20240315-170000
+ 18940.22
+
+ 20080917-170000
+ -
+ EUB6FIX6M
+ 0.0521
+ 20080917-170000
+
+ -
+ ESTRSWP3W
+ 0.0424
+ 20080917-170000
+
+ -
+ ESTRSWP1W
+ 0.0426
+ 20080917-170000
+
+ -
+ ESTRSWP2W
+ 0.0424
+ 20080917-170000
+
+ -
+ ESTRSWP1M
+ 0.0422
+ 20080917-170000
+
+ -
+ ESTRSWP2M
+ 0.0426
+ 20080917-170000
+
+ -
+ ESTRSWP3M
+ 0.0429
+ 20080917-170000
+
+ -
+ ESTRSWP4M
+ 0.0421
+ 20080917-170000
+
+ -
+ ESTRSWP5M
+ 0.0422
+ 20080917-170000
+
+ -
+ ESTRSWP6M
+ 0.0425
+ 20080917-170000
+
+ -
+ ESTRSWP7M
+ 0.0415
+ 20080917-170000
+
+ -
+ ESTRSWP8M
+ 0.0416
+ 20080917-170000
+
+ -
+ ESTRSWP9M
+ 0.0416
+ 20080917-170000
+
+ -
+ ESTRSWP10M
+ 0.041
+ 20080917-170000
+
+ -
+ ESTRSWP11M
+ 0.0412
+ 20080917-170000
+
+ -
+ EUB6SWP1Y
+ 0.0513
+ 20080917-170000
+
+ -
+ ESTRSWP12M
+ 0.0412
+ 20080917-170000
+
+ -
+ ESTRSWP15M
+ 0.0402
+ 20080917-170000
+
+ -
+ ESTRSWP18M
+ 0.0394
+ 20080917-170000
+
+ -
+ EUB6SWP2Y
+ 0.0481
+ 20080917-170000
+
+ -
+ ESTRSWP2Y
+ 0.0393
+ 20080917-170000
+
+ -
+ EUB6SWP3Y
+ 0.0468
+ 20080917-170000
+
+ -
+ ESTRSWP3Y
+ 0.0391
+ 20080917-170000
+
+ -
+ EUB6SWP4Y
+ 0.0469
+ 20080917-170000
+
+ -
+ ESTRSWP4Y
+ 0.0403
+ 20080917-170000
+
+ -
+ EUB6SWP5Y
+ 0.047
+ 20080917-170000
+
+ -
+ ESTRSWP5Y
+ 0.0406
+ 20080917-170000
+
+ -
+ EUB6SWP6Y
+ 0.0466
+ 20080917-170000
+
+ -
+ ESTRSWP6Y
+ 0.0408
+ 20080917-170000
+
+ -
+ EUB6SWP7Y
+ 0.0474
+ 20080917-170000
+
+ -
+ ESTRSWP7Y
+ 0.0416
+ 20080917-170000
+
+ -
+ EUB6SWP8Y
+ 0.0473
+ 20080917-170000
+
+ -
+ ESTRSWP8Y
+ 0.0415
+ 20080917-170000
+
+ -
+ EUB6SWP9Y
+ 0.0473
+ 20080917-170000
+
+ -
+ ESTRSWP9Y
+ 0.0423
+ 20080917-170000
+
+ -
+ EUB6SWP10Y
+ 0.0474
+ 20080917-170000
+
+ -
+ ESTRSWP10Y
+ 0.0422
+ 20080917-170000
+
+ -
+ EUB6SWP11Y
+ 0.048
+ 20080917-170000
+
+ -
+ ESTRSWP11Y
+ 0.0424
+ 20080917-170000
+
+ -
+ EUB6SWP12Y
+ 0.0478
+ 20080917-170000
+
+ -
+ ESTRSWP12Y
+ 0.0435
+ 20080917-170000
+
+ -
+ EUB6SWP13Y
+ 0.0483
+ 20080917-170000
+
+ -
+ EUB6SWP14Y
+ 0.0486
+ 20080917-170000
+
+ -
+ EUB6SWP15Y
+ 0.0488
+ 20080917-170000
+
+ -
+ ESTRSWP15Y
+ 0.0443
+ 20080917-170000
+
+ -
+ EUB6SWP16Y
+ 0.0488
+ 20080917-170000
+
+ -
+ EUB6SWP17Y
+ 0.0491
+ 20080917-170000
+
+ -
+ EUB6SWP18Y
+ 0.0483
+ 20080917-170000
+
+ -
+ EUB6SWP19Y
+ 0.0487
+ 20080917-170000
+
+ -
+ EUB6SWP20Y
+ 0.0491
+ 20080917-170000
+
+ -
+ ESTRSWP20Y
+ 0.0447
+ 20080917-170000
+
+ -
+ EUB6SWP21Y
+ 0.0484
+ 20080917-170000
+
+ -
+ EUB6SWP22Y
+ 0.0488
+ 20080917-170000
+
+ -
+ EUB6SWP23Y
+ 0.048
+ 20080917-170000
+
+ -
+ EUB6SWP24Y
+ 0.0488
+ 20080917-170000
+
+ -
+ EUB6SWP25Y
+ 0.0481
+ 20080917-170000
+
+ -
+ ESTRSWP25Y
+ 0.0437
+ 20080917-170000
+
+ -
+ EUB6SWP26Y
+ 0.0482
+ 20080917-170000
+
+ -
+ EUB6SWP27Y
+ 0.0478
+ 20080917-170000
+
+ -
+ EUB6SWP28Y
+ 0.0479
+ 20080917-170000
+
+ -
+ EUB6SWP29Y
+ 0.0478
+ 20080917-170000
+
+ -
+ EUB6SWP30Y
+ 0.0473
+ 20080917-170000
+
+ -
+ ESTRSWP30Y
+ 0.0435
+ 20080917-170000
+
+ -
+ EUB6SWP35Y
+ 0.0473
+ 20080917-170000
+
+ -
+ EUB6SWP40Y
+ 0.0472
+ 20080917-170000
+
+ -
+ EUB6SWP45Y
+ 0.0471
+ 20080917-170000
+
+ -
+ EUB6SWP50Y
+ 0.0461
+ 20080917-170000
+
+ -
+ EUB6SWP60Y
+ 0.0458
+ 20080917-170000
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/patches/TradeIdentifier.java b/src/main/resources/patches/TradeIdentifier.java
index 8a4aa4f1f..6478f93e3 100644
--- a/src/main/resources/patches/TradeIdentifier.java
+++ b/src/main/resources/patches/TradeIdentifier.java
@@ -1,20 +1,12 @@
package net.finmath.smartcontract.product.xml;
-import java.util.ArrayList;
-import java.util.List;
-
-import jakarta.xml.bind.annotation.XmlAccessType;
-import jakarta.xml.bind.annotation.XmlAccessorType;
-import jakarta.xml.bind.annotation.XmlAttribute;
-import jakarta.xml.bind.annotation.XmlElement;
-import jakarta.xml.bind.annotation.XmlElements;
-import jakarta.xml.bind.annotation.XmlID;
-import jakarta.xml.bind.annotation.XmlSchemaType;
-import jakarta.xml.bind.annotation.XmlSeeAlso;
-import jakarta.xml.bind.annotation.XmlType;
+import jakarta.xml.bind.annotation.*;
import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import java.util.ArrayList;
+import java.util.List;
+
/** I WAS HERE
* A type defining a trade identifier issued by the indicated party.
diff --git a/src/main/resources/schemas/openapi-schemas/InitialSettlementRequest.yml b/src/main/resources/schemas/openapi-schemas/InitialSettlementRequest.yml
new file mode 100644
index 000000000..e2f283768
--- /dev/null
+++ b/src/main/resources/schemas/openapi-schemas/InitialSettlementRequest.yml
@@ -0,0 +1,6 @@
+type: object
+required:
+ - tradeData
+properties:
+ tradeData:
+ type: string
\ No newline at end of file
diff --git a/src/main/resources/schemas/openapi-schemas/InitialSettlementResult.yml b/src/main/resources/schemas/openapi-schemas/InitialSettlementResult.yml
new file mode 100644
index 000000000..62bb74a81
--- /dev/null
+++ b/src/main/resources/schemas/openapi-schemas/InitialSettlementResult.yml
@@ -0,0 +1,15 @@
+type: object
+required:
+ - marginValue
+ - currency
+ - valuationDate
+ - generatedInitialSettlement
+properties:
+ marginValue:
+ type: number
+ currency:
+ type: string
+ valuationDate:
+ type: string
+ generatedInitialSettlement:
+ type: string
\ No newline at end of file
diff --git a/src/main/resources/schemas/openapi-schemas/RegularSettlementRequest.yml b/src/main/resources/schemas/openapi-schemas/RegularSettlementRequest.yml
new file mode 100644
index 000000000..d2424f820
--- /dev/null
+++ b/src/main/resources/schemas/openapi-schemas/RegularSettlementRequest.yml
@@ -0,0 +1,9 @@
+type: object
+required:
+ - settlementLast
+ - tradeData
+properties:
+ settlementLast:
+ type: string
+ tradeData:
+ type: string
\ No newline at end of file
diff --git a/src/main/resources/schemas/openapi-schemas/RegularSettlementResult.yml b/src/main/resources/schemas/openapi-schemas/RegularSettlementResult.yml
new file mode 100644
index 000000000..eda885a25
--- /dev/null
+++ b/src/main/resources/schemas/openapi-schemas/RegularSettlementResult.yml
@@ -0,0 +1,15 @@
+type: object
+required:
+ - marginValue
+ - currency
+ - valuationDate
+ - generatedRegularSettlement
+properties:
+ marginValue:
+ type: number
+ currency:
+ type: string
+ valuationDate:
+ type: string
+ generatedRegularSettlement:
+ type: string
\ No newline at end of file
diff --git a/src/main/resources/static/generate-initial-settlement.html b/src/main/resources/static/generate-initial-settlement.html
new file mode 100644
index 000000000..2d6e1d5e5
--- /dev/null
+++ b/src/main/resources/static/generate-initial-settlement.html
@@ -0,0 +1,133 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
finmath Valuation Oracle: Margin Calculator
+
+
+ Perform a valuation of the settlement (margin) based on product data and two market data sets.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html
index 2b7c7124c..94ae89133 100644
--- a/src/main/resources/static/index.html
+++ b/src/main/resources/static/index.html
@@ -45,6 +45,16 @@ Product XML Check
+
+
+
Generate Initial Settlement XML
+
+ generate an initial settlement XML based on product data
+
+
+
+
+