Risk-aware Trading Portfolio Optimization Marco Bianchetti, Gabriele D’Acunto, Gianmarco De Francisci Morales, Yuko Kuroki, Marco Scaringi, Fabio Vitale Abstract We investigate portfolio optimization in financial markets from a trading and risk management perspective. We term this task Risk-Aware Trading Portfolio Optimization (RATPO), formulate the corresponding optimization problem, and propose an efficient Risk-Aware Trading Swarm (RATS) algorithm to solve it. The key elements of RATPO are a generic initial portfolio 𝒫 \mathcal{P} , a specific set of Unique Eligible Instruments (UEIs), their combination into an Eligible Optimization Strategy (EOS), an objective function, and a set of constraints. RATS searches for an optimal EOS that, added to 𝒫 \mathcal{P} , improves the objective function repecting the constraints. RATS is a specialized Particle Swarm Optimization method that leverages the parameterization of 𝒫 \mathcal{P} in terms of UEIs, enables parallel computation with a large number of particles, and is fully general with respect to specific choices of the key elements, which can be customized to encode financial knowledge and needs of traders and risk managers. We showcase two RATPO applications involving a real trading portfolio made of hundreds of different financial instruments, an objective function combining both market risk (VaR) and profit&loss measures, constrains on market sensitivities and UEIs trading costs. In the case of small-sized EOS, RATS successfully identifies the optimal solution and demonstrates robustness with respect to hyper-parameters tuning. In the case of large-sized EOS, RATS markedly improves the portfolio objective value, optimizing risk and capital charge while respecting risk limits and preserving expected profits. Our work bridges the gap between the implementation of effective trading strategies and compliance with stringent regulatory and economic capital requirements, allowing a better alignment of business and risk management objectives. JEL classifications : D8, H51. MSC Classification : 35A01, 65L10, 65L12, 65L20, 65L70. Keywords : Portfolio optimization, risk management, trading, particle swarm optimization. Acknowledgements : the authors contributed equally to this work. The authors acknowledge fruitful discussions with many colleagues from Intesa Sanpaolo Risk Management and Front Office Departments, Francesco Terribile and Pietro Gallo from Politecnico di Milano, who collaborated to the early stage of this work, Luca Lamorte, who joined at later stage, and Laura Li Puma, Arianna Miola, and Luigi Ruggerone from Intesa Sanpaolo Innovation Center for supporting the research team. Marco Scaringi declares that the views and opinions expressed here are his own and do not represent the views of his previous or current employers; they are not responsible for any use that may be made of these contents. 1 Introduction The financial crisis started in 2007, and the subsequent period of severe market stresses revealed weaknesses in the risk capital framework of the global banking and financial system. Since then, regulators increased pressure towards risk-based capital reserves. The Basel Committee on Banking Supervision (BCBS), the main international body that develops global banking standards, issued the so-called Basel III and Basel IV accords ( Basel Committee on Banking Supervision, 2011 ; Basel Committee on Banking Supervision, 2017 ), introducing substantial amendments to the capital treatment of all risk classes (market, liquidity, counterparty, credit and operational risk). 1 1 1 The BCBS also maintains the “Basel Framework” ( https://www.bis.org/basel_framework ) which provides a comprehensive and updated compendium of BCBS financial regulations. The BCBS proposals are transposed into legal frameworks by national and international authorities. 2 2 2 The European Union transposed the after-crisis BCBS proposals into the so-called CRD4/CRR package in 2013 ( CRD4, 2013 ; CRR1, 2013 ), the amended CRD5/CRR2 package in 2019 ( CRD5, 2019 ; CRR2, 2019 ), and the further amended CRD6/CRR3 package in 2024 ( CRD6, 2024 ; CRR3, 2024 ), the latter to enter into force in January 2025 and January 2026, respectively. The European Banking Authority (EBA) maintains the Interactive Single Rulebook ( https://www.eba.europa.eu/single-rulebook ) which provides a comprehensive compendium of EU financial regulations and related Q&As. The trading and risk management practices of financial institutions has developed according to regulatory requests. Nowadays, banks typically put huge efforts into research, development, implementation, and production of several different risk measures, which are the main inputs to compute capital reserves, both for regulatory purposes (regulatory capital and Risk-Weighted Assets—RWA) and internal managerial purposes (economic capital). In particular, market risk measures (e.g., Value at Risk, Stressed Value at Risk, Incremental Risk Charge) are typically computed with daily frequency, both for managerial reporting to trading desks, and to determine quarterly averages for regulatory reporting of capital reserves. Budgets for human and IT resources for risk management purposes have increased accordingly. Our goal: risk-aware trading portfolio optimization In the “classic” portfolio optimization approach à la Markowitz ( Markowitz, 1952 ), the point of view of portfolio managers typically prevails, who focus on dynamic forward-looking estimates of return and risk by selecting a portfolio of assets and looking for a strategy to adjusts the assets’ weights over a given time horizon T-t , where t is the rebalancing date. In this work, we focus on a different problem, named risk-aware trading portfolio optimization , where we take the point of view of the bank’s traders and risk managers, who focus on statical portfolio risk measurement and features at a given point in time t , and look for optimal trades at the same time t to reduce capital reserves while preserving portfolio value, consistently with the business objectives. This view, characterizing our approach, represents a stark difference with Markowitz’s framework. Another distinguishing feature of our approach concerns the full generality with respect to the portfolio composition. More in detail, we consider large heterogeneous trading portfolios typical of commercial or investment banks, potentially encompassing millions of financial instruments such as stocks, securities, loans, derivatives, and funds, depending on any underlying risk factors , i.e., interest rates, credit, equity, forex, and commodities. These positions can feature any level of complexity : linear and non-linear payoffs, plain vanilla and exotic options, multi-asset and hybrid derivatives. They are managed through appropriate pricing models and computational algorithms such as analytical formulas and Monte Carlo simulations. Moreover, trading portfolios are characterized by continuous turnover , driven by expiry of old trades, flows of new trades with clients, proprietary investments, speculative or hedging strategies, and generate continuous in/out cash flows related to received/paid coupons, collateral exchange, financing operations, and fees. Furthermore, in our approach portfolio risks are measured through various risk measures that capture all the different risk sources, e.g., market risk, liquidity risk, credit and counterparty risk, and valuation risk. 3 3 3 Valuation risk is captured by appropriate valuation risk measures such as fair value adjustments, required by EU accounting standards (IFRS, https://www.ifrs.org ), and Additional Valuation Adjustments (AVA) deducted from Common Equity Tier 1 capital, required by EU prudential regulation ( CRR3, 2024 ), etc., which ultimately determine the capital structure of the Bank. These risks are managed within a global Risk Appetite Framework (RAF) 4 4 4 RAF guidelines are issued by the Basel Committee of Banking Supervision ( Basel Committee on Banking Supervision, 2015 ) and transposed by the EU into CRD/CRR packages. , a structured approach used by Banks to define, manage, and align their willingness to assume risks in pursuit of their business objectives. The RAF is based on risk limits , which are set, monitored, and reported by a risk management unit independent of business units. Core components Several crucial components characterize our risk-aware trading portfolio optimization approach. unique eligible instruments are the main building blocks used to optimize the portfolio: they uniquely identify liquid market instruments quoted by exchanges, brokers, or market makers, typically used by traders for risk management purposes, i.e., to hedge Delta, Vega, and Gamma risks. Portfolio optimization is encoded through eligible optimization strategies , i.e., combinations of unique eligible instruments added to the portfolio to optimize the selected objective function , while complying with a set of constraints and adhering to a specific structure reflecting the prior financial knowledge of the bank’s traders and risk managers. The objective function consists of a combination of portfolio risk measures and features such as profit and loss measures and market transaction costs. Instead, the constraints are associated with risk limits to effectively drive the optimization process. More details and practical examples of these core components are included in the following sections. Challenges Our risk-aware trading portfolio optimization problem presents numerous challenges. The objective function is typically non-linear and its computation, particularly in the case of risk measures based on historical or Monte Carlo simulation, can require substantial computational resources. The unique eligible instruments are determined by various parameters, which are either intrinsically categorical (e.g., payoff type, currency, underlying asset), or are quoted in market-discrete values (e.g., maturity, strike), though some can be approximated continuously (e.g., notional amounts). Hence, a candidate eligible optimization strategy is represented by a set of values of the relevant parameters. However, the sheer number of potential combinations of the parameters’ values makes the brute-force approach (i.e., the direct calculation of all possible solutions) unfeasible even for simple portfolios and optimization strategies. Additionally, not every optimization strategy satisfies the optimization constraints, depending on their tightness (the tighter the constraints, the fewer eligible solutions). Finally, the global optimal solution is often hidden among numerous similar local optima due to the inherent complexity of the objective function landscape. Optimization meta-heuristics From a computational point of view, we must solve a multidimensional, non-linear, constrained optimization problem with integer variables, where the value of the objective function may change abruptly, thus complicating the search for a global minimum. Since simple techniques are insufficient for such complex problems, numerical algorithms based on optimization meta-heuristics are typically used. These techniques are recognized as efficient approaches for optimization problems that cannot be exactly solved in a “reasonable” time limit, overcoming incomplete initial information or limited computation capacity, and sampling a portion of the entire set of solutions that is too large to be completely explored. Even though these algorithms do not guarantee to converge to the global optimum in a finite computational time, their application to our optimization problem is beneficial, since also local optima leading to appreciable improvements of the objective function are valuable from a financial point of view. A complete overview of optimization meta-heuristics is presented by Boussaid et al., 2013 , who distinguish between single solution based algorithms, such as Simulated Annealing ( Kirkpatrick et al., 1983 ), which start with a single initial solution and move along a trajectory in the search space, and population based algorithms, which explore the search space using a population of different solutions evolving according to some rules, such as Genetic Algorithms (GA, Holland, 1992 ), and Particle Swarm Optimization (PSO, Kennedy & Eberhart, 1995 ). Related literature The classic portfolio optimization problem following Markowitz, 1952 is widely discussed in the literature, also using optimization meta-heuristics ( Dallagnol et al., 2009 ; Soleimani et al., 2009 ) and even quantum computers ( Rosenberg et al., 2016 ; Venturelli & Kondratyev, 2019 ). Conversely, to the best of our knowledge, the risk-aware trading portfolio optimization problem introduced above represents an understudied topic. Our work was initially motivated by Kondratyev & Giorgidze, 2017 , who use GA and PSO meta-heuristics to search optimal delta hedging strategies in the context of Margin Valuation Adjustment optimization. 5 5 5 Margin Valuation Adjustment is a valuation adjustment which takes into account the cost of financing initial margin collateralization of OTC derivatives, see e.g. Gregory, 2020 ; Green, 2015 . This seminal work is limited to a specific and very simple setting: a toy portfolio of USDCNY Non Deliverable FX Forwards (NDF, i.e., linear instruments on a single exchange rate) exchanged between two out of five counterparties, one single optimization instrument (the USDCNY NDF itself), and no optimization constraints beyond trading cost. An apparent application to collateral optimization with multiple Central Counterparties is found in Erekhinsky, 2017 . The idea of portfolio optimization based on market risk measures is obviously not new. For example, Rockafellar & “&, 2000 and Larsen et al., 2002 minimize Conditional Value at Risk (a.k.a. Expected Shortfall) using analytical approaches and linear programming techniques. Gaivoronski & Pflug, 2005 determine an optimal Value at Risk portfolio with a given expected return. Gilli et al., 2006 determine optimal quantities of n assets which minimize different risk functions for a given return target under constraints on the assets’ sizes. Faias & Santa-Clara, 2011 , Faias & Santa-Clara, 2017 and Dao, 2014 consider simplified European options’ portfolios. Also the idea of portfolio optimization based on meta-heuristics is largely explored in the literature. Chang et al., 2009 solve portfolio optimization problems by employing GA and risk measures based on Markowitz’s mean-variance, semi-variance, mean absolute deviation, and variance with skewness. Deng et al., 2012 introduce an improved PSO to solve the Cardinality Constraints Markowitz Portfolio Optimization problem. Das et al., 2023 compare PSO, GA, Dynamic Programming, and Differential Evolutionary Algorithm algorithms for portfolio optimization in the NIFTY 50 market using Sharpe Ratio and expected return. Jun & Johar, 2023 use PSO to maximize the Sharpe Ratio of portfolios of Exchange-Traded Funds, demonstrating its effectiveness in achieving higher risk-adjusted returns compared to traditional methods. Erwin & Engelbrecht, 2023a develop a Multi-Guide Set-Based Particle Swarm Optimization for multi-objective portfolio optimization, and test it against established algorithms. Excellent reviews by Fabozzi et al., 2010 , Ertenlice & Kalayci, 2018 , Erwin & Engelbrecht, 2023 , Loke et al., 2023 and Gunjan & Bhattacharyya, 2023 are available. Erwin & Engelbrecht, 2023 review 140 studies using evolutionary and swarm intelligence algorithms for portfolio optimization, finding that meta-heuristic approaches as more computationally efficient. Our contributions With the partial exception of Kondratyev & Giorgidze, 2017 , none of the cited works addresses the challenges of the risk-based trading portfolio optimization problem investigated in this paper. Specifically, our contributions are outlined below. We introduce and formalize the risk-aware trading portfolio optimization problem, taking the point of view of the bank’s traders and risk managers. Toward our goal, we introduce and consequently leverage the key concepts of the unique eligible instruments and eligible optimization strategies, also including options to allow Delta, Vega, and Gamma optimization. We propose a modified PSO algorithm, called Risk-Aware Trading Swarm (RATS), incorporating a specialized parameterization built around the concepts of the unique eligible instruments and eligible optimization strategy. RATS is a versatile framework that leverages the parallelizable nature of the optimization problem with respect to the particle dimension and can be adapted to different trading portfolios, objective functions, and constraints. Additionally, its parameterization enables users to incorporate their financial insights and business views by directly shaping the structure of the eligible optimization strategies. We showcase two applications on a real trading portfolio typical of large banks, made of hundreds of financial instruments of different kinds, using real market data and tradable optimization instruments. In both cases, we seek an eligible optimization strategy that, when combined with the initial portfolio, optimizes a fractional, non-convex objective function over a non-convex set of eligible optimization strategies defined by the constraints. Inspired by the practical needs of traders and risk managers, the objective function accounts for the Value at Risk measure, expected P&L, and trading costs. In addition, the set of constraints includes sensitivity limits; while the size of the eligible optimization strategy, its diversification, and the maximum nominal amount are handled directly via the proposed parameterization. In the first application, focused on a small-sized optimization strategy, RATS successfully identifies an optimal solution within the optimal solution set and demonstrates robustness to hyper-parameters tuning across all tested scenarios. In the second application, involving a large-sized optimization strategy, RATS markedly improves the cost-adjusted expected P&L and risk measures of the initial portfolio in every setting. At a high level, our work overcomes our inspiring paper by Kondratyev & Giorgidze, 2017 and bridges the gap between complying with stringent regulatory requirements and implementing effective trading strategies that align with the objectives of both business units and risk management. Roadmap This paper is organized as follows. Section 2 provides the fundamental concepts underlying the risk-aware trading portfolio problem. Then, Section 3 formalizes the risk-aware trading portfolio optimization problem. Next, Section 4 describes the proposed method, i.e., RATS. Section 5 provides the results of our empirical assessment. In detail, Section 5.1 specifies the setting and the building blocks of the risk-aware trading portfolio optimization problem. Section 5.2 compares our approach to Markowitz-like approaches, highlighting their limitations and key differences. Subsequently, Section 5.3 explores the small-sized application setting, and Section 5.4 addresses the large-sized one. Finally Section 6 draws the conclusions and outlines future research directions. 2 Preliminaries This section provides the basic notation and key concepts that underlie the risk-aware trading portfolio problem. We start the discussion at the individual financial instrument level and then move to the portfolio level. Notation We denote by [n] the set \{1,2,\ldots,n\} with n\in\mathbb{N} . Scalars are lowercase letters, a , vectors are lowercase bold, \mathbf{a} , matrices are uppercase bold, \mathbf{A} , sets are uppercase calligraphic, \mathcal{A} , elements of a set are uppercase, A . Given a , we denote \max(a,0) by [a]_{+} . The multiset union operator is \uplus . The element-wise (Hadamard) product is denoted by \circ . We use subscripts for indices, while superscripts are used for everything else. Given an n -dimensional vector \mathbf{a} and a permutation \prec such that \mathbf{a}^{\prec}=[a^{\prec}_{1},\dots,a^{\prec}_{n}] is increasing, we denote by the sort operator such that \mathbf{a}^{\prec}= . The discrete uniform distribution is U\{a,b\} , whereas the continuous one is U(a,b) . We work in a static setting, that is, a fixed point in time t . Hence, throughout the paper, we omit any reference to time without any ambiguity, also to ease the notation. Unique instruments We consider financial instruments of any type, such as fundamental assets (e.g., stocks), derivatives (e.g., swaps, options), securities (e.g., government and corporate bonds), and loans (e.g., mortgages). We identify a financial instrument having a unitary nominal amount with a set of m (categorical) parameters, namely \{\phi_{1},\ldots,\phi_{m}\} . The parameters \phi_{i} can vary in their corresponding domains \mathcal{D}^{\phi_{i}} . We term the sequence given by concatenating the values of the latter parameters unique instrument (UI). For instance, consider a vanilla option. A possible parameterization is given by four parameters, i.e., the ticker of the underlying, the payoff type, the strike, and the time-to-maturity. In this case, a UI is a sequence obtained by concatenating the four values of the previous parameters, each belonging to the associated domain. Additional parameters can be considered according to the application need (e.g., currency, dividends, counterparty). Risk factors and risk scenarios The UI is associated with a set of random variables \mathcal{R}=\{R_{1},\ldots,R_{n}\} , called risk factors , which fully determine its price. For instance, in the case of an option, key risk factors are the price of the underlying S , the implied volatility \sigma , the interest rate R , and the dividend rate D . Each risk factor can be associated with a risk distribution, quantifying the likelihood of different values in the risk factor. Hence, estimating the risk distribution enables the simulation of risk scenarios for the risk factor. We denote the dataset of risk scenarios by \mathcal{F} . Unique instruments features Features can characterize unique instruments, and we generally refer to them as \varphi^{G} . They can be either observed on the market, thus part of the market data \mathcal{M} , or computed by using risk factors \mathcal{R} and risk scenarios \mathcal{F} . Below we provide those relevant to our empirical assessment in Section 5 . Value. Consider a UI, namely G . We indicate its value by v^{G} . The value can be either marked to market , in which case the value is quoted on the market, or marked to model , when the value is computed using a specific pricing model involving the relevant risk factors. Pricing models can be chosen according to the institution’s internal pricing policy. Additionally, they may be calibrated to their reference plain vanilla instruments, and may be based on different numerical approaches (e.g., analytical formulas or Monte Carlo simulations). Profit and loss. The proposed framework is based on historical scenarios of risk factors \mathcal{F} and the corresponding profit and loss ( \mathrm{P\&L} ) distribution. These scenarios simulate past market variations at a fixed point in time t to assess changes in the UI value. Consider s simulated scenarios. We obtain s historical \mathrm{P\&L} r^{G}_{i} , with i\in[s] , as follows. Denote by v^{G}_{0} and v^{G}_{i} the value of the UI at t and at the i -th simulated scenario, respectively. Hence, we have r^{G}_{i}=v^{G}_{i}-v^{G}_{0},\quad i\in[s]\,. (1) We arrange the previous historical \mathrm{P\&L} in the vector \mathbf{r}^{G}=[r^{G}_{1},\ldots,r^{G}_{s}]^{\top} . Greeks. UIs can be characterized by the sensitivity of their value v^{G} to changes in the underlying risk factors \mathcal{R} . These sensitivities are known as Greeks . We introduce below the most important Greeks typically used for risk management and trading purposes. Delta is the sensitivity of v^{G} with respect to changes in the underlying price S^{G} , \Delta^{G}=\partialderivative{\val^\ui}{S^\ui}\,. (2) Vega is the sensitivity of v^{G} with respect to changes in the implied volatility of the underlying asset \sigma^{G} , \mathcal{V}^{G}=\partialderivative{\val^\ui}{\sigma^\ui}\,. (3) Gamma is the sensitivity of Delta with respect to changes in the underlying price S^{G} , \Gamma^{G}=\partialderivative[2]{\val^\ui}{{S^\ui}}\,. (4) Trading cost. Trading financial instruments incurs trading costs. It is market practice to measure such costs in terms of sensitivity, i.e., Delta for linear instruments and additionally Vega for options. Given a UI, namely G , we denote such contributions deriving from the buying of a unitary notional amount of G by c^{\Delta^{G}} and c^{\mathcal{V}^{G}}\in\mathbb{R}^{+} , respectively. Hence, the cost for buying a unitary notional amount of G is c^{G}=c^{\Delta^{G}}\!\!+c^{\mathcal{V}^{G}}\,. (5) The computation of c^{\Delta^{G}} and c^{\mathcal{V}^{G}} is specific to the nature of G . Henceforth, we provide the cases of stocks, futures on equity indexes, and European call and put options, which are instrumental for the empirical assessment in Section 5 . Denote by (i) \delta the market bid/ask spread for the underlying corresponding to G , (ii) \delta^{q} the market bid/ask spread for futures, and (iii) \delta^{K} the market bid/ask spread for the European options with strike K (expressed as Delta-percentage). The cost contributions for the corresponding UIs are c^{\Delta^{G}}=\begin{cases}\frac{1}{2}\Delta^{G}\delta&\text{if $G$ is either a stock, or a call, or a put},\\ \frac{1}{2}\delta^{q}&\text{if $G$ is a futures};\end{cases} (6) and c^{\mathcal{V}^{G}}=\begin{cases}\frac{1}{2}\mathcal{V}^{G}\delta^{K}&\text{if $G$ is either a call or a put},\\ 0&\text{otherwise}.\end{cases} (7) Portfolio parameterization A portfolio is canonically viewed as a collection of financial instruments with nominal amounts different from zero. The value of a financial instrument may be specified in terms of a unitary value in a given currency times the notional amount. In our setting, the unitary value is the value v^{G} of the corresponding UI. Accordingly, we represent the portfolio as a pair \langle\mathcal{G},\mathbf{g}\rangle , where \mathcal{G}=\{G_{1},\ldots,G_{n}\} is the set of UIs in the portfolio, and \mathbf{g}=[g_{1},\ldots,g_{n}]^{\top} is the integer vector of their corresponding notional amounts, representing long and short positions. Such portfolio parameterization is particularly convenient during optimization. First, it enables the search on UIs and nominal amounts to be separated. Second, it allows the portfolio features and risk measures to be expressed in terms of those of the constituting UIs. Accordingly, we can compute relevant features and risk measures at the UI level during the initialization phase. Then, instead of recomputing from scratch the portfolio features and risk measures by means of pricing functions at each iteration, we exploit the stored values during the optimization process thus reducing the computational burden (see Section 4 ). Portfolio features As in the case of the UI, we can associate features with a financial portfolio. By exploiting the parameterization \langle\mathcal{G},\mathbf{g}\rangle , the portfolio feature \varphi(\mathcal{G},\mathbf{g}) can be written as a linear combination of the UIs’ feature \varphi^{G_{j}} , where the coefficients a(g_{j}) depend on the notional amount associated with each UI. Mathematically, \varphi(\mathcal{G},\mathbf{g})=\sum_{j}^{n}a(g_{j})\varphi^{G_{j}}\,. (8) Starting from Equations 1 , 2 , 3 , 4 and 5 , exploiting Equation 8 , the portfolio features relevant to our empirical assessment read as \displaystyle v^{\mathcal{G}} \displaystyle=\sum_{j}^{n}g_{j}v^{G_{j}},\quad\text{(Value)} (9) \displaystyle r^{\mathcal{G}}_{i} \displaystyle=\sum_{j}^{n}g_{j}r^{G_{j}}_{i},\quad\text{($\mathrm{P\&L}$ for the $i$-th risk scenario, $i\in[s]$)} \displaystyle\Delta^{\mathcal{G}} \displaystyle=\sum_{j}^{n}g_{j}\Delta^{G_{j}},\quad\text{(Delta sensitivity)} \displaystyle\mathcal{V}^{\mathcal{G}} \displaystyle=\sum_{j}^{n}g_{j}\mathcal{V}^{G_{j}},\quad\text{(Vega sensitivity)} \displaystyle\Gamma^{\mathcal{G}} \displaystyle=\sum_{j}^{n}g_{j}\Gamma^{G_{j}},\quad\text{(Gamma sensitivity)} \displaystyle c^{\mathcal{G}} \displaystyle=\sum_{j}^{n}c^{G_{j}}\absolutevalue{g_j}\,.\quad\text{(Trading cost)} As per the UI, we arrange the historical \mathrm{P\&L} of the portfolio in a vector, namely \mathbf{r}^{\mathcal{G}}=[r^{\mathcal{G}}_{1},\ldots,r^{\mathcal{G}}_{s}] . Additionally, the trading cost involves the absolute notional amount since the trading fee is paid for both long and short trades. Risk measures Starting from the vector of portfolio \mathrm{P\&L} , we estimate the portfolio risk measures , generally denoted by \rho(\mathcal{G},\mathbf{g}) . Below we report those relevant to our application in Section 5 . We remark that our framework is general, and is not limited to using such risk measures. First, we have the sample profit and loss \overline{\mathrm{P\&L}}^{\mathcal{G}}=\frac{1}{s}\sum_{i}^{s}r^{\mathcal{G}}_{i}\,, (10) namely the empirical mean of the vector of portfolio \mathrm{P\&L} . Second, the sample Value at Risk at the \beta percentile , namely \beta\text{-}\mathrm{VaR}^{\mathcal{G}} , obtained using decreasing scenarios weight. Consider \lambda\in(0,1) the decay factor used to give more weight to the most recent scenarios, and define \alpha=1-\beta(1-\lambda^{s}) . Then, setting i^{\star}=\lceil\ln{\alpha}/\ln{\lambda}\rceil , we have \beta\text{-}\mathrm{VaR}^{\mathcal{G}}=\left[\right]_{i^{\star}}\,, (11) viz., \beta\text{-}\mathrm{VaR}^{\mathcal{G}} is the i^{\star} -th entry of the vector of sorted portfolio \mathrm{P\&L} . 3 Risk-aware trading portfolio optimization At a high level our goal can be stated as follows. Consider an initial portfolio \langle\mathcal{P},\mathbf{p}\rangle at time t and an objective function f , which will be discussed below. Additionally, consider a set of risk- and trading-based constraints associated with portfolio features and risk measures. We want to find the portfolio \langle\mathcal{T},\mathbf{t}\rangle optimizing f , which is obtained by adding to \langle\mathcal{P},\mathbf{p}\rangle a suitable eligible optimization strategy (EOS), denoted by \langle\mathcal{H},\mathbf{h}\rangle , complying with the specified constraints. Mathematically, \langle\mathcal{T},\mathbf{t}\rangle\coloneqq\left\langle\mathcal{P}\uplus\mathcal{H},\left[\mathbf{p}^{\top},\mathbf{h}^{\top}\right]^{\top}\right\rangle\,. (12) We call this task risk-aware trading portfolio optimization (RATPO). In the sequel, we formulate the general RATPO problem. Looking at RATPO, the first key ingredient is the initial portfolio \langle\mathcal{P},\mathbf{p}\rangle . In our work, \mathcal{P} may include any UI, as assumed throughout Section 2 . The parameterization of such UIs is static and does not depend on the specification of RATPO. Accordingly, we call \mathcal{P} the set of unique static instruments . Analogously, the vector of notional amounts \mathbf{p}\in\mathbb{Z}^{\absolutevalue{\asstP}} is fixed during the optimization process. The second key ingredient is the objective function f . Consider (i) a set of p portfolio risk measures, \rho_{i}(\mathcal{T},\mathbf{t}) , i\in[p] ; and (ii) a set of q portfolio features \varphi_{j}(\mathcal{T},\mathbf{t}) , j\in[q] . The family of objective functions considered in RATPO is a general combination of (possibly nonconvex) risk measures and portfolio features. Specifically, f(\mathcal{T},\mathbf{t})\stackrel{{\scriptstyle(a)}}{{=}}f(\mathcal{H},\mathbf{h};\mathcal{P},\mathbf{p})\coloneqq f\left(\rho_{1},\ldots,\rho_{p},\varphi_{1},\ldots,\varphi_{q}\right); (13) where in (a) we recognize that \langle\mathcal{P},\mathbf{p}\rangle is fixed during the optimization. Additionally, in Equation 13 we omit the arguments for risk measures and the portfolio features to enhance readability. The specific risk measures, portfolio features, and functional form of f can be chosen according to the application’s need, as demonstrated in the empirical assessment in Section 5 . The third key ingredient is a set of z inequality and equality constraints, \psi_{i}(\mathcal{H},\mathbf{h};\mathcal{P},\mathbf{p}) , i\in[z] . Similarly to the objective function, each constraint can be a combination of (possibly nonconvex) risk measures and portfolio features, depending on the application need. The constraints entail the set of feasible EOS, denoted by \mathcal{E} , which can be nonconvex. Next, the fourth key ingredient is the total portfolio \langle\mathcal{T},\mathbf{t}\rangle . Starting from Equation 12 , the considered universe of UIs in RATPO, namely \mathcal{U} such that \mathcal{T}\subseteq\mathcal{U} , consists of the multiset union of two distinct sets. The first, \mathcal{P} , is the set of UIs in the initial portfolio. The second, \mathcal{U}^{\mathcal{H}} such that \mathcal{H}\subseteq\mathcal{U}^{\mathcal{H}} , is the set of all possible UIs constituting the EOS \langle\mathcal{H},\mathbf{h}\rangle\in\mathcal{E} . The set \mathcal{U}^{\mathcal{H}} depends on the specification of RATPO since it is entailed by the Cartesian product of the domains \mathcal{D}^{\phi_{i}} associated with the parameters \phi_{i} specifying each UI H_{j} that can constitute \mathcal{H} , where j\in\left[\absolutevalue{\uiuniverse^\asstEOS}\right] . We term the H_{j} unique eligible instrument (UEI), and \mathcal{U}^{\mathcal{H}} the set of UEIs. Note that some UIs in \mathcal{P} can potentially be in \mathcal{U}^{\mathcal{H}} , depending on the application’s need. This is the reason why we use the multiset union. Now, we can pose the formal definitions for the UEI and for the EOS. Definition 1 (Unique eligible instrument, UEI) . A unique eligible instrument H_{j}\in\mathcal{U}^{\mathcal{H}} refers to a financial instrument tradable on the market at the optimization time t . It is represented as the sequence resulting from the concatenation of a combination in the Cartesian product \mathcal{D}^{\phi_{1}}\times\ldots\times\mathcal{D}^{\phi_{m}} , where \phi_{1},\ldots,\phi_{m} are the parameters determining the UEI, and \mathcal{D}^{\phi_{1}},\ldots,\mathcal{D}^{\phi_{m}} the corresponding domains. Definition 2 (Eligible optimization strategy, EOS) . An eligible optimization strategy \langle\mathcal{H},\mathbf{h}\rangle is a tradable financial strategy at time t , complying with a set of specified constraints. It is a set \mathcal{H}\subseteq\mathcal{U}^{\mathcal{H}} of UEIs, weighted by the corresponding notional amounts h_{j}\in\mathbf{h} , such that \langle\mathcal{H},\mathbf{h}\rangle\in\mathcal{E} . At this point, we are ready to formally state the general RATPO problem. Problem 1 (Risk-aware trading portfolio optimization, RATPO) . Given an initial portfolio \langle\mathcal{P},\mathbf{p}\rangle , the total portfolio that optimizes the objective function f is given by \langle\mathcal{T}^{\star},\mathbf{t}^{\star}\rangle\coloneqq\left\langle\mathcal{P}\uplus\mathcal{H}^{\star},\left[\mathbf{p}^{\top},\mathbf{h}^{{\star}^{\top}}\right]^{\top}\right\rangle , where \langle\mathcal{H}^{\star},\mathbf{h}^{\star}\rangle=\argmin_{\langle\mathcal{H},\mathbf{h}\rangle\in\mathcal{E}}\;f(\mathcal{H},\mathbf{h};\mathcal{P},\mathbf{p})\,. (P1) The optimization variable in ( P1 ), i.e., the EOS \langle\mathcal{H},\mathbf{h}\rangle , can be mapped into an integer vector as further discussed in Section 4 . Thus, Problem ( P1 ) can be viewed as an integer optimization problem with possibly nonconvex objective function and constraint set. We emphasize that nonconvexity can easily originate from the risk measures and portfolio features considered by risk managers and traders in their daily activities. Hence, the difficulty in solving ( P1 ) boils down to the mathematical properties of the objective function in Equation 13 and of the feasible solution set \mathcal{E} . Establishing a general method that guarantees global convergence for the general RATPO problem is not feasible, and each specification of ( P1 ) should be analyzed separately. The next section exposes a general-purpose algorithm based on particle swarm optimization. This method empirically proves to be effective and efficient in solving an instance of the RATPO problem involving the main risk measures and portfolio features used in daily risk management and trading activities (see Section 5 ). 4 Risk-aware trading swarm algorithm Meta-heuristics represent general-purpose approaches for solving optimization problems. Among their features, they do not make restrictive assumptions on the mathematical properties of the objective function and constraints. This approach allows risk managers and traders to specify arbitrarily complex objective functions of the form in Equation 13 arising from the need to satisfy trading, risk management, and regulatory objectives. In addition, this aspect allows specifying complex constraints set, and thus guiding the optimizer’s search toward solutions to problem ( P1 ) having precise financial meaning. In addition, they do not leverage the gradient during the optimization. Therefore, they are amenable to handling optimization variables of different natures. Finally, they efficiently explore the solution space by balancing the exploration-exploitation trade-off (see. Erwin & Engelbrecht, 2023 ). The compromise for this flexibility is the lack of convergence guarantees to a global optimum within a finite time. These algorithms may become trapped in local optima, making it challenging to assess their proximity to the global optimum. Nonetheless, for risk managers and traders—who typically possess deep domain knowledge that can inform the optimization problem through constraints—a consistent reduction in the objective function remains valuable. In our work, we build upon particle swarm optimization (PSO), originally introduced by Kennedy & Eberhart, 1995 . PSO is inspired by the flocking behavior of birds and fishes, and represents one of the most popular meta-heuristics based on the swarm intelligence paradigm by Kennedy, 2006 . In PSO, each particle in the swarm explores positions, i.e., candidate solutions of the optimization problem, in an n -dimensional space. Specifically, denoting by n^{p} the number of particles, the particle is described by the position and velocity vectors, \mathbf{x}_{i} and \mathbf{v}_{i} , i\in[n^{p}] , respectively. The algorithm proceeds by iteratively updating the particles’ position and velocity vectors. We denote by {\mathbf{y}}^{k}_{i} and {\mathbf{z}}^{k} respectively (i) the best position visited by the i -th particle at iteration k , and (ii) the best global position visited by the swarm at iteration k , respectively. Given (i) the inertia weight w\in\mathbb{R}^{+} , (ii) the personal and social coefficients c^{\mathrm{pers}} and c^{\mathrm{soc}} in \mathbb{R}^{+} respectively, and (iii) the vectors \mathbf{r}_{1} and \mathbf{r}_{2} drawn from U(0,1) , the particle update recursion is \begin{cases}\mathbf{v}_{i}^{k+1}&=w\mathbf{v}_{i}^{k}+\underbrace{c^{\mathrm{pers}}\mathbf{r}_{1}^{k+1}\circ({\mathbf{y}}^{k}_{i}-\mathbf{x}_{i}^{k})}_{\text{personal component}}+\underbrace{c^{\mathrm{soc}}\mathbf{r}_{2}^{k+1}\circ({\mathbf{z}}^{k}-\mathbf{x}_{i}^{k})}_{\text{social component}}\,,\\ \mathbf{x}^{k+1}_{i}&=\mathbf{x}^{k}_{i}+\mathbf{v}^{k+1}_{i}\,.\end{cases} (R1) By building on the key concepts of UEI and EOS, we develop a special version of PSO that leverages the parameterization \langle\mathcal{H},\mathbf{h}\rangle and enables parallel computation over the particles to efficiently solve the RATPO problem ( P1 ). Our method, termed risk-aware trading swarm (RATS), is described below. Initialization. As a first step, RATS runs an initialization phase. Consider that the cardinality of \mathcal{U}^{\mathcal{H}} is n , and that the names of the UEIs are sorted in lexicographic order. Since each H_{j}\in\mathcal{U}^{\mathcal{H}} corresponds to a unique combination of the representing parameters’ values, we can simply identify the H_{j} with its index j\in[n] 6 6 6 The same mapping can be applied to the notional amounts to handle the case in which the notional amount domain is undersampled, that is, the range of the corresponding integers is discretized. We use such a mapping in our empirical assessment in Section 5 . . Hence, the particle position can be represented as a 2m -dimensional integer vector \mathbf{x}\coloneqq\left[\underbrace{x_{1},\ldots,x_{m}}_{\text{UEI indices}},\underbrace{x_{m+1},\ldots,x_{2m}}_{\text{notional amounts}}\right]^{\top}\!,\quad\text{with }m\leq n. (14) The particle position in Equation 14 entails an optimization strategy \langle\mathcal{H},\mathbf{h}\rangle . If \langle\mathcal{H},\mathbf{h}\rangle\in\mathcal{E} , meaning the optimization strategy is eligible , the particle position is called feasible . Conversely, if \langle\mathcal{H},\mathbf{h}\rangle\notin\mathcal{E} , the particle position is called unfeasible . Furthermore, the number of distinct UEIs represented in \mathbf{x} , i.e., \absolutevalue{\mathcal{H}} , is at most m . This is because, in principle, the first m entries of \mathbf{x} may include repeated indices. Consequently, RATS enables users to easily set an upper bound of m on the number of financial instruments that can be selected, a helpful feature from an application viewpoint. RATS initializes the entries x_{j} , j\in[m] , by sampling from U\{b_{j},u_{j}\} , where b_{j} and u_{j}\in\mathbb{N} , such that 1\leq b_{j}\tau^{f}\,. (16) In case Equation 16 is not satisfied, RATS increases a counter k^{\mathrm{stall}}\in\mathbb{N} which keeps track of the number of stall iterations. Finally, following Shi & Eberhart, 1998 , we dynamically adjust the inertia weight, according to a linearly decaying rule. Given minimum and maximum values, w^{\min} and w^{\max} , respectively; and setting w^{1}=w^{\max} , the rule reads as w^{k+1}=w^{\max}-\frac{k}{k^{\max}}\left(w^{\max}-w^{\min}\right)\,, (17) where k^{\max} is the maximum number of iterations. Stopping criteria. RATS exits the recursion either (i) if the maximum number of iterations k^{\max} is reached, or (ii) if the global best position is not updated for a specified number of consecutive stall iterations k^{\mathrm{stall}}\geq k^{\mathrm{max\,stall}} , or (iii) if the fraction \chi of particles exhibiting a personal best position equal to the global best one exceeds a concentration threshold \tau^{p}\in(0,1) . Algorithm 1 summarizes the overall procedure. We emphasize that RATS can be easily equipped by the user with different existing variants of PSO. Algorithm 1 Risk-aware trading swarm (RATS) Input: risk factors \mathcal{R} , market data \mathcal{M} , risk scenarios \mathcal{F} , initial portfolio \langle\mathcal{P},\mathbf{p}\rangle , unique eligible instruments \{H_{j}\} with j\in[n] , number of particles n^{p} , minimum/maximum UEI indices/notional amounts \{b_{j},\,u_{j},\ell_{j},\,t_{j}\} with j\in[m] , minimum velocity v^{\min} , maximum velocity v^{\max} , minimum inertia weight w^{\min} , maximum inertia weight w^{\max} , small significance threshold \tau^{f} , concentration threshold \tau^{p} , maximum number of iterations k^{\max} , number of consecutive stall iterations k^{\mathrm{max\,stall}} Output: \mathbf{z} 1 w\leftarrow w^{\max} 2 k^{\mathrm{stall}}\leftarrow 0 3 for j\leftarrow 1 to n do 4 for q\leftarrow 1 to p do 5 \varphi^{H_{j}}_{q}\leftarrow Compute it by using \mathcal{R},\,\mathcal{M},\,\mathcal{F} 6 for i\leftarrow 1 to n^{p} do 7 \mathbf{x}_{i}^{0}\leftarrow Sample the first m entries from U\{b_{j},u_{j}\} , the rest from U\{\ell_{j},t_{j}\} , with j\in[m] 8 \mathbf{v}_{i}^{0}\leftarrow Sample the entries from U\left(v^{\min},\,v^{\max}\right) 9 \mathbf{y}_{i}^{0}\leftarrow\mathbf{x}_{i}^{0} 10 \bar{f}\big|_{\mathbf{x}_{i}^{0}}\leftarrow Apply Equation 15 11 \bar{f}\big|_{\mathbf{y}_{i}^{0}}\leftarrow\bar{f}\big|_{\mathbf{x}_{i}^{0}} 12 {\mathbf{z}}^{0}\leftarrow\argmin_{\mathbf{y}_{i}^{0}}\bar{f}\Big|_{\mathbf{y}_{i}^{0}} 13 \bar{f}\big|_{{\mathbf{z}}^{0}}\leftarrow Apply Equation 15 14 while k