-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added adjusted internal rate of return #2975
Open
Lasall
wants to merge
1
commit into
portfolio-performance:master
Choose a base branch
from
Lasall:feature_adjusted_irr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the business logic of the widget, and it’s wrong. Since the IRR is money-weighted, it is not enough to just subtract the benchmark; you need to correct the whole data series by the benchmark before calculating the IRR.