Skip to content

Commit

Permalink
Merge pull request #101 from Julius278/feature/634_fix
Browse files Browse the repository at this point in the history
SDC-634, fix for including multiple fixings
  • Loading branch information
Julius278 authored Nov 4, 2024
2 parents 265cd1a + 13615e1 commit 6531078
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,15 @@ private void includeFixingsOfLastSettlement(RegularSettlementRequest regularSett

//matching symbols from product data xml to last settlement xml marketdataPoints
Settlement settlementLast = SDCXMLParser.unmarshalXml(regularSettlementRequest.getSettlementLast(), Settlement.class);
List<MarketDataPoint> marketDataPointsLastSettlement = settlementLast.getMarketData().getPoints().stream().filter(marketDataPoint -> {
for (String symbol : symbols) {
if (marketDataPoint.getId().equalsIgnoreCase(symbol)) return true;
}
return false;
}).findAny().stream().toList();
List<MarketDataPoint> 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: {}", marketDataPointsLastSettlement);
for (MarketDataPoint marketDataPoint : marketDataPointsLastSettlement) {
logger.info("add matching marketdataPoints to product symbols: {}", fixingsLastSettlement);
for (MarketDataPoint marketDataPoint : fixingsLastSettlement) {
newMarketDataList.add(marketDataPoint);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,47 @@ void generateRegularSettlement_includes_FixingOfLastSettlement() throws IOExcept
assertTrue(settlementString.contains("<settlementType>REGULAR</settlementType>"));
}

@Test
void generateRegularSettlement_includes_FixingOfLastSettlement_twice() throws IOException {
String settlementLast = new String(SettlementServiceTest.class.getClassLoader().getResourceAsStream("net/finmath/smartcontract/valuation/client/settlement_testset_initial_historical.xml").readAllBytes(), StandardCharsets.UTF_8);

InputStream inputStream = SettlementServiceTest.class.getClassLoader().getResourceAsStream("net.finmath.smartcontract.product.xml/smartderivativecontract_simulated_historical_marketdata.xml");
String productXml = new String(inputStream.readAllBytes());

when(valuationConfig.getLiveMarketDataProvider()).thenReturn("internal");
when(valuationConfig.getInternalMarketDataProvider()).thenReturn("internal");
when(valuationConfig.isLiveMarketData()).thenReturn(false);
when(valuationConfig.getProductFixingType()).thenReturn("Fixing");


//first regular settlement request
RegularSettlementRequest regularSettlementRequest = new RegularSettlementRequest()
.settlementLast(settlementLast)
.tradeData(productXml);

RegularSettlementResult regularSettlementResult = serviceUnderTest.generateRegularSettlementResult(regularSettlementRequest);
String settlementString = regularSettlementResult.getGeneratedRegularSettlement();
System.out.println("first regular settlementString");
System.out.println(settlementString);

//second regular settlement request
RegularSettlementRequest secondSettlementRequest = new RegularSettlementRequest()
.settlementLast(regularSettlementResult.getGeneratedRegularSettlement())
.tradeData(productXml);
RegularSettlementResult secondSettlementResult = serviceUnderTest.generateRegularSettlementResult(secondSettlementRequest);

settlementString = secondSettlementResult.getGeneratedRegularSettlement();
System.out.println("second regular settlementString");
System.out.println(settlementString);

//fixing from initial settlement
assertTrue(settlementString.contains("<id>EUB6FIX6M</id><value>0.0521</value><timeStamp>20080917-170000</timeStamp>"));
//fixing first settlement request
assertTrue(settlementString.contains("<id>EUB6FIX6M</id><value>0.0484</value><timeStamp>20080502-170000</timeStamp>"));
//fixing second settlement request
assertTrue(settlementString.contains("<id>EUB6FIX6M</id><value>0.0484</value><timeStamp>20080505-170000</timeStamp>"));
assertTrue(settlementString.contains("<settlementNPV>72349.58</settlementNPV>"));
assertTrue(settlementString.contains("<settlementType>REGULAR</settlementType>"));
}

}

0 comments on commit 6531078

Please sign in to comment.