public enum ReturnsCalculators extends Enum<ReturnsCalculators> implements ReturnsCalculator
The arguments to computeReturn are the beginning value followed
by the ending value, measured in the same units. SIMPLE returns a
fraction: 0.05 means five percent. LOG returns the natural
logarithm of the price ratio; ABSOLUTE returns a change in price
units. These operations do not annualize or account for cash flows.
For conventional price returns, use strictly positive prices. The
implementations do not validate the price domain: zero denominators or
invalid logarithm arguments can produce infinities or NaN. Pass a return
in the selected convention to computePrice.
import tech.nmfin.returns.ReturnsCalculators;
double simple = ReturnsCalculators.SIMPLE.computeReturn(100.0, 105.0);
double log = ReturnsCalculators.LOG.computeReturn(100.0, 105.0);
assert Math.abs(simple - 0.05) < 1e-12;
assert Math.abs(log - Math.log(1.05)) < 1e-12;
assert Math.abs(ReturnsCalculators.SIMPLE.computePrice(100.0, simple) - 105.0) < 1e-12;
assert Math.abs(ReturnsCalculators.LOG.computePrice(100.0, log) - 105.0) < 1e-12;
| Enum Constant and Description |
|---|
ABSOLUTE
The return is defined as the difference between the values of the
portfolio. i.e.,
\[
r = v_2-v_1
\]
|
LOG
The return is defined as the natural logarithm of the ratio
v2/v1.
|
SIMPLE
The return is defined as the absolute return over the original value.
|
| Modifier and Type | Method and Description |
|---|---|
abstract double |
computePrice(double px0,
double r)
Computes the next price after a return.
|
abstract double |
computeReturn(double v1,
double v2)
Computes the portfolio return.
|
static ReturnsCalculators |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static ReturnsCalculators[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final ReturnsCalculators ABSOLUTE
public static final ReturnsCalculators SIMPLE
public static final ReturnsCalculators LOG
public static ReturnsCalculators[] values()
for (ReturnsCalculators c : ReturnsCalculators.values()) System.out.println(c);
public static ReturnsCalculators valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic abstract double computeReturn(double v1,
double v2)
ReturnsCalculatorcomputeReturn in interface ReturnsCalculatorv1 - the beginning value of the portfoliov2 - the ending value of the portfoliopublic abstract double computePrice(double px0,
double r)
ReturnsCalculatorcomputePrice in interface ReturnsCalculatorpx0 - the original pricer - the returnCopyright © 2010-2026 NM Group. All Rights Reserved.