From 877b4861058c110897b1e6e59c750e4de6ce23df Mon Sep 17 00:00:00 2001 From: mierin12 Date: Fri, 1 Nov 2024 13:47:05 +0100 Subject: [PATCH] add comparison with "moving average" purchase price in securities chart --- .../name/abuchen/portfolio/ui/Messages.java | 1 + .../abuchen/portfolio/ui/messages.properties | 2 + .../portfolio/ui/messages_cs.properties | 2 + .../portfolio/ui/messages_da.properties | 2 + .../portfolio/ui/messages_de.properties | 2 + .../portfolio/ui/messages_es.properties | 2 + .../portfolio/ui/messages_fr.properties | 2 + .../portfolio/ui/messages_it.properties | 2 + .../portfolio/ui/messages_nl.properties | 2 + .../portfolio/ui/messages_pl.properties | 2 + .../portfolio/ui/messages_pt.properties | 2 + .../portfolio/ui/messages_pt_BR.properties | 2 + .../portfolio/ui/messages_ru.properties | 2 + .../portfolio/ui/messages_sk.properties | 2 + .../portfolio/ui/messages_zh.properties | 2 + .../portfolio/ui/messages_zh_TW.properties | 2 + .../portfolio/ui/views/SecuritiesChart.java | 38 +++++++++++++++++-- 17 files changed, 66 insertions(+), 3 deletions(-) diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/Messages.java b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/Messages.java index 1f687dfe23..d818457a6e 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/Messages.java +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/Messages.java @@ -553,6 +553,7 @@ public class Messages extends NLS public static String LabelChartDetailChartDevelopment; public static String LabelChartDetailChartDevelopmentClosing; public static String LabelChartDetailChartDevelopmentClosingFIFO; + public static String LabelChartDetailChartDevelopmentClosingMovingAverage; public static String LabelChartDetailChartScaling; public static String LabelChartDetailChartScalingLinear; public static String LabelChartDetailChartScalingLog; diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages.properties index e101d73066..a8bc1fa3ae 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages.properties @@ -1098,6 +1098,8 @@ LabelChartDetailChartDevelopmentClosing = Market trend LabelChartDetailChartDevelopmentClosingFIFO = Market trend vs. Purchase Value +LabelChartDetailChartDevelopmentClosingMovingAverage = Market trend vs. Purchase Price (moving average) + LabelChartDetailChartScaling = Scaling LabelChartDetailChartScalingLinear = Linear diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_cs.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_cs.properties index e7bff2230d..9ace190365 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_cs.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_cs.properties @@ -1088,6 +1088,8 @@ LabelChartDetailChartDevelopmentClosing = V\u00FDvoj na trhu LabelChartDetailChartDevelopmentClosingFIFO = V\u00FDvoj na trhu vs po\u0159izovac\u00ED hodnota +LabelChartDetailChartDevelopmentClosingMovingAverage = V\u00FDvoj na trhu vs po\u0159izovac\u00ED hodnota (klouzav\u00FD pr\u016Fm\u011Br) + LabelChartDetailChartScaling = M\u011B\u0159\u00EDtko LabelChartDetailChartScalingLinear = Line\u00E1rn\u00ED diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_da.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_da.properties index 56aa2bbdf0..26cf4b7dbc 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_da.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_da.properties @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Markedstrend LabelChartDetailChartDevelopmentClosingFIFO = Markedstrend vs. K\u00F8bsv\u00E6rdi +LabelChartDetailChartDevelopmentClosingMovingAverage = Markedstrend vs. K\u00F8bsv\u00E6rdi (glidende gennemsnit) + LabelChartDetailChartScaling = Skalering LabelChartDetailChartScalingLinear = Line\u00E6r diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_de.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_de.properties index ce3b0c9f58..2276515aaa 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_de.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_de.properties @@ -1091,6 +1091,8 @@ LabelChartDetailChartDevelopmentClosing = Kursentwicklung LabelChartDetailChartDevelopmentClosingFIFO = Kursentwicklung zum Einstandspreis +LabelChartDetailChartDevelopmentClosingMovingAverage = Kursentwicklung zum Einstandspreis (gleitender Durchschnitt) + LabelChartDetailChartScaling = Skalierung LabelChartDetailChartScalingLinear = Linear diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_es.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_es.properties index b62af466bc..91c40603f7 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_es.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_es.properties @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Evoluci\u00F3n de la cotizaci\u00F3n LabelChartDetailChartDevelopmentClosingFIFO = Evoluci\u00F3n respecto al precio de compra +LabelChartDetailChartDevelopmentClosingMovingAverage = Evoluci\u00F3n respecto al precio de compra (media m\u00F3vil) + LabelChartDetailChartScaling = Escala LabelChartDetailChartScalingLinear = Lineal diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_fr.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_fr.properties index 905979d817..dbdd796847 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_fr.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_fr.properties @@ -1088,6 +1088,8 @@ LabelChartDetailChartDevelopmentClosing = \u00C9volution du cours LabelChartDetailChartDevelopmentClosingFIFO = \u00C9volution du cours vs. Prix d'achat +LabelChartDetailChartDevelopmentClosingMovingAverage = \u00C9volution du cours vs. Prix d'achat (moyenne glissante) + LabelChartDetailChartScaling = \u00C9chelle LabelChartDetailChartScalingLinear = Lin\u00E9aire diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_it.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_it.properties index 646c1e42fc..3cbd4d4051 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_it.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_it.properties @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Tendenza mercato LabelChartDetailChartDevelopmentClosingFIFO = Tendenza mercato vs. Valore acquisto +LabelChartDetailChartDevelopmentClosingMovingAverage = Tendenza mercato vs. Valore acquisto (media mobile) + LabelChartDetailChartScaling = Scala LabelChartDetailChartScalingLinear = Lineare diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_nl.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_nl.properties index 4cde1fb02d..3ef1612964 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_nl.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_nl.properties @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Koersontwikkeling LabelChartDetailChartDevelopmentClosingFIFO = Koersontwikkeling versus GAK (FIFO) +LabelChartDetailChartDevelopmentClosingMovingAverage = Koersontwikkeling versus GAK (SMA) + LabelChartDetailChartScaling = Schaling LabelChartDetailChartScalingLinear = Lineair diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pl.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pl.properties index aa0463c6e9..48a56a3c6f 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pl.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pl.properties @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Trend rynkowy LabelChartDetailChartDevelopmentClosingFIFO = Trend rynku vs. warto\u015B\u0107 kupna +LabelChartDetailChartDevelopmentClosingMovingAverage = Trend rynku vs. warto\u015B\u0107 kupna (\u015Brednia ruchoma) + LabelChartDetailChartScaling = Skalowanie LabelChartDetailChartScalingLinear = Liniowe diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt.properties index 7dc31c9691..5db0344154 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt.properties @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Gr\u00E1fico de Crescimento LabelChartDetailChartDevelopmentClosingFIFO = Gr\u00E1fico de Crescimento versus valor de compra +LabelChartDetailChartDevelopmentClosingMovingAverage = Gr\u00E1fico de Crescimento versus valor de compra (m\u00E9dia m\u00F3vel) + LabelChartDetailChartScaling = Escala LabelChartDetailChartScalingLinear = Linear diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt_BR.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt_BR.properties index 83ae24c08e..8fe277f4ef 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt_BR.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_pt_BR.properties @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Tend\u00EAncia do Mercado LabelChartDetailChartDevelopmentClosingFIFO = Tend\u00EAnciad o Mercado vs. Valor de Compra +LabelChartDetailChartDevelopmentClosingMovingAverage = Tend\u00EAnciad o Mercado vs. Valor de Compra (m\u00E9dia m\u00F3vel) + LabelChartDetailChartScaling = Escala LabelChartDetailChartScalingLinear = Linear diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_ru.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_ru.properties index 60b0a632c3..35f5e2679e 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_ru.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_ru.properties @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = \u0422\u0435\u043D\u0434\u0435\u043D\u LabelChartDetailChartDevelopmentClosingFIFO = \u0420\u044B\u043D\u043E\u0447\u043D\u0430\u044F \u0442\u0435\u043D\u0434\u0435\u043D\u0446\u0438\u044F \u0438 \u0441\u0442\u043E\u0438\u043C\u043E\u0441\u0442\u044C \u043F\u043E\u043A\u0443\u043F\u043A\u0438 +LabelChartDetailChartDevelopmentClosingMovingAverage = \u0420\u044B\u043D\u043E\u0447\u043D\u0430\u044F \u0442\u0435\u043D\u0434\u0435\u043D\u0446\u0438\u044F \u0438 \u0441\u0442\u043E\u0438\u043C\u043E\u0441\u0442\u044C \u043F\u043E\u043A\u0443\u043F\u043A\u0438 (\u0441\u043A\u043E\u043B\u044C\u0437\u044F\u0449\u0435\u0435 \u0441\u0440\u0435\u0434\u043D\u0435\u0435) + LabelChartDetailChartScaling = \u041C\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 LabelChartDetailChartScalingLinear = \u041B\u0438\u043D\u0435\u0439\u043D\u043E diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_sk.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_sk.properties index 90b0956277..a6da4db978 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_sk.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_sk.properties @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = V\u00FDvoj na trhu LabelChartDetailChartDevelopmentClosingFIFO = V\u00FDvoj na trhu vs n\u00E1kupn\u00E1 hodnota +LabelChartDetailChartDevelopmentClosingMovingAverage = V\u00FDvoj na trhu vs n\u00E1kupn\u00E1 hodnota (k\u013Azav\u00FD priemer) + LabelChartDetailChartScaling = \u0160k\u00E1lovanie LabelChartDetailChartScalingLinear = Line\u00E1rne diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh.properties index ec86254c80..eb0abc3890 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh.properties @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = \u5E02\u573A\u8D8B\u52BF LabelChartDetailChartDevelopmentClosingFIFO = \u5E02\u573A\u8D8B\u52BF vs. \u6210\u672C +LabelChartDetailChartDevelopmentClosingMovingAverage = \u5E02\u573A\u8D8B\u52BF vs. \u6210\u672C (\u79FB\u52A8\u5E73\u5747) + LabelChartDetailChartScaling = \u5C3A\u5EA6 LabelChartDetailChartScalingLinear = \u7EBF\u6027 diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh_TW.properties b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh_TW.properties index 7293f60c64..a0f3636811 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh_TW.properties +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_zh_TW.properties @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = \u5E02\u5834\u8DA8\u52E2 LabelChartDetailChartDevelopmentClosingFIFO = \u5E02\u5834\u8DA8\u52E2\u8207\u8CFC\u8CB7\u50F9\u503C +LabelChartDetailChartDevelopmentClosingMovingAverage = \u5E02\u5834\u8DA8\u52E2\u8207\u8CFC\u8CB7\u50F9\u503C \uFF08\u79FB\u52D5\u5E73\u5747\u6CD5\uFF09 + LabelChartDetailChartScaling = \u7E2E\u653E LabelChartDetailChartScalingLinear = \u7DDA\u6027 diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java index 652a581a9b..a71cd2f2d9 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java @@ -245,6 +245,7 @@ private enum ChartDetails SCALING_LOG(Messages.LabelChartDetailChartScalingLog), // CLOSING(Messages.LabelChartDetailChartDevelopmentClosing), // PURCHASEPRICE(Messages.LabelChartDetailChartDevelopmentClosingFIFO), // + PURCHASEPRICE_MA(Messages.LabelChartDetailChartDevelopmentClosingMovingAverage), // INVESTMENT(Messages.LabelChartDetailMarkerInvestments), // SHARES_HELD(Messages.ColumnSharesOwned), // DIVIDENDS(Messages.LabelChartDetailMarkerDividends), // @@ -727,6 +728,7 @@ private void chartConfigAboutToShow(IMenuManager manager) subMenuChartScaling.add(addMenuAction(ChartDetails.SCALING_LOG)); subMenuChartDevelopment.add(addMenuAction(ChartDetails.CLOSING)); subMenuChartDevelopment.add(addMenuAction(ChartDetails.PURCHASEPRICE)); + subMenuChartDevelopment.add(addMenuAction(ChartDetails.PURCHASEPRICE_MA)); subMenuChartMarker.add(addMenuAction(ChartDetails.INVESTMENT)); subMenuChartMarker.add(addMenuAction(ChartDetails.SHARES_HELD)); subMenuChartMarker.add(addMenuAction(ChartDetails.DIVIDENDS)); @@ -792,15 +794,23 @@ private Action addMenuAction(ChartDetails detail) case SCALING_LOG: chartConfig.remove(ChartDetails.SCALING_LINEAR); chartConfig.remove(ChartDetails.PURCHASEPRICE); + chartConfig.remove(ChartDetails.PURCHASEPRICE_MA); chartConfig.remove(ChartDetails.CLOSING); break; case CLOSING: chartConfig.remove(ChartDetails.PURCHASEPRICE); + chartConfig.remove(ChartDetails.PURCHASEPRICE_MA); chartConfig.remove(ChartDetails.SCALING_LOG); break; case PURCHASEPRICE: chartConfig.remove(ChartDetails.CLOSING); chartConfig.remove(ChartDetails.SCALING_LOG); + chartConfig.remove(ChartDetails.PURCHASEPRICE_MA); + break; + case PURCHASEPRICE_MA: + chartConfig.remove(ChartDetails.CLOSING); + chartConfig.remove(ChartDetails.SCALING_LOG); + chartConfig.remove(ChartDetails.PURCHASEPRICE); break; case SHOW_MAIN_HORIZONTAL_LINES: chartConfig.remove(ChartDetails.SHOW_PERCENTAGE_HORIZONTAL_LINES); @@ -905,13 +915,15 @@ private void updateChart() swtAntialias = range.size > 1000 ? SWT.OFF : SWT.ON; boolean showAreaRelativeToFirstQuote = chartConfig.contains(ChartDetails.CLOSING) - || chartConfig.contains(ChartDetails.PURCHASEPRICE); - if (!chartConfig.contains(ChartDetails.PURCHASEPRICE)) + || chartConfig.contains(ChartDetails.PURCHASEPRICE) + || chartConfig.contains(ChartDetails.PURCHASEPRICE_MA); + if (!chartConfig.contains(ChartDetails.PURCHASEPRICE) + && !chartConfig.contains(ChartDetails.PURCHASEPRICE_MA)) { SecurityPrice p2 = prices.get(range.start); firstQuote = (p2.getValue() / Values.Quote.divider()); } - else + else if (chartConfig.contains(ChartDetails.PURCHASEPRICE)) { Optional purchasePrice = getLatestPurchasePrice(); @@ -920,6 +932,15 @@ private void updateChart() else showAreaRelativeToFirstQuote = false; } + else if (chartConfig.contains(ChartDetails.PURCHASEPRICE_MA)) + { + Optional purchasePrice = getLatestMovingAveragePurchasePrice(); + + if (purchasePrice.isPresent()) + firstQuote = purchasePrice.get(); + else + showAreaRelativeToFirstQuote = false; + } addChartMarkerBackground(chartInterval, range); @@ -1894,6 +1915,17 @@ private Optional getLatestPurchasePrice() converter.with(security.getCurrencyCode()), LocalDate.now()); } + private Optional getLatestMovingAveragePurchasePrice() + { + // securities w/o currency (e.g. index) cannot be bought and hence have + // no purchase price + if (security.getCurrencyCode() == null) + return Optional.empty(); + + return getMovingAveragePurchasePrice(new ClientSecurityFilter(security).filter(client), + converter.with(security.getCurrencyCode()), LocalDate.now()); + } + private Optional getPurchasePrice(Client filteredClient, CurrencyConverter currencyConverter, LocalDate date) {