Skip to main content

Optimize Portfolio Allocation using FinRL

Make dynamic decisions: where to trade, what price, what quantity...
Created on July 2|Last edited on July 6

Problem:

Goal: Model the stock trading process as a Markov Decision Process (MDP).
Trading goal is formulated as a maximization problem.
Solution: Reinforcement Learning Trading Strategy
Strategy used: Actor-critic based algorithm: Advantage Actor Critic (A2C).
It robustly adjusts to different market conditions.

Components of RL Environment:
  • Action: portfolio weight of each stock [0,1]
  • State: metrics: {MACD, RSI, CCI, ADX}
  • Reward function: cumulative portfolio value.
  • Environment: portfolio allocation for Dow 30 constituents (Technical Indicators, Stock Price, Balance, Shares)

Assumption: No transaction cost is taken into account

  1. Data Source: FinRL uses a YahooDownloader class to extract data.
    
    Run set
    1
    
  2. Preprocessing: FinRL FeatureEngineer class to preprocess data.
    • Perform Feature Engineering: covariance matrix + technical indicators
    • Covariance matrix is a good feature because portfolio managers use it to quantify the risk (standard deviation) associated with a particular portfolio.
  3. Model Training:
    1. We use A2C for portfolio allocation, because it is stable, cost-effective, faster and works better with large batch sizes.
    2. Trading: Assume that we have $1,000,000 initial capital at 2019/01/01. We use the A2C model to perform portfolio allocation of the Dow 30 stocks.
    3. 
      Run set
      23
      
  4. Backtesting Performance: FinRL uses a set of functions to do the backtesting with Quantopian pyfolio.
Stats for Index (DJIA) performance.



Cumulative Returns & Rewards


Run set
2



Performance Evaluation

The performance of the trading agent is evaluated using Sharpe ratio and compared with AAPL ticker

Run set
23



References