How to correctly calculate the BBP ( Bollinger bands percent ) for cryptocurency price?
up vote
0
down vote
favorite
I try to calculate the BBP ( Bollinger bands percent ) in python by this code. Howevery, my BBP
function returns inf
or -inf
for bbp
. Confusingly when I use some coin close price like ETH
this function return the correct bbp
number (not inf).
This is my python code:
import requests
import json
import pandas as pd
import numpy as np
from talib import RSI, BBANDS
def BBP(price, close):
up, mid, low = BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)
bbp = (price['close'] - low) / (up - low)
print(up[-1])
print(mid[-1])
print(low[-1])
print(bbp.iloc[-1])
return bbp
r = requests.get('https://min-api.cryptocompare.com/data/histohour?fsym=SALT&tsym=BTC&limit=900&s=Binance&aggregate=5')
j = r.json()
price = pd.DataFrame(j['Data'])
price = price.sort_values(by='time', ascending=False)
price = price.iloc[::-1]
price = price.dropna()
close = price['close'].values
up, mid, low = BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)
rsi = RSI(close, timeperiod=14)
bbp = BBP(price, close)
price.insert(loc=0, column='RSI',value=rsi)
price.insert(loc=0, column='BBP',value=bbp)
print(price.head(30))
If I use ETH
instead of SALT
in the request API that code works correctly but in other small prices coins the BBP
function returns inf
for the BBP
column in the price data frame.
This is a sample of the return value for SALT
:
BBP RSI close high low open time
0 NaN NaN 0.000069 0.000071 0.000068 0.000068 1534626000
1 NaN NaN 0.000070 0.000070 0.000068 0.000069 1534644000
2 NaN NaN 0.000072 0.000072 0.000068 0.000070 1534662000
3 NaN NaN 0.000073 0.000073 0.000071 0.000072 1534680000
4 NaN NaN 0.000074 0.000074 0.000072 0.000073 1534698000
5 NaN NaN 0.000073 0.000074 0.000072 0.000074 1534716000
6 NaN NaN 0.000073 0.000074 0.000072 0.000073 1534734000
7 NaN NaN 0.000071 0.000073 0.000071 0.000073 1534752000
8 NaN NaN 0.000072 0.000074 0.000070 0.000071 1534770000
9 NaN NaN 0.000069 0.000072 0.000069 0.000072 1534788000
10 NaN NaN 0.000070 0.000071 0.000068 0.000069 1534806000
11 NaN NaN 0.000072 0.000072 0.000069 0.000070 1534824000
12 NaN NaN 0.000070 0.000072 0.000070 0.000072 1534842000
13 NaN NaN 0.000070 0.000070 0.000069 0.000070 1534860000
14 NaN 56.138260 0.000071 0.000072 0.000069 0.000070 1534878000
15 NaN 53.757682 0.000071 0.000073 0.000071 0.000071 1534896000
16 NaN 56.547317 0.000072 0.000072 0.000070 0.000071 1534914000
17 NaN 52.340624 0.000070 0.000072 0.000070 0.000072 1534932000
18 NaN 42.426811 0.000067 0.000071 0.000067 0.000070 1534950000
19 -inf 41.721667 0.000067 0.000067 0.000065 0.000067 1534968000
20 -inf 41.087686 0.000066 0.000067 0.000066 0.000067 1534986000
21 -inf 42.663976 0.000067 0.000067 0.000066 0.000066 1535004000
22 -inf 46.241512 0.000068 0.000068 0.000066 0.000067 1535022000
23 -inf 47.300220 0.000068 0.000069 0.000067 0.000068 1535040000
24 -inf 47.984947 0.000068 0.000069 0.000067 0.000068 1535058000
25 -inf 47.984947 0.000068 0.000069 0.000067 0.000068 1535076000
26 -inf 50.590822 0.000069 0.000069 0.000068 0.000068 1535094000
27 inf 56.805348 0.000071 0.000071 0.000068 0.000069 1535112000
28 inf 57.658800 0.000071 0.000072 0.000069 0.000071 1535130000
29 inf 63.418810 0.000073 0.000073 0.000070 0.000071 1535148000
How can I fix this?
Thanks.
python pandas finance ta-lib
add a comment |
up vote
0
down vote
favorite
I try to calculate the BBP ( Bollinger bands percent ) in python by this code. Howevery, my BBP
function returns inf
or -inf
for bbp
. Confusingly when I use some coin close price like ETH
this function return the correct bbp
number (not inf).
This is my python code:
import requests
import json
import pandas as pd
import numpy as np
from talib import RSI, BBANDS
def BBP(price, close):
up, mid, low = BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)
bbp = (price['close'] - low) / (up - low)
print(up[-1])
print(mid[-1])
print(low[-1])
print(bbp.iloc[-1])
return bbp
r = requests.get('https://min-api.cryptocompare.com/data/histohour?fsym=SALT&tsym=BTC&limit=900&s=Binance&aggregate=5')
j = r.json()
price = pd.DataFrame(j['Data'])
price = price.sort_values(by='time', ascending=False)
price = price.iloc[::-1]
price = price.dropna()
close = price['close'].values
up, mid, low = BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)
rsi = RSI(close, timeperiod=14)
bbp = BBP(price, close)
price.insert(loc=0, column='RSI',value=rsi)
price.insert(loc=0, column='BBP',value=bbp)
print(price.head(30))
If I use ETH
instead of SALT
in the request API that code works correctly but in other small prices coins the BBP
function returns inf
for the BBP
column in the price data frame.
This is a sample of the return value for SALT
:
BBP RSI close high low open time
0 NaN NaN 0.000069 0.000071 0.000068 0.000068 1534626000
1 NaN NaN 0.000070 0.000070 0.000068 0.000069 1534644000
2 NaN NaN 0.000072 0.000072 0.000068 0.000070 1534662000
3 NaN NaN 0.000073 0.000073 0.000071 0.000072 1534680000
4 NaN NaN 0.000074 0.000074 0.000072 0.000073 1534698000
5 NaN NaN 0.000073 0.000074 0.000072 0.000074 1534716000
6 NaN NaN 0.000073 0.000074 0.000072 0.000073 1534734000
7 NaN NaN 0.000071 0.000073 0.000071 0.000073 1534752000
8 NaN NaN 0.000072 0.000074 0.000070 0.000071 1534770000
9 NaN NaN 0.000069 0.000072 0.000069 0.000072 1534788000
10 NaN NaN 0.000070 0.000071 0.000068 0.000069 1534806000
11 NaN NaN 0.000072 0.000072 0.000069 0.000070 1534824000
12 NaN NaN 0.000070 0.000072 0.000070 0.000072 1534842000
13 NaN NaN 0.000070 0.000070 0.000069 0.000070 1534860000
14 NaN 56.138260 0.000071 0.000072 0.000069 0.000070 1534878000
15 NaN 53.757682 0.000071 0.000073 0.000071 0.000071 1534896000
16 NaN 56.547317 0.000072 0.000072 0.000070 0.000071 1534914000
17 NaN 52.340624 0.000070 0.000072 0.000070 0.000072 1534932000
18 NaN 42.426811 0.000067 0.000071 0.000067 0.000070 1534950000
19 -inf 41.721667 0.000067 0.000067 0.000065 0.000067 1534968000
20 -inf 41.087686 0.000066 0.000067 0.000066 0.000067 1534986000
21 -inf 42.663976 0.000067 0.000067 0.000066 0.000066 1535004000
22 -inf 46.241512 0.000068 0.000068 0.000066 0.000067 1535022000
23 -inf 47.300220 0.000068 0.000069 0.000067 0.000068 1535040000
24 -inf 47.984947 0.000068 0.000069 0.000067 0.000068 1535058000
25 -inf 47.984947 0.000068 0.000069 0.000067 0.000068 1535076000
26 -inf 50.590822 0.000069 0.000069 0.000068 0.000068 1535094000
27 inf 56.805348 0.000071 0.000071 0.000068 0.000069 1535112000
28 inf 57.658800 0.000071 0.000072 0.000069 0.000071 1535130000
29 inf 63.418810 0.000073 0.000073 0.000070 0.000071 1535148000
How can I fix this?
Thanks.
python pandas finance ta-lib
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I try to calculate the BBP ( Bollinger bands percent ) in python by this code. Howevery, my BBP
function returns inf
or -inf
for bbp
. Confusingly when I use some coin close price like ETH
this function return the correct bbp
number (not inf).
This is my python code:
import requests
import json
import pandas as pd
import numpy as np
from talib import RSI, BBANDS
def BBP(price, close):
up, mid, low = BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)
bbp = (price['close'] - low) / (up - low)
print(up[-1])
print(mid[-1])
print(low[-1])
print(bbp.iloc[-1])
return bbp
r = requests.get('https://min-api.cryptocompare.com/data/histohour?fsym=SALT&tsym=BTC&limit=900&s=Binance&aggregate=5')
j = r.json()
price = pd.DataFrame(j['Data'])
price = price.sort_values(by='time', ascending=False)
price = price.iloc[::-1]
price = price.dropna()
close = price['close'].values
up, mid, low = BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)
rsi = RSI(close, timeperiod=14)
bbp = BBP(price, close)
price.insert(loc=0, column='RSI',value=rsi)
price.insert(loc=0, column='BBP',value=bbp)
print(price.head(30))
If I use ETH
instead of SALT
in the request API that code works correctly but in other small prices coins the BBP
function returns inf
for the BBP
column in the price data frame.
This is a sample of the return value for SALT
:
BBP RSI close high low open time
0 NaN NaN 0.000069 0.000071 0.000068 0.000068 1534626000
1 NaN NaN 0.000070 0.000070 0.000068 0.000069 1534644000
2 NaN NaN 0.000072 0.000072 0.000068 0.000070 1534662000
3 NaN NaN 0.000073 0.000073 0.000071 0.000072 1534680000
4 NaN NaN 0.000074 0.000074 0.000072 0.000073 1534698000
5 NaN NaN 0.000073 0.000074 0.000072 0.000074 1534716000
6 NaN NaN 0.000073 0.000074 0.000072 0.000073 1534734000
7 NaN NaN 0.000071 0.000073 0.000071 0.000073 1534752000
8 NaN NaN 0.000072 0.000074 0.000070 0.000071 1534770000
9 NaN NaN 0.000069 0.000072 0.000069 0.000072 1534788000
10 NaN NaN 0.000070 0.000071 0.000068 0.000069 1534806000
11 NaN NaN 0.000072 0.000072 0.000069 0.000070 1534824000
12 NaN NaN 0.000070 0.000072 0.000070 0.000072 1534842000
13 NaN NaN 0.000070 0.000070 0.000069 0.000070 1534860000
14 NaN 56.138260 0.000071 0.000072 0.000069 0.000070 1534878000
15 NaN 53.757682 0.000071 0.000073 0.000071 0.000071 1534896000
16 NaN 56.547317 0.000072 0.000072 0.000070 0.000071 1534914000
17 NaN 52.340624 0.000070 0.000072 0.000070 0.000072 1534932000
18 NaN 42.426811 0.000067 0.000071 0.000067 0.000070 1534950000
19 -inf 41.721667 0.000067 0.000067 0.000065 0.000067 1534968000
20 -inf 41.087686 0.000066 0.000067 0.000066 0.000067 1534986000
21 -inf 42.663976 0.000067 0.000067 0.000066 0.000066 1535004000
22 -inf 46.241512 0.000068 0.000068 0.000066 0.000067 1535022000
23 -inf 47.300220 0.000068 0.000069 0.000067 0.000068 1535040000
24 -inf 47.984947 0.000068 0.000069 0.000067 0.000068 1535058000
25 -inf 47.984947 0.000068 0.000069 0.000067 0.000068 1535076000
26 -inf 50.590822 0.000069 0.000069 0.000068 0.000068 1535094000
27 inf 56.805348 0.000071 0.000071 0.000068 0.000069 1535112000
28 inf 57.658800 0.000071 0.000072 0.000069 0.000071 1535130000
29 inf 63.418810 0.000073 0.000073 0.000070 0.000071 1535148000
How can I fix this?
Thanks.
python pandas finance ta-lib
I try to calculate the BBP ( Bollinger bands percent ) in python by this code. Howevery, my BBP
function returns inf
or -inf
for bbp
. Confusingly when I use some coin close price like ETH
this function return the correct bbp
number (not inf).
This is my python code:
import requests
import json
import pandas as pd
import numpy as np
from talib import RSI, BBANDS
def BBP(price, close):
up, mid, low = BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)
bbp = (price['close'] - low) / (up - low)
print(up[-1])
print(mid[-1])
print(low[-1])
print(bbp.iloc[-1])
return bbp
r = requests.get('https://min-api.cryptocompare.com/data/histohour?fsym=SALT&tsym=BTC&limit=900&s=Binance&aggregate=5')
j = r.json()
price = pd.DataFrame(j['Data'])
price = price.sort_values(by='time', ascending=False)
price = price.iloc[::-1]
price = price.dropna()
close = price['close'].values
up, mid, low = BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)
rsi = RSI(close, timeperiod=14)
bbp = BBP(price, close)
price.insert(loc=0, column='RSI',value=rsi)
price.insert(loc=0, column='BBP',value=bbp)
print(price.head(30))
If I use ETH
instead of SALT
in the request API that code works correctly but in other small prices coins the BBP
function returns inf
for the BBP
column in the price data frame.
This is a sample of the return value for SALT
:
BBP RSI close high low open time
0 NaN NaN 0.000069 0.000071 0.000068 0.000068 1534626000
1 NaN NaN 0.000070 0.000070 0.000068 0.000069 1534644000
2 NaN NaN 0.000072 0.000072 0.000068 0.000070 1534662000
3 NaN NaN 0.000073 0.000073 0.000071 0.000072 1534680000
4 NaN NaN 0.000074 0.000074 0.000072 0.000073 1534698000
5 NaN NaN 0.000073 0.000074 0.000072 0.000074 1534716000
6 NaN NaN 0.000073 0.000074 0.000072 0.000073 1534734000
7 NaN NaN 0.000071 0.000073 0.000071 0.000073 1534752000
8 NaN NaN 0.000072 0.000074 0.000070 0.000071 1534770000
9 NaN NaN 0.000069 0.000072 0.000069 0.000072 1534788000
10 NaN NaN 0.000070 0.000071 0.000068 0.000069 1534806000
11 NaN NaN 0.000072 0.000072 0.000069 0.000070 1534824000
12 NaN NaN 0.000070 0.000072 0.000070 0.000072 1534842000
13 NaN NaN 0.000070 0.000070 0.000069 0.000070 1534860000
14 NaN 56.138260 0.000071 0.000072 0.000069 0.000070 1534878000
15 NaN 53.757682 0.000071 0.000073 0.000071 0.000071 1534896000
16 NaN 56.547317 0.000072 0.000072 0.000070 0.000071 1534914000
17 NaN 52.340624 0.000070 0.000072 0.000070 0.000072 1534932000
18 NaN 42.426811 0.000067 0.000071 0.000067 0.000070 1534950000
19 -inf 41.721667 0.000067 0.000067 0.000065 0.000067 1534968000
20 -inf 41.087686 0.000066 0.000067 0.000066 0.000067 1534986000
21 -inf 42.663976 0.000067 0.000067 0.000066 0.000066 1535004000
22 -inf 46.241512 0.000068 0.000068 0.000066 0.000067 1535022000
23 -inf 47.300220 0.000068 0.000069 0.000067 0.000068 1535040000
24 -inf 47.984947 0.000068 0.000069 0.000067 0.000068 1535058000
25 -inf 47.984947 0.000068 0.000069 0.000067 0.000068 1535076000
26 -inf 50.590822 0.000069 0.000069 0.000068 0.000068 1535094000
27 inf 56.805348 0.000071 0.000071 0.000068 0.000069 1535112000
28 inf 57.658800 0.000071 0.000072 0.000069 0.000071 1535130000
29 inf 63.418810 0.000073 0.000073 0.000070 0.000071 1535148000
How can I fix this?
Thanks.
python pandas finance ta-lib
python pandas finance ta-lib
edited Nov 10 at 7:24
asked Nov 10 at 6:03
Arman Feyzi
347212
347212
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236426%2fhow-to-correctly-calculate-the-bbp-bollinger-bands-percent-for-cryptocurency%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown