Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

portfolio_optimization.py:63: RuntimeWarning: invalid value encountered in true_divide #563

Open
sandybradley opened this issue Nov 5, 2019 · 0 comments

Comments

@sandybradley
Copy link

Dear Catalyst Maintainers,

Environment

  • Operating System: Windows 10
  • Python Version: Python 3.6.0
  • How did you install Catalyst: virtualenv, as described in your install section
  • Python packages:
    aiodns==1.1.1
    aiohttp==3.6.2
    alembic==0.9.7
    async-timeout==3.0.1
    attrdict==2.0.1
    attrs==19.3.0
    bcolz==1.2.1
    boto3==1.5.27
    botocore==1.8.50
    Bottleneck==1.2.1
    cchardet==2.1.1
    ccxt==1.17.94
    certifi==2018.1.18
    cffi==1.13.2
    chardet==3.0.4
    click==6.7
    contextlib2==0.5.5
    cycler==0.10.0
    cyordereddict==1.0.0
    Cython==0.27.3
    cytoolz==0.10.1
    decorator==4.3.0
    docutils==0.15.2
    empyrical==0.2.1
    enigma-catalyst==0.5.21
    eth-abi==1.3.0
    eth-account==0.2.3
    eth-hash==0.2.0
    eth-keyfile==0.5.1
    eth-keys==0.2.4
    eth-rlp==0.1.2
    eth-typing==2.2.0
    eth-utils==1.8.0
    hexbytes==0.2.0
    idna==2.7
    idna-ssl==1.1.0
    intervaltree==2.1.0
    jmespath==0.9.4
    kiwisolver==1.1.0
    Logbook==0.12.5
    lru-dict==1.1.6
    lxml==4.4.1
    Mako==1.0.7
    MarkupSafe==1.0
    matplotlib==3.1.1
    multidict==4.5.2
    multipledispatch==0.4.9
    networkx==2.1
    numexpr==2.6.4
    numpy==1.16.0
    pandas==0.19.2
    pandas-datareader==0.6.0
    parsimonious==0.8.1
    patsy==0.5.0
    pycares==3.0.0
    pycparser==2.19
    pycryptodome==3.9.1
    pyparsing==2.4.3
    pypiwin32==223
    python-dateutil==2.7.3
    python-editor==1.0.4
    pytz==2016.4
    pywin32==225
    redo==2.0.1
    requests==2.20.1
    requests-file==1.4.3
    requests-ftp==0.3.1
    requests-toolbelt==0.8.0
    rlp==1.1.0
    s3transfer==0.1.13
    scipy==1.0.0
    six==1.11.0
    sortedcontainers==1.5.9
    SQLAlchemy==1.2.2
    statsmodels==0.8.0
    tables==3.4.2
    toolz==0.9.0
    typing-extensions==3.7.4.1
    urllib3==1.24.3
    web3==4.4.1
    websockets==5.0.1
    wrapt==1.11.2
    yarl==1.1.0

Description of Issue

python portfolio_optimization.py
[2019-11-05 08:37:47.292909] INFO: run_algo: Catalyst version 0.5.21
[2019-11-05 08:37:47.292909] 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-11-05 08:37:50.295283] INFO: run_algo: running algo in backtest mode
[2019-11-05 08:37:50.674810] INFO: exchange_algorithm: initialized trading algorithm in backtest mode
r -0.774314
stdev 0.650009
sharpe -1.191235
TradingPair(374465 [btc_usdt]) 0.044980
TradingPair(23347 [eth_usdt]) 0.027125
TradingPair(19201 [ltc_usdt]) 0.091859
TradingPair(3314 [dash_usdt]) 0.320543
TradingPair(748770 [xmr_usdt]) 0.250509
TradingPair(680958 [etc_usdt]) 0.013610
TradingPair(417834 [zec_usdt]) 0.034781
TradingPair(345380 [xrp_usdt]) 0.172837
TradingPair(18350 [str_usdt]) 0.043757
Name: 43957, dtype: float64
r 0.505976
stdev 0.548862
sharpe 0.921864
TradingPair(374465 [btc_usdt]) 0.011322
TradingPair(23347 [eth_usdt]) 0.061596
TradingPair(19201 [ltc_usdt]) 0.154222
TradingPair(3314 [dash_usdt]) 0.333953
TradingPair(748770 [xmr_usdt]) 0.032554
TradingPair(680958 [etc_usdt]) 0.001896
TradingPair(417834 [zec_usdt]) 0.053802
TradingPair(345380 [xrp_usdt]) 0.324514
TradingPair(18350 [str_usdt]) 0.026141
Name: 44279, dtype: float64

portfolio_optimization.py:63: RuntimeWarning: invalid value encountered in true_divide
corr_m = cov_m / np.dot(np.transpose(stds), stds)
portfolio_optimization.py:81: RuntimeWarning: invalid value encountered in double_scalars
results_array[2, p] = results_array[0, p] / results_array[1, p]
Traceback (most recent call last):
File "portfolio_optimization.py", line 150, in
quote_currency='usdt')
File "C:\Users\ALEXAN1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\catalyst\utils\run_algo.py", line 643, in run_algorithm
stats_output=stats_output
File "C:\Users\ALEXAN
1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\catalyst\utils\run_algo.py", line 361, in _run
overwrite_sim_params=False,
File "C:\Users\ALEXAN1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\catalyst\exchange\exchange_algorithm.py", line 403, in run
data, overwrite_sim_params
File "C:\Users\ALEXAN
1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\catalyst\exchange\exchange_algorithm.py", line 360, in run
data, overwrite_sim_params
File "C:\Users\ALEXAN1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\catalyst\algorithm.py", line 725, in run
for perf in self.get_generator():
File "C:\Users\ALEXAN
1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\catalyst\gens\tradesimulation.py", line 224, in transform
for capital_change_packet in every_bar(dt):
File "C:\Users\ALEXAN1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\catalyst\gens\tradesimulation.py", line 137, in every_bar
handle_data(algo, current_data, dt_to_use)
File "C:\Users\ALEXAN
1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\catalyst\utils\events.py", line 216, in handle_data
dt,
File "C:\Users\ALEXAN1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\catalyst\utils\events.py", line 235, in handle_data
self.callback(context, data)
File "C:\Users\ALEXAN
1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\catalyst\exchange\exchange_algorithm.py", line 381, in handle_data
super(ExchangeTradingAlgorithmBacktest, self).handle_data(data)
File "C:\Users\ALEXAN1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\catalyst\algorithm.py", line 474, in handle_data
self._handle_data(self, data)
File "portfolio_optimization.py", line 92, in handle_data
max_sharpe_port = results_frame.iloc[results_frame['sharpe'].idxmax()]
File "C:\Users\ALEXAN
1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\pandas\core\indexing.py", line 1312, in getitem
return self._getitem_axis(key, axis=0)
File "C:\Users\ALEXAN1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\pandas\core\indexing.py", line 1621, in _getitem_axis
key = self._convert_scalar_indexer(key, axis)
File "C:\Users\ALEXAN
1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\pandas\core\indexing.py", line 196, in _convert_scalar_indexer
return ax._convert_scalar_indexer(key, kind=self.name)
File "C:\Users\ALEXAN1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\pandas\indexes\numeric.py", line 160, in _convert_scalar_indexer
._convert_scalar_indexer(key, kind=kind))
File "C:\Users\ALEXAN
1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\pandas\indexes\base.py", line 1144, in _convert_scalar_indexer
return self._validate_indexer('positional', key, kind)
File "C:\Users\ALEXAN1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\pandas\indexes\base.py", line 3035, in _validate_indexer
self._invalid_indexer(form, key)
File "C:\Users\ALEXAN
1\DOWNLO1\CATALY1.21\CATALY1.21\CATALY1\lib\site-packages\pandas\indexes\base.py", line 1284, in _invalid_indexer
kind=type(key)))
TypeError: cannot do positional indexing on <class 'pandas.indexes.range.RangeIndex'> with these indexers [nan] of <class 'float'>

  • What did you expect to happen?
    No errors

  • What happened instead?
    Errors

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

Reproduction Steps

  1. Install catalyst
  2. catalyst ingest-exchange -x poloniex -f daily -s 2018-05-04 -i btc_usdt,eth_usdt,ltc_usdt,dash_usdt,xmr_usdt,etc_usdt,zec_usdt,xrp_usdt,str_usdt
  3. python portfolio_optimization.py

Sincerely,

Alexander

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant