create account

Compound Interest with Streamlit & Python by geekgirl

View this thread on: hive.blogpeakd.comecency.com
· @geekgirl ·
$9.32
Compound Interest with Streamlit & Python
<center>![compound_interest.png](https://images.hive.blog/DQmXn7cHBGDKcZHXgGpLtJupYFpdoQVMfjBbpM3daWwq5x7/compound_interest.png)</center>

We can often hear investors and traders say the key for financial success is compound interest. I personally interpret it as reinvesting the profits. Here is what Ivestopedia says about compound interest:

>Compound interest (or compounding interest) is the interest on a loan or deposit calculated based on both the initial principal and the accumulated interest from previous periods. Thought to have originated in 17th-century Italy, compound interest can be thought of as "interest on interest," and will make a sum grow at a faster rate than simple interest, which is calculated only on the principal amount.

The image above demonstrates the formula for calculating compound interest. Recently, a friend of mine jokingly asked if I could write a python code to display compound interest for staked assets. Even it is for fun, I thought why not? As a quick app making library I chose to use Streemlit and wrote up some code to display growth of the principal amount based on the interest rate and compounding interest every second. I believe normally compounding would work every month. I am not really sure how compounding works in defi. In any case, I just used every second. Below is the code, try it yourself.

```
import streamlit as st 
import time

amount = st.sidebar.text_input('Amount', '1000.00')
interest_rate = st.sidebar.text_input('Interest Rate', '10.00')
start = st.sidebar.button('Start')

if __name__ == '__main__':
    '''
    # Compound Interest!
    '''
    if start:

        st.markdown("""
                    <style>
                    .big-font {
                    color:green;
                    font-size:80px !important;
                    }
                    </style>
                    """, unsafe_allow_html=True)

        A = 0
        P = float(amount)
        r = float(interest_rate)
        n = 12 * 365 * 24 * 60 * 60
        t = 1  
        A = P * (1 + (r / 100) / n) ** (n*t)    
        b = st.empty()
        for i in range(n):
            I = P * (r / 100) / n
            P = P + I
            P = round(P, 8)
            txt = str(P)
            b.markdown('<p class="big-font">{}</p>'.format(txt), unsafe_allow_html=True)
            time.sleep(1)
```


Posted Using [LeoFinance <sup>Beta</sup>](https://leofinance.io/@geekgirl/compound-interest-with-streamlit-and-python)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 234 others
properties (23)
authorgeekgirl
permlinkcompound-interest-with-streamlit-and-python
categoryhive-167922
json_metadata{"app":"leofinance/0.2","format":"markdown","tags":["market","crypto","interest","money","neoxian","ctptalk","posh","palnet","blog","leofinance"],"canonical_url":"https://leofinance.io/@geekgirl/compound-interest-with-streamlit-and-python","image":["https://images.hive.blog/DQmXn7cHBGDKcZHXgGpLtJupYFpdoQVMfjBbpM3daWwq5x7/compound_interest.png"]}
created2021-01-25 07:13:15
last_update2021-01-25 07:13:15
depth0
children5
last_payout2021-02-01 07:13:15
cashout_time1969-12-31 23:59:59
total_payout_value5.266 HBD
curator_payout_value4.050 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,472
author_reputation1,588,017,852,468,897
root_title"Compound Interest with Streamlit & Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id101,545,149
net_rshares43,962,338,225,936
author_curate_reward""
vote details (298)
@mominsdt ·
$0.05
Thank you @geekgirl for coding for calculating compound interest
👍  
properties (23)
authormominsdt
permlinkqnhhsx
categoryhive-167922
json_metadata{"users":["geekgirl"],"app":"hiveblog/0.1"}
created2021-01-25 09:46:12
last_update2021-01-25 09:46:12
depth1
children0
last_payout2021-02-01 09:46:12
cashout_time1969-12-31 23:59:59
total_payout_value0.024 HBD
curator_payout_value0.025 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length64
author_reputation5,271,058,967,388
root_title"Compound Interest with Streamlit & Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id101,546,929
net_rshares375,445,430,674
author_curate_reward""
vote details (1)
@poshbot ·
https://twitter.com/geekjen/status/1353602342935875584
properties (22)
authorposhbot
permlinkre-compound-interest-with-streamlit-and-python-20210125t071528z
categoryhive-167922
json_metadata"{"app": "beem/0.24.20"}"
created2021-01-25 07:15:27
last_update2021-01-25 07:15:27
depth1
children0
last_payout2021-02-01 07:15:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length54
author_reputation5,554,335,374,496
root_title"Compound Interest with Streamlit & Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id101,545,170
net_rshares0
@poshbot ·
https://twitter.com/Bhattg18/status/1353639704088875008
properties (22)
authorposhbot
permlinkre-compound-interest-with-streamlit-and-python-20210125t094504z
categoryhive-167922
json_metadata"{"app": "beem/0.24.20"}"
created2021-01-25 09:45:03
last_update2021-01-25 09:45:03
depth1
children0
last_payout2021-02-01 09:45:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length55
author_reputation5,554,335,374,496
root_title"Compound Interest with Streamlit & Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id101,546,912
net_rshares0
@tuck-fheman ·
$0.07
I taught her everything she knows.
👍  
properties (23)
authortuck-fheman
permlinkre-geekgirl-qnl6c8
categoryhive-167922
json_metadata{"tags":["hive-167922"],"app":"peakd/2021.01.3"}
created2021-01-27 09:28:57
last_update2021-01-27 09:28:57
depth1
children1
last_payout2021-02-03 09:28:57
cashout_time1969-12-31 23:59:59
total_payout_value0.036 HBD
curator_payout_value0.036 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length34
author_reputation345,778,813,561,569
root_title"Compound Interest with Streamlit & Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id101,578,491
net_rshares526,351,341,964
author_curate_reward""
vote details (1)
@geekgirl ·
True!
properties (22)
authorgeekgirl
permlinkqnl7at
categoryhive-167922
json_metadata{"app":"hiveblog/0.1"}
created2021-01-27 09:49:42
last_update2021-01-27 09:49:42
depth2
children0
last_payout2021-02-03 09:49:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5
author_reputation1,588,017,852,468,897
root_title"Compound Interest with Streamlit & Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id101,578,700
net_rshares0