History Object#

The history object is similar to a DataFrame, but it was made to be faster. It stores many training information at each timestep of the training. You can use it this way :

  • history['column name', t] returns a scalar value of the metrics ‘column name’ at time step t.

  • history['column name'] returns a numpy array with all the values from timestep 0 to current timestep.

  • history[t] returns a dictionary with of the metrics as keys with the associated values.

It was made to make everything easier :

  • You can access training info like : step, date, reward, position `…

  • It gathers info from your initial DataFrame and labels them with data_{column_name} like : data_close , data_open , data_high ….

  • It stores the portfolio valuation and distribution

>>> history[33091]
 {
  # Training info
  'step': 33091, #Step = t.
  'date': numpy.datetime64('2022-03-01T00:00:00.000000000'), #Date at step t, datetime.
  'position_index': 2, #Index of the position at step t among your position list.
  'position': 1, # Last position taken by the agent.
  'real_position': 1.09848, # Real portfolio position  = (asset owned - asset borrowed - asset interests) * current price / portfolio valuation
  'reward': 0.0028838985262525257, #Reward at step t. Obviously, you can not be used inside a custom reward function (the value is always 0 as it as not been computed yet).

  # DataFrame info : Every column (except features) of your initial DataFrame preceded by 'data_'
  'data_symbol': 'BTC/USD',
  'data_volume': 52.05632,
  'data_Volume USD': 2254677.3870464,
  'data_high': 43626.49,
  'data_open': 43221.71,
  'data_close': 43312.27,
  'data_unix': 1646092800,
  'data_low': 43185.48,

  # Portfolio info : Distribution of the portfolio
  'portfolio_valuation': 45.3857471834205, #Global valuation of the portfolio
  'portfolio_distribution_asset': 0.001047869568779473, #the amount of owned BTC
  'portfolio_distribution_fiat': 0.0001374956603967803, #the amount of owned USD
  'portfolio_distribution_borrowed_asset': 0, #the amount of borrowed BTC (when position < 0 = SHORT)
  'portfolio_distribution_borrowed_fiat': 0, #the amount of borrowed USD (when position > 1)
  'portfolio_distribution_interest_asset': 0.0, #the cumalated interest generated by the borrowed BTC
  'portfolio_distribution_interest_fiat': 0.0, #the cumalated interest generated by the borrowed USD
 }