Fixed that quantity is a floating point number

This commit is contained in:
dankito 2024-10-15 09:29:52 +02:00
parent ce3b1d32d7
commit ecf930fcad
3 changed files with 53 additions and 7 deletions

View File

@ -145,7 +145,7 @@ open class Mt535Parser(
val (marketValue, pricingTime, totalCostPrice) = parseMarketValue(holdingBlock)
val balance = portfolioValue?.first ?: (if (balanceIsQuantity == false) Amount(totalBalance) else null)
val quantity = if (balanceIsQuantity) totalBalance.replace(",", "").toIntOrNull() else null
val quantity = if (balanceIsQuantity) totalBalance.replace(",", ".").toDoubleOrNull() else null
Holding(name, isin, wkn, buyingDate, quantity, averageCostPrice, balance, portfolioValue?.second ?: averageCostPriceCurrency, marketValue, pricingTime, totalCostPrice)
} catch (e: Throwable) {

View File

@ -11,7 +11,7 @@ data class Holding(
val isin: String?,
val wkn: String?,
val buyingDate: LocalDate?,
val quantity: Int?,
val quantity: Double?,
/**
* (Durchschnittlicher) Einstandspreis/-kurs einer Einheit des Wertpapiers
*/

View File

@ -22,8 +22,19 @@ class Mt535ParserTest {
assertSize(2, statement.holdings)
assertHolding(statement.holdings.first(), "MUL AMUN MSCI WLD ETF ACC MUL Amundi MSCI World V", "LU1781541179", null, LocalDate(2024, 6, 3), 1693, "16,828250257", "18531,08")
assertHolding(statement.holdings[1], "NVIDIA CORP. DL-,001 NVIDIA Corp.", "US67066G1040", null, LocalDate(2024, 8, 5), 214, "92,86", "22846,64")
assertHolding(statement.holdings.first(), "MUL AMUN MSCI WLD ETF ACC MUL Amundi MSCI World V", "LU1781541179", null, LocalDate(2024, 6, 3), 1693.0, "16,828250257", "18531,08")
assertHolding(statement.holdings[1], "NVIDIA CORP. DL-,001 NVIDIA Corp.", "US67066G1040", null, LocalDate(2024, 8, 5), 214.0, "92,86", "22846,64")
}
@Test
fun quantityIsFloatingPointNumber() {
val result = underTest.parseMt535String(QuantityIsFloatingPointNumber)
val statement = assertStatement(result, "70033100", "0123456789", "21480,38", LocalDate(2024, 10, 15), LocalDate(2024, 10, 15))
assertSize(1, statement.holdings)
assertHolding(statement.holdings.first(), "SAP SE O.N. SAP SE", "DE0007164600", null, LocalDate(2024, 10, 4), 100.446, "199,090257451", "21480,38")
}
@Test
@ -46,8 +57,8 @@ class Mt535ParserTest {
assertSize(3, statement.holdings)
assertHolding(statement.holdings.first(), "/DE/123456 Mustermann AG, Stammaktien", "DE0123456789", null, LocalDate(1999, 8, 15), 100, "68,5", "5270,")
assertHolding(statement.holdings[1], "/DE/123457 Mustermann AG, Vorzugsaktien", "DE0123456790", null, LocalDate(1998, 10, 13), 100, "42,75", "5460,")
assertHolding(statement.holdings.first(), "/DE/123456 Mustermann AG, Stammaktien", "DE0123456789", null, LocalDate(1999, 8, 15), 100.0, "68,5", "5270,")
assertHolding(statement.holdings[1], "/DE/123457 Mustermann AG, Vorzugsaktien", "DE0123456790", null, LocalDate(1998, 10, 13), 100.0, "42,75", "5460,")
// TODO: these values are not correct. Implement taking foreign currencies into account to fix this
assertHolding(statement.holdings[2], "Australian Domestic Bonds 1993 (2003) Ser. 10", "AU9876543210", null, LocalDate(1999, 3, 15), null, "31", "6294,65")
}
@ -71,7 +82,7 @@ class Mt535ParserTest {
return statement
}
private fun assertHolding(holding: Holding, name: String, isin: String?, wkn: String?, buyingDate: LocalDate?, quantity: Int?, averagePrice: String?, balance: String?, currency: String? = "EUR") {
private fun assertHolding(holding: Holding, name: String, isin: String?, wkn: String?, buyingDate: LocalDate?, quantity: Double?, averagePrice: String?, balance: String?, currency: String? = "EUR") {
assertEquals(name, holding.name)
assertEquals(isin, holding.isin)
@ -140,6 +151,41 @@ class Mt535ParserTest {
-
""".trimIndent()
private val QuantityIsFloatingPointNumber = """
:16R:GENL
:28E:1/ONLY
:20C::SEME//NONREF
:23G:NEWM
:98A::PREP//20241015
:98A::STAT//20241015
:22F::STTY//CUST
:97A::SAFE//70033100/0123456789
:17B::ACTI//Y
:16S:GENL
:16R:FIN
:35B:ISIN DE0007164600
SAP SE O.N.
SAP SE
:93B::AGGR//UNIT/100,446
:16R:SUBBAL
:93C::TAVI//UNIT/AVAI/100,446
:70C::SUBB//1 SAP SE O.N.
2
3 EDE 213.850000000EUR 2024-10-15T09:03:25.4
4 19997.82EUR DE0007164600, 1/SHS
:16S:SUBBAL
:19A::HOLD//EUR21480,38
:70E::HOLD//1STK++++20241004+
2199,090257451+EUR
:16S:FIN
:16R:ADDINFO
:19A::HOLP//EUR21480,38
:16S:ADDINFO
-'
""".trimIndent()
/**
* See Anlage_3_Datenformate_V3.8, S. 317ff
*