Core mechanism
The aggregation maps position-level values or sensitivities into a common hierarchy, combines them with specified correlations or netting rules, and exposes standalone, diversified and residual contributions.
TeaVM Java nets named equity delta factors into a portfolio, then applies NablaTensor NestedAggregation with editable within-bucket and across-bucket correlations.
| Trade | Bucket | Name | Delta |
|---|---|---|---|
| T1 | Tech | AAPL | |
| T2 | Tech | MSFT | |
| T3 | Tech | GOOG | |
| T4 | Financials | JPM | |
| T5 | Financials | GS |
This exact source runs in TeaVM. Form changes update its Java literals and reset manual edits.
import com.nablatensor.risk.NestedAggregation;
import com.nablatensor.risk.RiskFactor;
import com.nablatensor.risk.Sensitivities;
public final class PortfolioAggregationRiskStudio {
public static void main(String[] args) {
double[] d = {
3200000, 2100000, -1400000, 1800000, 900000
};
double rho = 0.6, gamma = 0.2;
String[] buckets = {
"Tech", "Tech", "Tech", "Financials", "Financials"
}, names = {
"AAPL", "MSFT", "GOOG", "JPM", "GS"
};
Sensitivities.Builder builder = Sensitivities.builder();
double standalone = 0;
for (int i = 0; i < d.length; i++) {
builder.add(RiskFactor.equityDelta(buckets[i], names[i]), d[i]);
standalone += Math.abs(d[i]);
}
Sensitivities book = builder.build();
NestedAggregation.Result result = NestedAggregation.delta(f -> 1.0, (a, b) -> a.equals(b) ? 1.0 : (a.bucket()
.equals(b.bucket()) ? rho : 0.0), (a, b) -> a.equals(b) ? 1.0 : gamma)
.aggregate(book);
System.out.println("RESULT|" + standalone + "|" + result.total() + "|" + (standalone - result.total()));
for (String bucket : new String[] {
"Tech", "Financials"
}) System.out.println("BUCKET|" + bucket + "|" + result.kb()
.get(bucket));
}
}
Portfolio risk combines positions through netting and dependence; simply adding standalone risks loses both diversification and concentration effects.
The aggregation maps position-level values or sensitivities into a common hierarchy, combines them with specified correlations or netting rules, and exposes standalone, diversified and residual contributions.
Define the legal and economic aggregation hierarchy first, validate identifiers and currencies, calculate leaf risks consistently, then explain changes through contribution and diversification reports.
*Keywords: portfolio greeks aggregation, netting set sensitivities, per-trade adjoint aggregate, risk factor bucketing java*
Each trade is recorded and risked on its own tape. The portfolio, netting-set and bucket views are plain addition of the resulting sensitivity vectors — the aggregation layer (nablatensor-risk) never touches a kernel.
The Phase-2 definition of done: per-trade adjoint sensitivities, aggregated to the book, reconcile to a full one-factor-at-a-time bump grid on the whole book — for a mixed long/short book across two equity names in two SBM buckets, to 1%. The netting-set split (NS_A + NS_B) reconstructs the book exactly.
delta/vega: D(w)=w², R(c)=c, ψ=1; curvature: D(w)=max(w,0)², R(c)=c², ψ(a,b)=0 iff both negative. withConcentration(CR) adds the SIMM CR_k-scaling and f_kl = min/max within-bucket correction. NestedAggregationTest reconciles all of this to hand arithmetic.
Correlation-based diversification is model-dependent and can vanish in stress. Legal netting and capital-recognition rules cannot be inferred from a portfolio tree alone.