Skip to content

Commit

Permalink
Added adjusted internal rate of return
Browse files Browse the repository at this point in the history
- Add new widget Adjusted IRR that allows to set benchmark to e.g.
  consumer price index to get inflation adjusted IRR.
  • Loading branch information
Lasall committed Sep 11, 2022
1 parent a9aca70 commit 8cfb317
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ public class Messages extends NLS
public static String LabelInvestedCapital;
public static String LabelInvestmentPlans;
public static String LabelIRR;
public static String LabelIRRAdjusted;
public static String LabelLanguage;
public static String LabelLanguageAutomatic;
public static String LabelLayout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,8 @@ LabelHistoricalReturnsAndVolatiltity = Historical Returns and Volatility

LabelIRR = Internal Rate of Return (IRR)

LabelIRRAdjusted = Adjusted Internal Rate of Return (IRR)

LabelIncludeSecuritiesInPieChart = Include investment vehicles

LabelIncludeUnassignedCategoryInCharts = Include 'Without Classification'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@ LabelHistoricalReturnsAndVolatiltity = Historische Performance und Volatilit\u00

LabelIRR = Interner Zinsfu\u00DF (IZF)

LabelIRRAdjusted = Angepasster Interner Zinsfu\u00DF (IZF)

LabelIncludeSecuritiesInPieChart = Wertpapiere einbeziehen

LabelIncludeUnassignedCategoryInCharts = 'Ohne Klassifizierung' einbeziehen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
public class DataSeriesConfig implements WidgetConfig
{
private final WidgetDelegate<?> delegate;
private final boolean supportsDataSeries;
private final boolean supportsBenchmarks;
private final String label;
private final Dashboard.Config configurationKey;
Expand All @@ -29,18 +30,26 @@ public class DataSeriesConfig implements WidgetConfig

public DataSeriesConfig(WidgetDelegate<?> delegate, boolean supportsBenchmarks)
{
this(delegate, supportsBenchmarks, false, null, Messages.LabelDataSeries, Dashboard.Config.DATA_SERIES);
this(delegate, supportsBenchmarks, false, null, Messages.LabelDataSeries, true, Dashboard.Config.DATA_SERIES);
}

public DataSeriesConfig(WidgetDelegate<?> delegate)
{
this(delegate, true, true, null, Messages.LabelBenchmarks, false, Dashboard.Config.DATA_SERIES);
}

public DataSeriesConfig(WidgetDelegate<?> delegate, boolean supportsBenchmarks, Predicate<DataSeries> predicate)
{
this(delegate, supportsBenchmarks, false, predicate, Messages.LabelDataSeries, Dashboard.Config.DATA_SERIES);
this(delegate, supportsBenchmarks, false, predicate, Messages.LabelDataSeries, true,
Dashboard.Config.DATA_SERIES);
}

protected DataSeriesConfig(WidgetDelegate<?> delegate, boolean supportsBenchmarks, boolean supportsEmptyDataSeries,
Predicate<DataSeries> predicate, String label, Dashboard.Config configurationKey)
Predicate<DataSeries> predicate, String label, boolean supportsDataSeries,
Dashboard.Config configurationKey)
{
this.delegate = delegate;
this.supportsDataSeries = supportsDataSeries;
this.supportsBenchmarks = supportsBenchmarks;
this.label = label;
this.configurationKey = configurationKey;
Expand Down Expand Up @@ -70,7 +79,9 @@ public void menuAboutToShow(IMenuManager manager)
MenuManager subMenu = new MenuManager(label, configurationKey.name());
subMenu.add(new LabelOnly(dataSeries != null ? dataSeries.getLabel() : "-")); //$NON-NLS-1$
subMenu.add(new Separator());
subMenu.add(new SimpleAction(Messages.MenuSelectDataSeries, a -> doAddSeries(false)));

if (supportsDataSeries)
subMenu.add(new SimpleAction(Messages.MenuSelectDataSeries, a -> doAddSeries(false)));

if (supportsBenchmarks)
subMenu.add(new SimpleAction(Messages.MenuSelectBenchmarkDataSeries, a -> doAddSeries(true)));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package name.abuchen.portfolio.ui.views.dashboard;

import java.time.LocalDate;
import java.util.function.Supplier;

import name.abuchen.portfolio.model.Dashboard.Widget;
import name.abuchen.portfolio.money.Values;
import name.abuchen.portfolio.ui.views.dataseries.DataSeries;
import name.abuchen.portfolio.util.Interval;

public class IRRAdjustedWidget extends IndicatorWidget<Double>
{
public IRRAdjustedWidget(Widget widget, DashboardData dashboardData)
{
super(widget, dashboardData, false, null);
this.setFormatter(Values.Percent2);

addConfig(new DataSeriesConfig(this));
}

@Override
public Supplier<Double> getUpdateTask()
{
return () -> {
double irrBench = 0;
Interval reportingPeriod = get(ReportingPeriodConfig.class).getReportingPeriod()
.toInterval(LocalDate.now());
DataSeries dsBench = get(DataSeriesConfig.class, 1).getDataSeries();
if (dsBench != null)
{
irrBench = getDashboardData().calculate(dsBench, reportingPeriod).getPerformanceIRR();
}

double irr = getDashboardData().calculate(get(DataSeriesConfig.class).getDataSeries(), reportingPeriod)
.getPerformanceIRR();
return (irrBench != -1) ? (1 + irr) / (1 + irrBench) - 1 : irr - irrBench;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ public DashboardData getDashboardData()

public <C extends WidgetConfig> C get(Class<C> type)
{
return type.cast(config.stream().filter(c -> type.equals(c.getClass())).findAny()
return get(type, 0);
}

public <C extends WidgetConfig> C get(Class<C> type, int skip)
{
return type.cast(config.stream().filter(c -> type.equals(c.getClass())).skip(skip).findAny()
.orElseThrow(IllegalArgumentException::new));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public enum WidgetFactory
.withBenchmarkDataSeries(false) //
.build()),

IRR_ADJUSTED(Messages.LabelIRRAdjusted, Messages.ClientEditorLabelPerformance, IRRAdjustedWidget::new),

ABSOLUTE_CHANGE(Messages.LabelAbsoluteChange, Messages.LabelStatementOfAssets, //
(widget, data) -> IndicatorWidget.<Long>create(widget, data) //
.with(Values.Amount) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ExcessReturnDataSeriesConfig extends DataSeriesConfig
public ExcessReturnDataSeriesConfig(WidgetDelegate<?> delegate)
{
super(delegate, true, true, null, Messages.LabelExcessReturnBaselineDataSeries,
Dashboard.Config.SECONDARY_DATA_SERIES);
true, Dashboard.Config.SECONDARY_DATA_SERIES);
}

}

0 comments on commit 8cfb317

Please sign in to comment.