Can a bot learn efficiently in a noisy and self adapting environment with sequential, non-stationary and nonhomogeneous observations? By noisy and non homogeneous, we mean that data have different statistical properties across time. By sequential observations, we mean that chronological order matters and that observations are completely modified if we change their order. To answer this question, we use trading bots that offer a perfect example of noisy data, strongly sequential observations subject to change of regime. We aim at creating an augmented asset manager bot for the asset management industry.
Asset management is a well-suited industry to apply robotic machine learning: large amount of data available due to electronic tradings and strategic interest in bots as they do not give any hold on emotional and or behavioral bias largely described in Kahneman (2011) that can cause the asset manager ruin. However, machine learning is hardly used to make investment decision. Because of the complexity of the learning environment, asset managers are still largely relying on traditional methods, based on human decisions. This is in sharp contrast with recent advances of deep reinforcement learning (DRL) on challenging tasks like game Copyright c 2021, Association for the Advancement of Artificial Intelligence (www.aaai.org). All rights reserved.
(Atari games from raw pixel inputs Mnih et al. (2013 Mnih et al. ( , 2015 , Go Silver et al. (2016) , StarCraft II Vinyals et al. (2019) ), but also more robotic learning like advanced locomotion and manipulation skills from raw sensory inputs (Levine et al. (2015 (Levine et al. ( , 2016 Schulman et al. (2015a Schulman et al. ( ,b, 2017 , Lillicrap et al. (2015) ), autonomous driving (Wang, Jia, and Weng (2018) ) and general bot learning (Gu et al. (2017) ).
We investigate if deep reinforcement learning can help creating an augmented asset manager when solving a classical portfolio allocation problem: finding hedging strategies to an existing portfolio, the MSCI World index in our example. The hedging strategies are different strategies operated by standard bots that have different logics and perform well in different market conditions. Knowing when to add and remove them and when to decrease or increase their asset under management is a fundamental but challenging question for an augmented asset manager.
At first, reinforcement learning was not used in portfolio allocation. Initial works focused on trying to use deep networks to forecast next period prices, as presented in Freitas, De Souza, and Almeida (2009) , Niaki and Hoseinzade (2013) , Heaton, Polson, and Witte (2017) . These models solved a supervised learning task akin to a regression, and tried to predict prices using past information only and compute portfolio allocations based on forecast. For asset managers, this initial usage of machine learning contains multiple problems. First, it does not ensure that the prediction is reliable in the near future: financial markets are well known to be non stationary and to present regime changes as illustrated in Salhi et al. (2015) , Dias, Vermunt, and Ramos (2015) , Zheng, Li, and Xu (2019) . Second, this approach does not address the question of finding the optimal portfolio based on some reward metrics. Third, it does not adapt to changing environment and does not easily incorporate transaction costs.
A second stream of research around deep reinforcement learning has emerged to address those points: Jiang and Liang (2016) Xiong et al. (2019) . The dynamic nature of reinforcement learning makes it an obvious candidate for changing environment Jiang and Liang (2016) ; Zhengyao et al. (2017); Liang et al. (2018) , Benhamou et al. (2020a) , Benhamou et al. (2020b) . Transaction costs can be easily included in rules Liang et al. (2018) ; Yu et al. (2019) ; Wang and Zhou (2019) ; Liu et al. (2020) ; Ye et al. (2020) ; Yu et al. (2019) . However, these works, except Ye et al. (2020) rely on time series of open high low close prices, which are known to be very noisy. Secondly, they all assume an immediate action after observing prices which is quite different from reality as asset managers need a one day turnaround to manage new portfolio positions. Thirdly, they mostly rely on a single reward function and do not measure the impact of the reward function. Last but not least, they only do one train and test period, and never test for model stability.
More generally, DRL has recently been applied to other problems than portfolio allocation and direct trading strategies Zhang, Zohren, and Roberts (2019) , Huang (2018) , Thate and Ernst (2020) , Nan, Perumal, and Zaiane (2020) , Wu et al. (2020) or to the case of multi agents Bao and yang Liu (2019) or to optimal execution Ning, Lin, and Jaimungal (2018).
Our contributions are threefold:
• The addition of contextual information. Using just past information is not sufficient for bot learning in a noisy and fast changing environment. The addition of contextual information improves results significantly. Technically, we create two sub-networks: one fed with direct observations (past prices and standard deviation) and another one with contextual information (level of risk aversion in financial markets, early warning indicators for future recession, corporate earnings...).
• One day lag between price observation and action. We assume that prices are observed at time t but action only occurs at time t + 1, to be consistent with reality. This one day lag makes the RL problem more realistic but also more challenging.
• The walk-forward procedure. Because of the non stationarity nature of time dependent data and especially financial data, it is crucial to test DRL models stability. We present a new methodology in DRL model evaluation referred to as walk forward analysis that iteratively trains and tests the model on extending data-set. This can be seen as the analogy of cross validation for time series. This allows to validate that selected hyper parameters work well over time and that resulting models are stable over time.
In standard bot reinforcement learning, models are based on Markov Decision Process (MDP) as in Sutton and Barto (2018) . MDP assumes that the bot knows all the states of the environment and has all the information to make the optimal decision in every state. The Markov property in addition implies that knowing the current state is sufficient.
Yet, the traditional MDP framework is inappropriate here: noise may arise in financial market data due to unpredictable external events. We prefer to use Partially Observable Markov Decision Process (POMDP) as presented initially in Astrom (1969) . In POMDP, only a subset of the information of a given state is available. The partiallyinformed agent cannot behave optimally. He uses a window of past observations to replace states as in a traditional MDP.
Mathematically, POMDP is a generalization of MDP. Recall that MDP assumes a 4-tuple (S, A, P, R) where S is the set of states, A is the set of actions, P is the state action to next state transition probability function P : S ×A×S → [0, 1], and R is the immediate reward. The goal of the agent is to learn a policy that maps states to the optimal action µ : S → A and that maximizes the expected discounted reward E[ At each time, the agent is asked to take an action a t ∈ A in a particular environment state s t ∈ S, that is followed by the next state s t+1 with transition probability P(s t+1 |s t , a t ). The next state s t+1 is not observed by the agent. It rather receives an observation o t+1 ∈ O on the state s t+1 with probability Z(o t+1 |s t+1 , a t ).
From a practical standpoint, the general RL setting is modified by taking a pseudo state formed with a set of past observations (o t−n , o t−n−1 , . . . , o t−1 , o t ). In practice to avoid large dimension and the curse of dimension, it is useful to reduce this set and take only a subset of these past observations with j < n past observations, such that 0 < i 1 < . . . < i j and i k,1≤k≤j ∈ N is an integer. The set δ 1 = (0, i 1 , . . . , i j ) is called the observation lags. In our experiment we typically use lag periods like (0, 1, 2, 3, 4, 20, 60) for daily data, where the tuple (0, 1, 2, 3, 4) is indeed the last week observation, 20 is for the one-month ago observation (as there is approximately 20 business days in a month) and 60 the three-month ago observation.
Regular observations There are two types of observations: regular and contextual information. Regular observations are data directly linked to the problem to solve. For a standard bot, these are observations from its environment like position of the arm, degree, etc. In the case of a trading bot, regular observations are past prices observed over a lag period δ = (0 < i 1 < . . . < i j ). To re-normalize data, we rather use past returns computed as
where p k t is the price at time t of the asset k. For a financial asset k, to give information about regime changes, our trading bot receives also empirical standard deviation computed over a sliding estimation window denoted by d as follows
Hence our regular observations is a three dimensional tensor represented as follows:
This setting with two layers (past returns and past volatilities) is quite different from the one presented in Jiang and Liang (2016) ; Zhengyao et al. (2017) ; Liang et al. (2018) that uses different layers representing open, high, low and close prices. There are various remarks to be made. First, high low information does not make sense for portfolio strategies that are only evaluated daily, which is the case of all the funds. Secondly, open high low prices tend to be highly correlated creating some noise in the inputs. Third, the concept of volatility is crucial to detect regime change and is surprisingly absent from these works as well as from other works like Yu et al. Context observation Contextual observations are additional information that provides intuition about current context. For our asset manager bot, they are other financial data not directly linked to its portfolio assumed to have some predictive power for portfolio assets. In the case of a financial portfolio, context information is typically modelled by a large range of features :
• the level of risk aversion in financial markets, or market sentiment, measured as an indicator varying between 0 for maximum risk aversion and 1 for maximum risk appetite, • the bond/equity historical correlation, a classical expost measure of the diversification benefits of a duration hedge, measured on a 1-month, 3-month and 1-year rolling window, • The credit spreads of global corporate -investment grade, high yield, in Europe and in the US -known to be an early indicator of potential economic tensions, • The equity implied volatility, a measure if the 'fear factor' in financial market, • The spread between the yield of Italian government bonds and the German government bond, a measure of potential tensions in the European Union, • The US Treasury slope, a classical early indicator for US recession, • And some more financial variables, often used as a gauge for global trade and activity: the dollar, the level of rates in the US, the estimated earnings per shares (EPS).
On top of these observations, we also include the maximum and minimum portfolio strategies return and the maximum portfolio strategies volatility. The latter information is like for regular observations motivated by the stylized fact that standard deviations are useful features to detect crisis.
Contextual observations are stored in a 2D matrix denoted by C t with stacked past p individual contextual observations.
The matrix nature of contextual states C t implies in particular that we will use 1D convolutions should we use convolutional layers. All in all, observations that are augmented observations, write
that will feed the two sub-networks of our global network as presented in figure 1. 
In our deep reinforcement learning the augmented asset manager trading bot needs to decide at each period in which hedging strategy it invests. The augmented asset manager can invest in l strategies that can be simple strategies or strategies that are also done by asset management bots. To cope with reality, the bot will only be able to act after one period. This is because asset managers have a one day turn around to change their positions. We will see on experiments that this one day turnaround lag makes a big difference in results. As it has access to l potential hedging strategies, the output is a l dimension vector that provides how much it invests in each hedging strategy. For our deep network, this means that the last layer is a softmax layer to ensure that portfolio weights are between 0 and 100% and sum to 1.
There are multiple choices for our reward. A straightforward reward function is to compute the final net performance of the combination of our portfolio computed as the value of our portfolio at the last train date t T over the initial value of the portfolio t 0 minus one: P t T /P t0 − 1. Another natural reward function is to compute the Sortino ratio, that is a variation of Sharpe ratio where risk is computed by the downside standard deviation (instead of regular standard deviation) whose definition is to compute the standard deviation only on negative daily returns denoted by (r t ) t=0..T . Hence the downside standard deviation is computed by
A policy is a mapping from the observation space to the action space, π : O → A. To achieve this, a policy is specified by a deep network with a set of parameters θ. The action is a vector function of the observation given the parameters: a t = π θ (o t ). The performance metric of π θ for time interval [0, t] is defined as the corresponding total reward function of the interval J [0,t] (π θ ) = R o 1 , π θ (o 1 ), · · · , o t , π θ (o t ), o t+1 . After random initialization, the parameters are continuously updated along the gradient direction with a learning rate λ: θ −→ θ + λ∇ θ J [0,t] (π θ ). The gradient ascent optimization is done with standard Adam (short term for Adaptive Moment Estimation) optimizer to have the benefit of adaptive gradient descent with root mean square propagation Kingma and Ba (2014) . The whole process is summarized in algorithm 1, called adversarial policy gradient as we introduce randomisation both in the observations and the action (to have standard exploration exploitation). This two steps randomization ensures more robust training as we will see in the experiments. Noise in observations has already been suggested to improve training in Liang et al. (2018) . for however many updates in D do 
In machine learning, the standard approach is to do k-fold cross validation as shown in figure 2. White rectangles represent training periods while grey rectangles testing periods. This approach breaks the chronology of data and potentially uses past data in the test set. Rather, we can take sliding test set and take past data as training data. We can either take the training data set with a fixed starting point and grow the training data set by adding more and more data, which is what we call extending walk forward as shown in figure 3 or take always the same amount of data and slide the training data (figure 4), hence the name of sliding walk forward. Extending walk forward tends to more stable models as we add incrementally new data, at each new training step, and share all past data. The negative effect of this is to adapt slowly to new information. On the opposite, sliding walk forward leads to more rapidly changing models as we progressively drop old data and hence give more weight to more recent data. To our experience, because we do not have so much data to train our DRL model, it is better to use extending walk forward. Last but not least, as the test set is always after the train set, walk forward analysis gives less steps compared to cross validation. In practice for our data set, we train our models from 2000 to end of 2006 (to have at least seven years of data) and use an extending test period of one year. Test Test Test Test Test
Step 1:
Step 2:
Step 3:
Step 4:
Step 5: Step 1:
Step 2:
Step 3:
Step 4: Test   Test   Test   Test Step 1:
Step 2:
Step 3:
Step 4:
We are interested in finding a hedging strategy for a risky asset. The experiment is using daily data from 01/05/2000 to 19/06/2020. The risky asset is the MSCI world index (see https://www.msci.com/ -data source: SG CIB). We choose the MSCI world index because it is a good proxy for a wide range of asset manager portfolios. The hedging strategies are 4 SG CIB proprietary systematic strategies (see https://sgi.sgmarkets.com/ -data source: SG CIB), computed and executed by trading bots and further described below. As we use extending walk forward traning, train set 
Systematic strategies are asset management bots that invest in financial markets according to adaptive and pre-defined trading rules. Here, we use 4 SG CIB proprietary 'hedging strategies', that tend to perform when stock markets are down:
• Directional hedges -react to small negative return in equities,
• Gap risk hedges -perform well in sudden market crashes,
• Proxy hedges -tend to perform in some market configurations, like for example when highly indebted stocks under-perform other stocks,
• Duration hedges -invest in bond market, a classical diversifier to equity risk in finance.
The underlying financial instruments vary from put options, listed futures, single stocks, to government bonds. Some of those strategies are akin to an insurance contract and bear a negative cost over the long run. The challenge consists in balancing cost versus benefits. In practice, asset managers have to decide how much of these hedging strategies are needed on top of an existing portfolio to achieve a better risk reward. The decision making process is often based on contextual information, such as the economic and geopolitical environment, the level of risk aversion among investors and other correlation regimes. A cross validation step selects the most relevant features contextual information. In the present case, the first three features are selected. The rebalancing of strategies in the portfolio comes with transaction costs, that can be quite high since hedges use options. Transactions costs are like frictions in physical systems. They are taken into account dynamically to penalise solutions with a high turnover rate.
Asset managers use a wide range of metrics to gauge the success of their investment decision. For a thorough review of those metrics, see for example Cogneau and Hbner (2009) . To keep things simple, we use the following metrics:
• annualized return defined as the average annualized compounded return,
• annualized daily based Sharpe ratio defined as the ratio of the annualized return over the annualized daily based volatility µ/σ,
• Sortino ratio computed as the ratio of the annualized return overt the downside standard deviation,
• maximum drawdown denoted by max DD in table 4.
Let P T be the final value of the portfolio at time T and P 0 its initial value at time t = 0. Let τ be the year fraction of the final time T . The annualized return is defined as µ = (P T /P 0 ) 1/τ − 1. The maximum drawdown is computed as the maximum of all daily drawdowns. The daily drawdown is computed as the ratio of the difference between the running maximum of the portfolio value (RM T = max t=0..T (P t ) ) and the portfolio value over the running maximum of the portfolio value. Hence DD T = (RM T − P T )/RM T and M DD T = max t=0..T (DD t ).
Pure risky asset This first evaluation is to compare our portfolio composed only of the risky asset (in our case, the MSCI world index) with the one augmented by the trading bot and composed of the risky asset and the hedging overlay. If our bot is successful in identifying good hedging strategies, it should improve the overall portfolio and have a better performance than the risky asset.
Markowitz theory The standard approach for portfolio allocation in finance is the Markowitz model (Markowitz (1952) ). It computes the portfolio with minimum variance given an expected return which is taken in our experiment to be the average return of the hedging strategies over the last year. The intuition in Markowitz (or mean-variance portfolio) theory is that an investor wants to have the lowest risk for a given return. In practice, we solve a quadratic program that finds the minimum portfolio variance under the constraint that the expected return is greater or equal to the minimum return. In our baseline, Markowitz portfolio is recomputed every 6 months to have something dynamic to cope with regime changes.
Follow the winner This is a simple strategy that consists in selecting the hedging strategy that was the best performer in the past year. If there is some persistence over time of the hedging strategies' performance, this simple methodology should work well. It replicates standard investors behavior that tend to select strategies that performed well in the past.
Follow the loser Follow the loser is the opposite of follow the winner. It assumes that there is some mean reversion in strategies' performance, meaning that strategies tend to perform equally well on long term and mean revert around their trend. Hence if a strategy did not perform well in the past, and if there is mean reversion, there is a lot of chance that this strategy will recover with its pairs.
We compare the performance of the following 5 models: DRL model based on convolutional networks with contextual states (Sentiment indicator, 6 month correlation between equity and bonds and credit main index), same DRL model without contextual states, follow the winner, follow the loser and Markowitz portfolio. The resulting graphics are displayed in figure 5 with the risky asset position alone in blue and the models in orange. Out of these 5 models, only DRL and Follow the winner are able to provide significant net performance increase thanks to an efficient hedging strategy over the 2007 to 2020 period. The DRL model is in addition able to better adapt to the Covid crisis and to have better efficiency in net return but also Sharpe and Sortino ratios over 3 and 5 years as shown in table 4. In terms of the smallest maximum drawdown, the follow the loser model is able to significantly reduce maximum drawdown but at the price of a lower return, Sharpe and Sortino ratios. Removing contextual information deteriorates model performances significantly and is illustrated by the difference in term of return, Sharpe, Sortino ratio and maximum drawdown between the DRL and the DRL no context model. Last but not least, Markowitz model is not able to adapt to the new regime change of 2015 onwards despite its good performance from 2007 to 2015. It is the worst performer over the last 3 and 5 years because of this lack of adaptation. For all models, we use the walk forward analysis as described in the corresponding section. Hence, we start training the models from 2000 to end of 2006 and use the best model on the test set in 2007. We then train the model from 2000 to end of 2007 and use the best model on the test set in 2008. In total, we do 14 training (from 2007 to 2020). This process ensures that we detect models that are unstable over time and is similar in spirit to delayed online training.
In table 1, we provide a list of 32 models based on the following choices: network architecture (LSTM or CNN), adversarial training with noise in data or not, use of contextual states, and reward function (net profit and Sortino), use of day lag between observations and actions. We see that the best DRL model with the day-lag turnover constraint is the one using convolutional networks, adversarial training, contextual states and net profit reward function. These 4 parameters are meaningful for our DRL model and change model performance substantially as illustrated by the table. We also compare the same model with and without contextual state and see in table 3 that the use of contextual state improves model performance substantially. This is quite intuitive as we provide more meaningful data to the model.
Reminding the fact that asset managers cannot immediately change their position at the close of the financial markets, modeling the one day lag turnover to account is also significant as shown in table 2. It is not surprising that a delayed action after observation makes the learning process more challenging for the DRL agent as influence of variables tends to decrease with time. Surprisingly, this salient modeling characteristic is ignored in existing literature Zhengyao et al. (2017) 
In this paper, we address the challenging task of learning in a noisy and self adapting environment with sequential, nonstationary and non-homogeneous observations for a bot and more specifically for a trading bot. Our approach is based on deep reinforcement learning using contextual information thanks to a second sub-network. We also show that the additional constraint of a delayed action following observations has a substantial impact that should not be overlooked. We introduce the novel concept of walk forward to test the robustness of the deep RL model. This is very important for regime changing environment that cannot be evaluated with a simple train validation test procedure, neither a k-fold cross validation that ignores the strong chronological feature of observations.
For our trading bots, we take not only past performances of portfolio strategies over different rolling period, but also standard deviation to provide predictive variables for regime changes. Augmented states with contextual information make a big difference in the model and help the bot learning more efficiently in a noisy environment. On experiment, contextual based approach over-performs baseline methods like Markowitz or naive follow the winner and follow the loser. Last but not least, it is quite important to fine tune the numerous hyper-parameters of the contextual based DRL model, namely the various lags (lags period for the sub network fed by portfolio strategies past returns, lags period for common contextual features referred to as the common features in the paper), standard deviation period, learning rate, etc...
Despite the efficiency of contextual based DRL models, there is room for improvement. Other information like news could be incorporated to continue increasing model performance. For large stocks, like tech stocks, sentiment information based on social media activity could also be relevant.