class_docstr: Class implementing policy gradient algorithm to train portfolio
  optimization agents.
  
  Note:
      During testing, the agent is optimized through online learning.
      The parameters of the policy is updated repeatedly after a constant
      period of time. To disable it, set learning rate to 0.
  
  Attributes:
      train_env: Environment used to train the agent
      train_policy: Policy used in training.
      test_env: Environment used to test the agent.
      test_policy: Policy after test online learning.
class_docstr_tok: ["Class","implementing","policy","gradient","algorithm","to","train","portfolio","optimization","agents",".","Note",":","During","testing",",","the","agent","is","optimized","through","online","learning",".","The","parameters","of","the","policy","is","updated","repeatedly","after","a","constant","period","of","time",".","To","disable","it",",","set","learning","rate","to","0",".","Attributes",":","train_env",":","Environment","used","to","train","the","agent","train_policy",":","Policy","used","in","training",".","test_env",":","Environment","used","to","test","the","agent",".","test_policy",":","Policy","after","test","online","learning","."]
docstr: Initializes Policy Gradient for portfolio optimization.
  
  Args:
    env: Training Environment.
    policy: Policy architecture to be used.
    policy_kwargs: Arguments to be used in the policy network.
    validation_env: Validation environment.
    batch_size: Batch size to train neural network.
    lr: policy Neural network learning rate.
    optimizer: Optimizer of neural network.
    device: Device where neural network is run.
docstr_tok: ["Initializes","Policy","Gradient","for","portfolio","optimization",".","Args",":","env",":","Training","Environment",".","policy",":","Policy","architecture","to","be","used",".","policy_kwargs",":","Arguments","to","be","used","in","the","policy","network",".","validation_env",":","Validation","environment",".","batch_size",":","Batch","size","to","train","neural","network",".","lr",":","policy","Neural","network","learning","rate",".","optimizer",":","Optimizer","of","neural","network",".","device",":","Device","where","neural","network","is","run","."]
code: def __init__(
      self,
      env,
      policy=EIIE,
      policy_kwargs=None,
      validation_env=None,
      batch_size=100,
      lr=1e-3,
      optimizer=AdamW,
      device="cpu",
  ):
      """Initializes Policy Gradient for portfolio optimization.
  
      Args:
        env: Training Environment.
        policy: Policy architecture to be used.
        policy_kwargs: Arguments to be used in the policy network.
        validation_env: Validation environment.
        batch_size: Batch size to train neural network.
        lr: policy Neural network learning rate.
        optimizer: Optimizer of neural network.
        device: Device where neural network is run.
      """
      self.policy = policy
      self.policy_kwargs = (
          {} if policy_kwargs is None else policy_kwargs
      )
      self.validation_env = validation_env
      self.batch_size = batch_size
      self.lr = lr
      self.optimizer = optimizer
      self.device = device
      self._setup_train(
          env, self.policy, self.batch_size, self.lr, self.optimizer
      )
  
file_path: FinRL/finrl/agents/portfolio_optimization/algorithms.py
imports: from __future__ import annotations
  import copy
  import numpy
  import torch
  from torch.optim import AdamW
  from torch.utils.data import DataLoader
  from tqdm import tqdm
  from .architectures import EIIE
  from .utils import PVM
  from .utils import ReplayBuffer
  from .utils import RLDataset
label_desc: Use image node_id 1 to create a new PolicyGradient object  with example: obj = PolicyGradient(env, policy, policy_kwargs, validation_env, batch_size, lr, optimizer, device)