scrtlabs / catalyst

An Algorithmic Trading Library for Crypto-Assets in Python
http://enigma.co
Apache License 2.0
2.49k stars 725 forks source link

RuntimeWarning: invalid value encountered in greater #532

Closed Industrial closed 5 years ago

Industrial commented 5 years ago

Dear Catalyst Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

Now that you know a little about me, let me tell you about the issue I am having:

Description of Issue

Following the Beginner Tutorial but filling in binance instead of bitfinex and usdt instead of usd, I get this error: RuntimeWarning: invalid value encountered in greater.

Here is how you can reproduce this issue on your machine:

Reproduction Steps

  1. $ catalyst ingest-exchange -x binance -i btc_usdt
  2. $ catalyst run -f ./first_algorithm.py -x binance --start 2018-1-24 --end 2019-1-24 -c usdt --capital-base 100000 -o first_algorithm_out.pickle
Running in backtesting mode.
[2019-01-24 15:43:26.976977] INFO: run_algo: Catalyst version 0.5.21
[2019-01-24 15:43:26.977089] WARNING: run_algo: Catalyst is currently in ALPHA. It is going through rapid development and it is subject to errors. Please use carefully. We encourage you to report any issue on GitHub: https://github.com/enigmampc/catalyst/issues
[2019-01-24 15:43:29.980398] INFO: run_algo: running algo in backtest mode
[2019-01-24 15:43:30.295787] INFO: exchange_algorithm: initialized trading algorithm in backtest mode
[2019-01-24 15:43:31.174019] INFO: Performance: Simulated 366 trading days out of 366.
[2019-01-24 15:43:31.174137] INFO: Performance: first open: 2018-01-24 00:00:00+00:00
[2019-01-24 15:43:31.174233] INFO: Performance: last close: 2019-01-24 23:59:00+00:00
Traceback (most recent call last):
  File "/home/tom/anaconda3/envs/catalyst/bin/catalyst", line 11, in <module>
    sys.exit(main())
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/__main__.py", line 107, in _
    return f(*args, **kwargs)
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/__main__.py", line 294, in run
    stats_output=None,
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/utils/run_algo.py", line 361, in _run
    overwrite_sim_params=False,
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/exchange/exchange_algorithm.py", line 403, in run
    data, overwrite_sim_params
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/exchange/exchange_algorithm.py", line 360, in run
    data, overwrite_sim_params
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/algorithm.py", line 725, in run
    for perf in self.get_generator():
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/gens/tradesimulation.py", line 247, in transform
    risk_message = algo.perf_tracker.handle_simulation_end()
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/finance/performance/tracker.py", line 470, in handle_simulation_end
    treasury_curves=self.treasury_curves,
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/finance/risk/report.py", line 98, in __init__
    1, start_session, end_session
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/finance/risk/report.py", line 157, in periods_in_range
    algorithm_leverages=self.algorithm_leverages,
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/finance/risk/period.py", line 81, in __init__
    self.calculate_metrics()
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/catalyst/finance/risk/period.py", line 138, in calculate_metrics
    self.algorithm_returns.values
  File "/home/tom/anaconda3/envs/catalyst/lib/python3.6/site-packages/empyrical/stats.py", line 661, in downside_risk
    mask = downside_diff > 0
RuntimeWarning: invalid value encountered in greater

What steps have you taken to resolve this already?

I don't know where to look / go from here.

Sincerely,

Tom

Industrial commented 5 years ago

Never mind, it appears that error is thrown if you misconfigure the start/end dates.

Might still be a worthy issue then :-)