SharpeRatioPortfolioObjective<T>
Models & Types · AiDotNet.Finance.Portfolio
The Sharpe-ratio training objective and the sum-normalizing allocation layer for
GraphAttentionPortfolio (Korangi, Mues and Bravo, arXiv:2407.15532).
For Beginners
The Sharpe ratio is return divided by volatility — reward per unit of risk. This trains the model to maximize it directly, and allocates capital in a way that can leave an asset out completely rather than giving everything a sliver.
How It Works
The loss is LF = -ln(mu_p) + ln(sigma_p), which is -ln(mu_p / sigma_p) — the negative
log Sharpe ratio. Maximizing a ratio is awkward for a gradient optimizer; taking the negative log
turns it into a plain minimization and splits the ratio into two additive terms.
Allocation does NOT use a softmax, and that is a deliberate finding of the paper rather than
an omission: with an investment universe of thousands of firms a softmax “would lead to many tiny
holdings of firms, which is impractical and can bring high transaction costs”. Softmax cannot emit
an exact zero, so every asset always receives some capital. Instead the weights are
w_u = s_u / sum_v s_v over non-negative scores, so any score driven to zero — which the L1
regularization on the preceding feed-forward layer is there to do — produces a weight of EXACTLY
zero and the firm drops out of the portfolio entirely. The paper also considered sparsemax and
reported this mechanism as more stable, with a smoother loss curve and more reproducible weights
across runs.
Constructors
| Constructor | Summary |
|---|---|
SharpeRatioPortfolioObjective() |
Methods
| Method | Summary |
|---|---|
T L1Penalty(Vector<T> scores) |
L1 penalty sum |s_i| over the final-layer scores. |
T Loss(Vector<T> portfolioReturns) |
The training loss LF = -ln(mu_p) + ln(sigma_p). |
T SharpeRatio(Vector<T> portfolioReturns) |
The Sharpe ratio mu_p / sigma_p, assuming a zero risk-free rate as the paper does. |
ValueTuple<T, T> Moments(Vector<T> portfolioReturns) |
Mean and (population) standard deviation of a portfolio return series. |
Vector<T> Allocate(Vector<T> scores) |
The paper’s “Importance Layer”: w_u = s_u / sum_v s_v over non-negative scores. |
Vector<T> PortfolioReturns(Vector<T> weights, Tensor<T> assetReturns) |
Portfolio return series for a fixed allocation: r_pt = sum_i w_i * r_it. |
int ActivePositions(Vector<T> weights) |
Number of assets receiving a strictly positive allocation. |
Fields
| Field | Summary |
|---|---|
double LosingPortfolioPenalty |
The loss floor assigned to a portfolio whose mean return is not positive. |
double MeanReturnFloor |
Floor applied to the mean return before taking its logarithm. |