-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Update IRR widget to add benchmark. That way the inflation adjusted IRR can be displayed by selecting a relevant consumer price index as benchmark.
- Loading branch information
Showing
5 changed files
with
108 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...uchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/dashboard/IRRDataSeriesConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package name.abuchen.portfolio.ui.views.dashboard; | ||
|
||
import org.eclipse.jface.action.IMenuManager; | ||
import org.eclipse.jface.action.Separator; | ||
|
||
import name.abuchen.portfolio.model.Dashboard; | ||
import name.abuchen.portfolio.ui.Messages; | ||
import name.abuchen.portfolio.ui.util.SimpleAction; | ||
|
||
public class IRRDataSeriesConfig extends DataSeriesConfig | ||
{ | ||
|
||
public IRRDataSeriesConfig(WidgetDelegate<?> delegate) | ||
{ | ||
super(delegate, false, true, true, null, Messages.LabelBenchmarks, | ||
Dashboard.Config.SECONDARY_DATA_SERIES); | ||
} | ||
|
||
@Override | ||
public void menuAboutToShow(IMenuManager manager) | ||
{ | ||
super.menuAboutToShow(manager); | ||
if (getDataSeries() != null) | ||
{ | ||
IMenuManager subMenu = manager.findMenuUsingPath(Dashboard.Config.SECONDARY_DATA_SERIES.name()); | ||
subMenu.add(new Separator()); | ||
subMenu.add(new SimpleAction(Messages.MenuReportingPeriodDelete, a -> removeBenchmark())); | ||
} | ||
|
||
} | ||
|
||
private void removeBenchmark() | ||
{ | ||
if (getDataSeries() == null) | ||
return; | ||
|
||
setDataSeries(null); | ||
getDelegate().getWidget().getConfiguration().remove(Dashboard.Config.SECONDARY_DATA_SERIES.name()); | ||
getDelegate().getWidget().setLabel(WidgetFactory.valueOf(getDelegate().getWidget().getType()).getLabel()); | ||
getDelegate().update(); | ||
getDelegate().getClient().touch(); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/dashboard/IRRWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 IRRWidget extends IndicatorWidget<Double> | ||
{ | ||
public IRRWidget(Widget widget, DashboardData dashboardData) | ||
{ | ||
super(widget, dashboardData, false, null); | ||
this.setFormatter(Values.Percent2); | ||
|
||
addConfig(new IRRDataSeriesConfig(this)); | ||
} | ||
|
||
@Override | ||
public Supplier<Double> getUpdateTask() | ||
{ | ||
return () -> { | ||
double irrBench = 0; | ||
Interval reportingPeriod = get(ReportingPeriodConfig.class).getReportingPeriod() | ||
.toInterval(LocalDate.now()); | ||
DataSeries dsBench = get(IRRDataSeriesConfig.class).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; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters