Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge develop to main #112

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ RUN mvn -f /usr/src/app/pom.xml clean package spring-boot:repackage

# Run Stage: Copy fat-jar and define Entrypoint
FROM openjdk:17 as RunStage
COPY --from=BuildStage /usr/src/app/target/finmath-smart-derivative-contract-1.0.7-SNAPSHOT.jar /usr/app/finmath-smart-derivative-contract-1.0.7-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar", "/usr/app/finmath-smart-derivative-contract-1.0.7-SNAPSHOT.jar"]
COPY --from=BuildStage /usr/src/app/target/finmath-smart-derivative-contract-1.1.1-SNAPSHOT.jar /usr/app/finmath-smart-derivative-contract-1.1.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar", "/usr/app/finmath-smart-derivative-contract-1.1.1-SNAPSHOT.jar"]
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,14 @@
<imageName>docker.io/finmath/${project.artifactId}:${project.version}</imageName>
<jvmArguments>--add-opens java.base/java.time=ALL-UNNAMED</jvmArguments>
</configuration>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -974,6 +982,10 @@
<!-- <id>finmath-site</id>-->
<!-- <url>scp://www.finmath.net/var/www/vhosts/finmath.net/httpdocs/finmath-smart-derivative-contract/</url>-->
<!-- </site>-->
<repository>
<id>gitlab</id>
<url>https://gitlab.com/api/v4/projects/33978063/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab</id>
<url>https://gitlab.com/api/v4/projects/33978063/packages/maven</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public SmartDerivativeContractDescriptor(String dltTradeId, String dltAddress, S
Validate.isTrue(marginAccountInitialByPartyID.size() == 2, "Number of margin accounts values must be 2.");
Validate.isTrue(penaltyFeeInitialByPartyID.size() == 2, "Number of penalty fee values must be 2.");
Validate.notNull(underlying, "Underlying must not be null.");
Validate.notNull(tradeType, "TradeType must not be null.");
}

