How to correctly calculate the BBP ( Bollinger bands percent ) for cryptocurency price?










0














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.










share|improve this question




























    0














    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.










    share|improve this question


























      0












      0








      0







      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 7:24

























      asked Nov 10 at 6:03









      Arman Feyzi

      347213




      347213






















          1 Answer
          1






          active

          oldest

          votes


















          0














          This is how I use BBANDS:



          upperband, middleband, lowerband = talib.BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=talib.MA_Type.T3)


          I multiply close (and other prices) by 1000000 since I then rescale them. Maybe it is because the closing prices are too low.






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            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

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            This is how I use BBANDS:



            upperband, middleband, lowerband = talib.BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=talib.MA_Type.T3)


            I multiply close (and other prices) by 1000000 since I then rescale them. Maybe it is because the closing prices are too low.






            share|improve this answer

























              0














              This is how I use BBANDS:



              upperband, middleband, lowerband = talib.BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=talib.MA_Type.T3)


              I multiply close (and other prices) by 1000000 since I then rescale them. Maybe it is because the closing prices are too low.






              share|improve this answer























                0












                0








                0






                This is how I use BBANDS:



                upperband, middleband, lowerband = talib.BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=talib.MA_Type.T3)


                I multiply close (and other prices) by 1000000 since I then rescale them. Maybe it is because the closing prices are too low.






                share|improve this answer












                This is how I use BBANDS:



                upperband, middleband, lowerband = talib.BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=talib.MA_Type.T3)


                I multiply close (and other prices) by 1000000 since I then rescale them. Maybe it is because the closing prices are too low.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 12 at 21:08









                iso_9001_

                58021126




                58021126



























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                    Crossroads (UK TV series)

                    ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế