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.5k stars 1.02k forks source link

TypeError: float() argument must be a string or a number, not 'Timestamp' #312

Open Youbadawy opened 3 years ago

Youbadawy commented 3 years ago

Please make sure that this is a Bug or a Feature Request and provide all applicable information asked by the template. If your issue is an implementation question, please ask your question on StackOverflow or on the TensorTrade Discord #help-desk channel instead of opening a GitHub issue.

System information

You can obtain the TensorFlow version with:
python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"

Describe the current behavior After initializing all Datastreams, portfolios, and render feeds, and inputting it inside a DQN agent to train,

it receives an error of Timestamp is not float, although we I used the below format to input my data streams as indicated in notebook examples,

for i, count in enumerate(data):
  pair = count.replace("/USD","")
  with NameSpace("bitfinex"):
    if i==0:
      bitfinex_streams = [
          Stream.source(list(data.get(count)[c]), dtype="float").rename(f"{pair}:{c}") for c in data.get(count).columns
      ]
    else:
      bitfinex_streams += [
          Stream.source(list(data.get(count)[c]), dtype="float").rename(f"{pair}:{c}") for c in data.get(count).columns
      ]

feed = DataFeed(bitfinex_streams)

image

Describe the expected behavior

It should be able to train as the notebook setup_environment_tutorial.ipynb displays a similar format,

image

Code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate the problem.

cdd = CryptoDataDownload()
data = {}

data["BTC/USD"] = cdd.fetch("Bitfinex", "USD", "BTC", "1h")
data["ETH/USD"] = cdd.fetch("Bitfinex", "USD", "ETH", "1h")
data["LTC/USD"] = cdd.fetch("Bitfinex", "USD", "LTC", "1h")

data

for i, count in enumerate(data):
  pair = count.replace("/USD","")
  with NameSpace("bitfinex"):
    if i==0:
      bitfinex_streams = [
          Stream.source(list(data.get(count)[c]), dtype="float").rename(f"{pair}:{c}") for c in data.get(count).columns
      ]
    else:
      bitfinex_streams += [
          Stream.source(list(data.get(count)[c]), dtype="float").rename(f"{pair}:{c}") for c in data.get(count).columns
      ]

feed = DataFeed(bitfinex_streams)

bitfinex_options = ExchangeOptions(commission=0.0075, min_trade_price=10.0)
bitfinex = Exchange("bitfinex", service=execute_order,  options=bitfinex_options)(
    Stream.source(list(data.get("BTC/USD")["close"]), dtype="float").rename("USD-BTC"),
    Stream.source(list(data.get("ETH/USD")["close"]), dtype="float").rename("USD-ETH"),
    Stream.source(list(data.get("LTC/USD")["close"]), dtype="float").rename("USD-LTC")
)

portfolio = Portfolio(USD, [
    Wallet(bitfinex, 100000 * USD),
    Wallet(bitfinex, 0 * BTC),
    Wallet(bitfinex, 0 * ETH),
    Wallet(bitfinex, 0 * LTC)
])

env = default.create(
    portfolio=portfolio,
    action_scheme='managed-risk',  # ['managed-risk', 'simple', BSH ]
    reward_scheme='risk-adjusted', # [ 'risk-adjusted', 'simple' ]
    feed=feed,
    renderer_feed=renderer_feed,
    renderer=default.renderers.PlotlyTradingChart(),
    window_size=5
)

agent = DQNAgent(env)

agent.train(n_steps=200, n_episodes=5, save_path="agents/", render_interval=None)

Other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

image

daecepi commented 3 years ago

@Youbadawy i am having the same error, did you resolve it?

Youbadawy commented 3 years ago

@daecepi yes, use unix timestamp instead, it should work!

abstractguy commented 2 years ago

Please start from the latest examples. This is fixed there. I may merge the fix to data/cdd.py later.