public String getDltTradeId() {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
import net.finmath.smartcontract.valuation.marketdata.curvecalibration.CalibrationDataItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -124,16 +125,19 @@ public static <T> T unmarshalXml(String xml, Class<T> t) {

/**
* Generic object-to-XML-string converter for all annotated classes
* @param t object to be converted to an XML string
* @return XML formatted String
*
* @param t object to be converted to an XML string
* @param <T> generic Type, which has the correct XML bind annotations
* @return XML formatted String
*/
public static <T> String marshalClassToXMLString(T t) {
try {
JAXBContext jaxbContextSettlement = JAXBContext.newInstance(t.getClass());
Marshaller jaxbMarshaller = jaxbContextSettlement.createMarshaller();
if (t instanceof Smartderivativecontract)
if (t instanceof Smartderivativecontract){
jaxbMarshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "uri:sdc smartderivativecontract.xsd");
jaxbMarshaller.setSchema(getSDCSchema());
}
StringWriter writer = new StringWriter();
jaxbMarshaller.marshal(t, writer);
return writer.toString();
Expand All @@ -143,15 +147,28 @@ public static <T> String marshalClassToXMLString(T t) {
}
}

private static Schema getSDCSchema() {
final String schemaPath = "net.finmath.smartcontract.product.xml/smartderivativecontract.xsd";
final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema sdcmlSchema;
try {
sdcmlSchema = schemaFactory.newSchema((new ClassPathResource(schemaPath)).getURL());
} catch (SAXException | IOException e) {
throw new SDCException(ExceptionId.SDC_JAXB_ERROR, "", 400);
}
return sdcmlSchema;
}

/**
* this version of an SDC-object-to-XML-string conversion includes text replacements to get rid of XML namespace tags like "fpml:dataDocument"
*
* @param smartderivativecontract SDC product data object which will be transformed into an XML string
* @return formatted xml string
*/
public static String marshalSDCToXMLString(Smartderivativecontract smartderivativecontract) {
//TODO took over an old implementation, please review
return marshalClassToXMLString(smartderivativecontract)
.replaceAll("<fpml:dataDocument fpmlVersion=\"5-9\">", "<dataDocument fpmlVersion=\"5-9\" xmlns=\"http://www.fpml.org/FpML-5/confirmation\">")
.replaceAll("fpml:", "");
.replace("<fpml:dataDocument fpmlVersion=\"5-9\">", "<dataDocument fpmlVersion=\"5-9\" xmlns=\"http://www.fpml.org/FpML-5/confirmation\">")
.replace("fpml:", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

@Configuration
@ConfigurationProperties(prefix = "valuation")
Expand All @@ -12,6 +13,8 @@ public class ValuationConfig {
private String liveMarketDataProvider;
private String internalMarketDataProvider;
private String productFixingType;
private String fpmlSchemaPath;
private Map<String, String> marketDataProviderToTemplate;

public boolean isLiveMarketData() {
return liveMarketData;
Expand Down Expand Up @@ -52,4 +55,20 @@ public String getProductFixingType() {
public void setProductFixingType(String productFixingType) {
this.productFixingType = productFixingType;
}

public String getFpmlSchemaPath() {
return fpmlSchemaPath;
}

public void setFpmlSchemaPath(String fpmlSchemaPath) {
this.fpmlSchemaPath = fpmlSchemaPath;
}

public Map<String, String> getMarketDataProviderToTemplate() {
return marketDataProviderToTemplate;
}

public void setMarketDataProviderToTemplate(Map<String, String> marketDataProviderToTemplate) {
this.marketDataProviderToTemplate = marketDataProviderToTemplate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import net.finmath.smartcontract.valuation.marketdata.generators.WebSocketConnector;
import net.finmath.smartcontract.valuation.marketdata.generators.legacy.LiveFeedAdapter;
import net.finmath.smartcontract.valuation.marketdata.generators.legacy.ReactiveMarketDataUpdater;
import net.finmath.smartcontract.valuation.service.config.ValuationConfig;
import net.finmath.smartcontract.valuation.service.utils.ResourceGovernor;
import net.finmath.util.TriFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.info.BuildProperties;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ProblemDetail;
Expand Down Expand Up @@ -69,19 +71,24 @@ public class PlainSwapEditorController implements PlainSwapEditorApi {
}
return rootFinder.getBestPoint();
};
private final String schemaPath = "schemas/sdc-schemas/sdcml-contract.xsd";
private final String schemaPath;
//may be changed to allow for different versions of the schema

@Value("${hostname:localhost:8080}")
private String hostname;
private final DatabaseConnector databaseConnector;
private final ResourceGovernor resourceGovernor;
private final ObjectMapper objectMapper;
private final ValuationConfig valuationConfig;
private final BuildProperties buildProperties;

public PlainSwapEditorController(DatabaseConnector databaseConnector, ResourceGovernor resourceGovernor, ObjectMapper objectMapper) {
public PlainSwapEditorController(DatabaseConnector databaseConnector, ResourceGovernor resourceGovernor, ObjectMapper objectMapper, ValuationConfig valuationConfig, ValuationConfig valuationConfig1, BuildProperties buildProperties) {
this.databaseConnector = databaseConnector;
this.resourceGovernor = resourceGovernor;
this.objectMapper = objectMapper;
this.schemaPath = valuationConfig.getFpmlSchemaPath();
this.valuationConfig = valuationConfig1;
this.buildProperties = buildProperties;
}

/**
Expand All @@ -94,9 +101,11 @@ public PlainSwapEditorController(DatabaseConnector databaseConnector, ResourceGo
public ResponseEntity<String> generatePlainSwapSdcml(PlainSwapOperationRequest plainSwapOperationRequest) {

try {
String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider());
return ResponseEntity.ok(new PlainSwapEditorHandler(plainSwapOperationRequest,
plainSwapOperationRequest.getCurrentGenerator(),
schemaPath).getContractAsXmlString());
currentGenerator,
schemaPath,
buildProperties.getVersion()).getContractAsXmlString());
} catch (JAXBException | IOException | DatatypeConfigurationException | SAXException e) {
/*
You may see this recurring snippet of code in other controller methods as well. Its goal is to report the stack
Expand Down Expand Up @@ -127,9 +136,11 @@ public ResponseEntity<ValueResult> evaluateFromPlainSwapEditor(PlainSwapOperatio

String sdcmlBody;
try {
String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider());
sdcmlBody = new PlainSwapEditorHandler(plainSwapOperationRequest,
plainSwapOperationRequest.getCurrentGenerator(),
schemaPath).getContractAsXmlString();
currentGenerator,
schemaPath,
buildProperties.getVersion()).getContractAsXmlString();
} catch (JAXBException | IOException | DatatypeConfigurationException | SAXException e) {
ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR,
ErrorDetails.JAXB_ERROR_DETAIL);
Expand Down Expand Up @@ -192,9 +203,11 @@ public ResponseEntity<List<CashflowPeriod>> getFixedSchedule(PlainSwapOperationR
throw new ErrorResponseException(HttpStatus.INTERNAL_SERVER_ERROR, pd, e);
}
try {
String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider());
return ResponseEntity.ok(new PlainSwapEditorHandler(plainSwapOperationRequest,
plainSwapOperationRequest.getCurrentGenerator(),
schemaPath).getSchedule(
currentGenerator,
schemaPath,
buildProperties.getVersion()).getSchedule(
PlainSwapEditorHandler.LegSelector.FIXED_LEG, marketData));
} catch (JAXBException | IOException | DatatypeConfigurationException | SAXException e) {
ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR,
Expand Down Expand Up @@ -236,9 +249,11 @@ public ResponseEntity<List<CashflowPeriod>> getFloatingSchedule(PlainSwapOperati
throw new ErrorResponseException(HttpStatus.INTERNAL_SERVER_ERROR, pd, e);
}
try {
String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider());
return ResponseEntity.ok(new PlainSwapEditorHandler(plainSwapOperationRequest,
plainSwapOperationRequest.getCurrentGenerator(),
schemaPath).getSchedule(
currentGenerator,
schemaPath,
buildProperties.getVersion()).getSchedule(
PlainSwapEditorHandler.LegSelector.FLOATING_LEG, marketData));
} catch (JAXBException | IOException | DatatypeConfigurationException | SAXException e) {
ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR,
Expand Down Expand Up @@ -301,9 +316,11 @@ public ResponseEntity<ValueResult> refreshMarketData(PlainSwapOperationRequest p
.getPrincipal()).getUsername();
SmartDerivativeContractDescriptor sdc;
try {
String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider());
sdc = SDCXMLParser.parse(new PlainSwapEditorHandler(plainSwapOperationRequest,
plainSwapOperationRequest.getCurrentGenerator(),
schemaPath).getContractAsXmlString());
currentGenerator,
schemaPath,
buildProperties.getVersion()).getContractAsXmlString());
} catch (IOException e) {
ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR,
ErrorDetails.STORAGE_ERROR_DETAIL);
Expand Down Expand Up @@ -443,9 +460,10 @@ public ResponseEntity<Double> getParRate(PlainSwapOperationRequest plainSwapOper
DoubleUnaryOperator swapValue = swapRate -> {
plainSwapOperationRequest.fixedRate(swapRate);
try {
String currentGenerator = identifyCurrentGenerator(plainSwapOperationRequest.getMarketDataProvider());
return (new MarginCalculator()).getValue(marketDataString, new PlainSwapEditorHandler(
plainSwapOperationRequest.notionalAmount(1E15),
plainSwapOperationRequest.getCurrentGenerator(), schemaPath).getContractAsXmlString())
currentGenerator, schemaPath, buildProperties.getVersion()).getContractAsXmlString())
.getValue().doubleValue();
} catch (Exception e) {
ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR,
Expand Down Expand Up @@ -697,4 +715,10 @@ private static final class ErrorTypeURI {
static final String STORAGE_ERROR_URI = "/storage-error";

}

private String identifyCurrentGenerator(String marketDataProvider){
String template = valuationConfig.getMarketDataProviderToTemplate().get(marketDataProvider);
logger.info("identifyCurrentGenerator - provided marketDataProvider '{}' has the following product xml template '{}'", marketDataProvider, template);
return template;
}
}
Loading
Loading