tensortrade-org / tensortrade

An open source reinforcement learning framework for training, evaluating, and deploying robust trading agents.
https://discord.gg/ZZ7BGWh
Apache License 2.0
4.52k stars 1.02k forks source link

Error when trying to Render Matplotlib per example doc #373

Closed MichaelQuaMan closed 2 years ago

MichaelQuaMan commented 2 years ago

At the bottom of:

https://www.tensortrade.org/en/latest/examples/renderers_and_plotly_chart.html?highlight=PlotlyTradingChart#

It states the the final performance and net worth can be displayed using pandas via Matplotlib.

portfolio.performance.plot()
portfolio.performance.net_worth.plot()

However, both lead to:

AttributeError: 'collections.OrderedDict' object has no attribute 'plot'

Guessing, the API changed

What's the correct way to render these charts?

MichaelQuaMan commented 2 years ago

Possible duplicate of TensorTrade Rendering Example Code Fails #325

MichaelQuaMan commented 2 years ago

Looks like portfolio.performance used to be a Pandas Dataframe, which has a built-in plot() method, but at some point it was implemented as an OrderedDict (probably for simplicity and performance).

It should be pretty simple to create a dataframe from and OrderedDict, if I desire to use the Pandas plot() method.

import pandas as pd
df = pd.DataFrame(portfolio.performance)
df.loc["bitfinex:/USD-BTC"].plot()

image

image