Last active
October 4, 2023 09:31
-
-
Save Pankaj-Gupta/3b6f8ebfb67544af5204fb6ef2233ddf to your computer and use it in GitHub Desktop.
This notebook simulates all the moving parts of ROSCA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"aim of this notebook is to complete all the maths related to Rosca\n", | |
"\n", | |
"- simulate a Rosca process, with multiple variables\n", | |
"- show min and max range of interests on savings\n", | |
"- show min and max range of interests on loans\n", | |
"- show what happens in scenarios where no one does bidding in the complete duration\n", | |
"- demonstrate if interest rates differ for people bidding later months, rather than later\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"#### NOTEBOOK FORMAT\n", | |
"- 1. Simulator Code\n", | |
"- 2. MAX INTEREST - when all take maximum loans except one(who doesnt takes any)\n", | |
"- 3. MIN INTEREST - when all users bid same\n", | |
"- 4. SAVINGS BANK DEPOSIT RATE simulator\n", | |
"- 5. When only one user takes loans (at max interest)\n", | |
"- 6. If a user deposits lumpsum money in the beginning of cycle" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## 1. Simulator Code" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# BUSINESS VARIABLES\n", | |
"STAKING_APY = 15.0\n", | |
"COMMISSION_PERCENT = 5.0\n", | |
"max_bid_ratio = 0.6 #participant cannot bid lower that ins*max_bid_ratio\n", | |
"IS_MONTHLY_PREMIUM_STAKED = True # whether to add monthly premiums back to staking" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# PROTOCOL_PARAMS\n", | |
"N = 12 #number of people participating in Rosca, it also represents the numbers of terms in a Rosca scheme\n", | |
"user_monthy_deposit = 100 #monthly deposit amount" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"pot_size = user_monthy_deposit*N\n", | |
"user_premium_array = [0]*N # the reason we are not mixing premium and deposits array is that, we dont want a monthly deposit to get cut from aggregated premiums itself\n", | |
"user_interest_array = [0]*N #this array is internal, it wont be visible to user. User will only see the premiums array\n", | |
"user_loan_array = [0]*N\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# create an array for user in which his initial money distribution is given.\n", | |
"# for scenarios where we take lumpsum amount from user at the start of rosca cycle" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def give_loan_to_winner_bid(bid_winner_index, current_bid):\n", | |
" amount_diff = pot_size - current_bid\n", | |
" premium_per_user = amount_diff/(N-1)\n", | |
" #decrease amount from user_deposits and give to winner bid. Give premium to rest of users\n", | |
" for k in range(N):\n", | |
" user_deposits_array[k] -= user_monthy_deposit\n", | |
" if k == bid_winner_index:\n", | |
" user_loan_array[k] += current_bid\n", | |
" else:\n", | |
" user_premium_array[k] += premium_per_user\n", | |
" return premium_per_user\n", | |
"\n", | |
"\n", | |
"def calculate_staking_rewards_of_month():\n", | |
" total_money_in_pool = sum(user_deposits_array)\n", | |
" if IS_MONTHLY_PREMIUM_STAKED:\n", | |
" total_money_in_pool += sum(user_premium_array) + sum(user_interest_array)\n", | |
" total_staking_return = total_money_in_pool*(STAKING_APY/12.0)/100\n", | |
" \n", | |
" #increase interest for each user, proportionally\n", | |
" for k in range(N):\n", | |
" user_money_in_pool = user_deposits_array[k] \n", | |
" if IS_MONTHLY_PREMIUM_STAKED:\n", | |
" user_money_in_pool += user_premium_array[k] + user_interest_array[k]\n", | |
" \n", | |
" #print(user_money_in_pool)\n", | |
" user_interest_array[k] = user_interest_array[k] + total_staking_return * (user_money_in_pool/total_money_in_pool)\n", | |
" \n", | |
" return total_money_in_pool, total_staking_return\n", | |
" \n", | |
" \n", | |
"def get_deposits_for_next_month():\n", | |
" # call API to get user deposits, if he has less money than the monthly deposit\n", | |
" for k in range(N):\n", | |
" if user_deposits_array[k] < user_monthy_deposit:\n", | |
" user_deposits_array[k] += user_monthy_deposit\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"\n", | |
"\n", | |
"def simulateROSCA():\n", | |
" \n", | |
" for i in range(N):\n", | |
" #print(user_interest_array)\n", | |
" current_bid = bid_array[i]\n", | |
" bid_winner_index = bid_user[i]\n", | |
"\n", | |
" total_money_in_pool, total_staking_return = calculate_staking_rewards_of_month()\n", | |
" premium_per_user = give_loan_to_winner_bid(bid_winner_index, current_bid)\n", | |
"\n", | |
" if i < N-1: # if it is NOT the last month\n", | |
" get_deposits_for_next_month()\n", | |
" #print(\"ROUND {} bid_vaue {} premium to other users {:.2f} money in pool {:.2f} staking returns {:.2f}\".format(i+1, current_bid, premium_per_user, total_money_in_pool, total_staking_return))\n", | |
" rosca_rounds.append({\n", | |
" \"ROUND #\": i+1,\n", | |
" \"BID VALUE\": current_bid,\n", | |
" \"BID USER\": i+1,\n", | |
" \"PREMIUM FOR OTHERS\": \"{:.2f}\".format(premium_per_user),\n", | |
" \"TOTAL MONEY IN POOL\": \"{:.2f}\".format(total_money_in_pool),\n", | |
" \"STAKING RETURNS\": \"{:.2f}\".format(total_staking_return)\n", | |
" })\n", | |
" \n", | |
" rosca_rounds_df = pd.DataFrame(rosca_rounds)\n", | |
" display(rosca_rounds_df)\n", | |
" \n", | |
"\n", | |
" print(\"\\ntotal staking returns: {:.2f}\".format(sum(user_interest_array)))\n", | |
" \n", | |
" #giving back staking money to users\n", | |
" total_staking_returns = sum(user_interest_array)\n", | |
" staking_returns_after_commission = total_staking_returns*(100-COMMISSION_PERCENT)/100\n", | |
" print(\"staking returns after commission: {:.2f}\\n\".format(staking_returns_after_commission))\n", | |
" \n", | |
" # cutting commission from generated interests\n", | |
" \n", | |
" #print(user_interest_array)\n", | |
" for k in range(N):\n", | |
" user_interest_array[k] = user_interest_array[k]*0.95\n", | |
"\n", | |
" #calculating final users savings rates\n", | |
" for k in range(N):\n", | |
" user_money_in_pool = user_deposits_array[k] + user_premium_array[k] + user_interest_array[k] + user_loan_array[k]\n", | |
"\n", | |
" interest_rate = (user_money_in_pool-user_monthy_deposit*N)/(user_monthy_deposit*N)*100\n", | |
" #print(\"USER {} wallet balance {:.2f} interest percent {:.2f} deposit {:.2f} premium {:.2f} interest {:.2f} loan {:.2f} \".format(k+1, user_money_in_pool, interest_rate, user_deposits_array[k], user_premium_array[k], user_interest_array[k], user_loan_array[k]))\n", | |
" \n", | |
" users_wallets.append({\n", | |
" \"USER\": \"USER \"+str(k+1),\n", | |
" \"WALLET BALANCE\": \"{:.2f}\".format(user_money_in_pool),\n", | |
" \"INTEREST PERCENT\": \"{:.2f}\".format(interest_rate)\n", | |
" })\n", | |
" \n", | |
" users_wallets_df = pd.DataFrame(users_wallets)\n", | |
"\n", | |
" display(users_wallets_df)\n", | |
" \n", | |
" \n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# pot_size = user_monthy_deposit*N\n", | |
"# user_premium_array = [0]*N # the reason we are not mixing premium and deposits array is that, we dont want a monthly deposit to get cut from aggregated premiums itself\n", | |
"# user_interest_array = [0]*N #this array is internal, it wont be visible to user. User will only see the premiums array\n", | |
"# user_loan_array = [0]*N\n", | |
"# rosca_rounds = []\n", | |
"# users_wallets = []\n", | |
"\n", | |
"# user_deposits_array = [user_monthy_deposit]*N\n", | |
"# #user_deposits_array[0] = 1200\n", | |
"# bid_array = [user_monthy_deposit*N*0.8]*N # each row represents the bid submitted by user\n", | |
"# bid_user = [i for i in range(N)] #index of user who bid that particular month\n", | |
"# simulateROSCA()\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 2. MAX INTEREST - when all take maximum loans except one(who doesnt takes any)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>ROUND #</th>\n", | |
" <th>BID VALUE</th>\n", | |
" <th>BID USER</th>\n", | |
" <th>PREMIUM FOR OTHERS</th>\n", | |
" <th>TOTAL MONEY IN POOL</th>\n", | |
" <th>STAKING RETURNS</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>1</td>\n", | |
" <td>720.0</td>\n", | |
" <td>1</td>\n", | |
" <td>43.64</td>\n", | |
" <td>1200.00</td>\n", | |
" <td>15.00</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>2</td>\n", | |
" <td>720.0</td>\n", | |
" <td>2</td>\n", | |
" <td>43.64</td>\n", | |
" <td>1695.00</td>\n", | |
" <td>21.19</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>3</td>\n", | |
" <td>720.0</td>\n", | |
" <td>3</td>\n", | |
" <td>43.64</td>\n", | |
" <td>2196.19</td>\n", | |
" <td>27.45</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>4</td>\n", | |
" <td>720.0</td>\n", | |
" <td>4</td>\n", | |
" <td>43.64</td>\n", | |
" <td>2703.64</td>\n", | |
" <td>33.80</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>5</td>\n", | |
" <td>720.0</td>\n", | |
" <td>5</td>\n", | |
" <td>43.64</td>\n", | |
" <td>3217.44</td>\n", | |
" <td>40.22</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>6</td>\n", | |
" <td>720.0</td>\n", | |
" <td>6</td>\n", | |
" <td>43.64</td>\n", | |
" <td>3737.65</td>\n", | |
" <td>46.72</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>7</td>\n", | |
" <td>720.0</td>\n", | |
" <td>7</td>\n", | |
" <td>43.64</td>\n", | |
" <td>4264.37</td>\n", | |
" <td>53.30</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>8</td>\n", | |
" <td>720.0</td>\n", | |
" <td>8</td>\n", | |
" <td>43.64</td>\n", | |
" <td>4797.68</td>\n", | |
" <td>59.97</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>9</td>\n", | |
" <td>720.0</td>\n", | |
" <td>9</td>\n", | |
" <td>43.64</td>\n", | |
" <td>5337.65</td>\n", | |
" <td>66.72</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>10</td>\n", | |
" <td>720.0</td>\n", | |
" <td>10</td>\n", | |
" <td>43.64</td>\n", | |
" <td>5884.37</td>\n", | |
" <td>73.55</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>11</td>\n", | |
" <td>720.0</td>\n", | |
" <td>11</td>\n", | |
" <td>43.64</td>\n", | |
" <td>6437.92</td>\n", | |
" <td>80.47</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>12</td>\n", | |
" <td>1200.0</td>\n", | |
" <td>12</td>\n", | |
" <td>0.00</td>\n", | |
" <td>6998.40</td>\n", | |
" <td>87.48</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" ROUND # BID VALUE BID USER PREMIUM FOR OTHERS TOTAL MONEY IN POOL \\\n", | |
"0 1 720.0 1 43.64 1200.00 \n", | |
"1 2 720.0 2 43.64 1695.00 \n", | |
"2 3 720.0 3 43.64 2196.19 \n", | |
"3 4 720.0 4 43.64 2703.64 \n", | |
"4 5 720.0 5 43.64 3217.44 \n", | |
"5 6 720.0 6 43.64 3737.65 \n", | |
"6 7 720.0 7 43.64 4264.37 \n", | |
"7 8 720.0 8 43.64 4797.68 \n", | |
"8 9 720.0 9 43.64 5337.65 \n", | |
"9 10 720.0 10 43.64 5884.37 \n", | |
"10 11 720.0 11 43.64 6437.92 \n", | |
"11 12 1200.0 12 0.00 6998.40 \n", | |
"\n", | |
" STAKING RETURNS \n", | |
"0 15.00 \n", | |
"1 21.19 \n", | |
"2 27.45 \n", | |
"3 33.80 \n", | |
"4 40.22 \n", | |
"5 46.72 \n", | |
"6 53.30 \n", | |
"7 59.97 \n", | |
"8 66.72 \n", | |
"9 73.55 \n", | |
"10 80.47 \n", | |
"11 87.48 " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"total staking returns: 605.88\n", | |
"staking returns after commission: 575.58\n", | |
"\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>USER</th>\n", | |
" <th>WALLET BALANCE</th>\n", | |
" <th>INTEREST PERCENT</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>USER 1</td>\n", | |
" <td>1201.23</td>\n", | |
" <td>0.10</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>USER 2</td>\n", | |
" <td>1201.82</td>\n", | |
" <td>0.15</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>USER 3</td>\n", | |
" <td>1202.40</td>\n", | |
" <td>0.20</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>USER 4</td>\n", | |
" <td>1202.97</td>\n", | |
" <td>0.25</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>USER 5</td>\n", | |
" <td>1203.54</td>\n", | |
" <td>0.29</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>USER 6</td>\n", | |
" <td>1204.09</td>\n", | |
" <td>0.34</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>USER 7</td>\n", | |
" <td>1204.64</td>\n", | |
" <td>0.39</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>USER 8</td>\n", | |
" <td>1205.19</td>\n", | |
" <td>0.43</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>USER 9</td>\n", | |
" <td>1205.73</td>\n", | |
" <td>0.48</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>USER 10</td>\n", | |
" <td>1206.26</td>\n", | |
" <td>0.52</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>USER 11</td>\n", | |
" <td>1206.78</td>\n", | |
" <td>0.57</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>USER 12</td>\n", | |
" <td>1730.94</td>\n", | |
" <td>44.24</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" USER WALLET BALANCE INTEREST PERCENT\n", | |
"0 USER 1 1201.23 0.10\n", | |
"1 USER 2 1201.82 0.15\n", | |
"2 USER 3 1202.40 0.20\n", | |
"3 USER 4 1202.97 0.25\n", | |
"4 USER 5 1203.54 0.29\n", | |
"5 USER 6 1204.09 0.34\n", | |
"6 USER 7 1204.64 0.39\n", | |
"7 USER 8 1205.19 0.43\n", | |
"8 USER 9 1205.73 0.48\n", | |
"9 USER 10 1206.26 0.52\n", | |
"10 USER 11 1206.78 0.57\n", | |
"11 USER 12 1730.94 44.24" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"pot_size = user_monthy_deposit*N\n", | |
"user_premium_array = [0]*N # the reason we are not mixing premium and deposits array is that, we dont want a monthly deposit to get cut from aggregated premiums itself\n", | |
"user_interest_array = [0]*N #this array is internal, it wont be visible to user. User will only see the premiums array\n", | |
"user_loan_array = [0]*N\n", | |
"rosca_rounds = []\n", | |
"users_wallets = []\n", | |
"\n", | |
"\n", | |
"user_deposits_array = [user_monthy_deposit]*N\n", | |
"\n", | |
"\n", | |
"bid_array = [user_monthy_deposit*N*max_bid_ratio]*N # each row represents the bid submitted by user\n", | |
"bid_array[-1] = user_monthy_deposit*N\n", | |
"bid_user = [i for i in range(N)] #index of user who bid that particular month\n", | |
"#initializeROSCA()\n", | |
"simulateROSCA()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 3. MIN INTEREST - when all users bid same" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>ROUND #</th>\n", | |
" <th>BID VALUE</th>\n", | |
" <th>BID USER</th>\n", | |
" <th>PREMIUM FOR OTHERS</th>\n", | |
" <th>TOTAL MONEY IN POOL</th>\n", | |
" <th>STAKING RETURNS</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>1</td>\n", | |
" <td>1080.0</td>\n", | |
" <td>1</td>\n", | |
" <td>10.91</td>\n", | |
" <td>1200.00</td>\n", | |
" <td>15.00</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>2</td>\n", | |
" <td>1080.0</td>\n", | |
" <td>2</td>\n", | |
" <td>10.91</td>\n", | |
" <td>1335.00</td>\n", | |
" <td>16.69</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>3</td>\n", | |
" <td>1080.0</td>\n", | |
" <td>3</td>\n", | |
" <td>10.91</td>\n", | |
" <td>1471.69</td>\n", | |
" <td>18.40</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>4</td>\n", | |
" <td>1080.0</td>\n", | |
" <td>4</td>\n", | |
" <td>10.91</td>\n", | |
" <td>1610.08</td>\n", | |
" <td>20.13</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>5</td>\n", | |
" <td>1080.0</td>\n", | |
" <td>5</td>\n", | |
" <td>10.91</td>\n", | |
" <td>1750.21</td>\n", | |
" <td>21.88</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>6</td>\n", | |
" <td>1080.0</td>\n", | |
" <td>6</td>\n", | |
" <td>10.91</td>\n", | |
" <td>1892.09</td>\n", | |
" <td>23.65</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>7</td>\n", | |
" <td>1080.0</td>\n", | |
" <td>7</td>\n", | |
" <td>10.91</td>\n", | |
" <td>2035.74</td>\n", | |
" <td>25.45</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>8</td>\n", | |
" <td>1080.0</td>\n", | |
" <td>8</td>\n", | |
" <td>10.91</td>\n", | |
" <td>2181.19</td>\n", | |
" <td>27.26</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>9</td>\n", | |
" <td>1080.0</td>\n", | |
" <td>9</td>\n", | |
" <td>10.91</td>\n", | |
" <td>2328.45</td>\n", | |
" <td>29.11</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>10</td>\n", | |
" <td>1080.0</td>\n", | |
" <td>10</td>\n", | |
" <td>10.91</td>\n", | |
" <td>2477.56</td>\n", | |
" <td>30.97</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>11</td>\n", | |
" <td>1080.0</td>\n", | |
" <td>11</td>\n", | |
" <td>10.91</td>\n", | |
" <td>2628.52</td>\n", | |
" <td>32.86</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>12</td>\n", | |
" <td>1080.0</td>\n", | |
" <td>12</td>\n", | |
" <td>10.91</td>\n", | |
" <td>2781.38</td>\n", | |
" <td>34.77</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" ROUND # BID VALUE BID USER PREMIUM FOR OTHERS TOTAL MONEY IN POOL \\\n", | |
"0 1 1080.0 1 10.91 1200.00 \n", | |
"1 2 1080.0 2 10.91 1335.00 \n", | |
"2 3 1080.0 3 10.91 1471.69 \n", | |
"3 4 1080.0 4 10.91 1610.08 \n", | |
"4 5 1080.0 5 10.91 1750.21 \n", | |
"5 6 1080.0 6 10.91 1892.09 \n", | |
"6 7 1080.0 7 10.91 2035.74 \n", | |
"7 8 1080.0 8 10.91 2181.19 \n", | |
"8 9 1080.0 9 10.91 2328.45 \n", | |
"9 10 1080.0 10 10.91 2477.56 \n", | |
"10 11 1080.0 11 10.91 2628.52 \n", | |
"11 12 1080.0 12 10.91 2781.38 \n", | |
"\n", | |
" STAKING RETURNS \n", | |
"0 15.00 \n", | |
"1 16.69 \n", | |
"2 18.40 \n", | |
"3 20.13 \n", | |
"4 21.88 \n", | |
"5 23.65 \n", | |
"6 25.45 \n", | |
"7 27.26 \n", | |
"8 29.11 \n", | |
"9 30.97 \n", | |
"10 32.86 \n", | |
"11 34.77 " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"total staking returns: 296.15\n", | |
"staking returns after commission: 281.34\n", | |
"\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>USER</th>\n", | |
" <th>WALLET BALANCE</th>\n", | |
" <th>INTEREST PERCENT</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>USER 1</td>\n", | |
" <td>1222.67</td>\n", | |
" <td>1.89</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>USER 2</td>\n", | |
" <td>1222.82</td>\n", | |
" <td>1.90</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>USER 3</td>\n", | |
" <td>1222.96</td>\n", | |
" <td>1.91</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>USER 4</td>\n", | |
" <td>1223.11</td>\n", | |
" <td>1.93</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>USER 5</td>\n", | |
" <td>1223.25</td>\n", | |
" <td>1.94</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>USER 6</td>\n", | |
" <td>1223.39</td>\n", | |
" <td>1.95</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>USER 7</td>\n", | |
" <td>1223.52</td>\n", | |
" <td>1.96</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>USER 8</td>\n", | |
" <td>1223.66</td>\n", | |
" <td>1.97</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>USER 9</td>\n", | |
" <td>1223.79</td>\n", | |
" <td>1.98</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>USER 10</td>\n", | |
" <td>1223.93</td>\n", | |
" <td>1.99</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>USER 11</td>\n", | |
" <td>1224.06</td>\n", | |
" <td>2.00</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>USER 12</td>\n", | |
" <td>1224.19</td>\n", | |
" <td>2.02</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" USER WALLET BALANCE INTEREST PERCENT\n", | |
"0 USER 1 1222.67 1.89\n", | |
"1 USER 2 1222.82 1.90\n", | |
"2 USER 3 1222.96 1.91\n", | |
"3 USER 4 1223.11 1.93\n", | |
"4 USER 5 1223.25 1.94\n", | |
"5 USER 6 1223.39 1.95\n", | |
"6 USER 7 1223.52 1.96\n", | |
"7 USER 8 1223.66 1.97\n", | |
"8 USER 9 1223.79 1.98\n", | |
"9 USER 10 1223.93 1.99\n", | |
"10 USER 11 1224.06 2.00\n", | |
"11 USER 12 1224.19 2.02" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"pot_size = user_monthy_deposit*N\n", | |
"user_premium_array = [0]*N # the reason we are not mixing premium and deposits array is that, we dont want a monthly deposit to get cut from aggregated premiums itself\n", | |
"user_interest_array = [0]*N #this array is internal, it wont be visible to user. User will only see the premiums array\n", | |
"user_loan_array = [0]*N\n", | |
"rosca_rounds = []\n", | |
"users_wallets = []\n", | |
"\n", | |
"user_deposits_array = [user_monthy_deposit]*N\n", | |
"bid_array = [user_monthy_deposit*N*0.9]*N # each row represents the bid submitted by user\n", | |
"bid_user = [i for i in range(N)] #index of user who bid that particular month\n", | |
"#initializeROSCA()\n", | |
"simulateROSCA()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 4. SAVINGS BANK DEPOSIT RATE" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"ROUND 1 deposited amount 100.00 interest 0.33\n", | |
"ROUND 2 deposited amount 200.33 interest 0.67\n", | |
"ROUND 3 deposited amount 301.00 interest 1.00\n", | |
"ROUND 4 deposited amount 402.00 interest 1.34\n", | |
"ROUND 5 deposited amount 503.34 interest 1.68\n", | |
"ROUND 6 deposited amount 605.02 interest 2.02\n", | |
"ROUND 7 deposited amount 707.04 interest 2.36\n", | |
"ROUND 8 deposited amount 809.40 interest 2.70\n", | |
"ROUND 9 deposited amount 912.09 interest 3.04\n", | |
"ROUND 10 deposited amount 1015.13 interest 3.38\n", | |
"ROUND 11 deposited amount 1118.52 interest 3.73\n", | |
"ROUND 12 deposited amount 1222.25 interest 4.07\n" | |
] | |
} | |
], | |
"source": [ | |
"# calculating compound interest on the deposit\n", | |
"\n", | |
"savings_interest_rate = 4\n", | |
"\n", | |
"deposited_amount = 0\n", | |
"for i in range(N):\n", | |
" deposited_amount += user_monthy_deposit\n", | |
" \n", | |
" interest = deposited_amount*(savings_interest_rate/12.0)/100\n", | |
" print(\"ROUND {} deposited amount {:.2f} interest {:.2f}\".format(i+1, deposited_amount, interest))\n", | |
" deposited_amount += interest\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 5. When only one user takes loans (at max interest)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>ROUND #</th>\n", | |
" <th>BID VALUE</th>\n", | |
" <th>BID USER</th>\n", | |
" <th>PREMIUM FOR OTHERS</th>\n", | |
" <th>TOTAL MONEY IN POOL</th>\n", | |
" <th>STAKING RETURNS</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>1</td>\n", | |
" <td>720.0</td>\n", | |
" <td>1</td>\n", | |
" <td>43.64</td>\n", | |
" <td>1200.00</td>\n", | |
" <td>15.00</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>2</td>\n", | |
" <td>1200.0</td>\n", | |
" <td>2</td>\n", | |
" <td>0.00</td>\n", | |
" <td>1695.00</td>\n", | |
" <td>21.19</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>3</td>\n", | |
" <td>1200.0</td>\n", | |
" <td>3</td>\n", | |
" <td>0.00</td>\n", | |
" <td>1716.19</td>\n", | |
" <td>21.45</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>4</td>\n", | |
" <td>1200.0</td>\n", | |
" <td>4</td>\n", | |
" <td>0.00</td>\n", | |
" <td>1737.64</td>\n", | |
" <td>21.72</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>5</td>\n", | |
" <td>1200.0</td>\n", | |
" <td>5</td>\n", | |
" <td>0.00</td>\n", | |
" <td>1759.36</td>\n", | |
" <td>21.99</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>6</td>\n", | |
" <td>1200.0</td>\n", | |
" <td>6</td>\n", | |
" <td>0.00</td>\n", | |
" <td>1781.35</td>\n", | |
" <td>22.27</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>7</td>\n", | |
" <td>1200.0</td>\n", | |
" <td>7</td>\n", | |
" <td>0.00</td>\n", | |
" <td>1803.62</td>\n", | |
" <td>22.55</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>8</td>\n", | |
" <td>1200.0</td>\n", | |
" <td>8</td>\n", | |
" <td>0.00</td>\n", | |
" <td>1826.16</td>\n", | |
" <td>22.83</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>9</td>\n", | |
" <td>1200.0</td>\n", | |
" <td>9</td>\n", | |
" <td>0.00</td>\n", | |
" <td>1848.99</td>\n", | |
" <td>23.11</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>10</td>\n", | |
" <td>1200.0</td>\n", | |
" <td>10</td>\n", | |
" <td>0.00</td>\n", | |
" <td>1872.10</td>\n", | |
" <td>23.40</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>11</td>\n", | |
" <td>1200.0</td>\n", | |
" <td>11</td>\n", | |
" <td>0.00</td>\n", | |
" <td>1895.51</td>\n", | |
" <td>23.69</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>12</td>\n", | |
" <td>1200.0</td>\n", | |
" <td>12</td>\n", | |
" <td>0.00</td>\n", | |
" <td>1919.20</td>\n", | |
" <td>23.99</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" ROUND # BID VALUE BID USER PREMIUM FOR OTHERS TOTAL MONEY IN POOL \\\n", | |
"0 1 720.0 1 43.64 1200.00 \n", | |
"1 2 1200.0 2 0.00 1695.00 \n", | |
"2 3 1200.0 3 0.00 1716.19 \n", | |
"3 4 1200.0 4 0.00 1737.64 \n", | |
"4 5 1200.0 5 0.00 1759.36 \n", | |
"5 6 1200.0 6 0.00 1781.35 \n", | |
"6 7 1200.0 7 0.00 1803.62 \n", | |
"7 8 1200.0 8 0.00 1826.16 \n", | |
"8 9 1200.0 9 0.00 1848.99 \n", | |
"9 10 1200.0 10 0.00 1872.10 \n", | |
"10 11 1200.0 11 0.00 1895.51 \n", | |
"11 12 1200.0 12 0.00 1919.20 \n", | |
"\n", | |
" STAKING RETURNS \n", | |
"0 15.00 \n", | |
"1 21.19 \n", | |
"2 21.45 \n", | |
"3 21.72 \n", | |
"4 21.99 \n", | |
"5 22.27 \n", | |
"6 22.55 \n", | |
"7 22.83 \n", | |
"8 23.11 \n", | |
"9 23.40 \n", | |
"10 23.69 \n", | |
"11 23.99 " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"total staking returns: 263.19\n", | |
"staking returns after commission: 250.03\n", | |
"\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>USER</th>\n", | |
" <th>WALLET BALANCE</th>\n", | |
" <th>INTEREST PERCENT</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>USER 1</td>\n", | |
" <td>735.27</td>\n", | |
" <td>-38.73</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>USER 2</td>\n", | |
" <td>1264.98</td>\n", | |
" <td>5.41</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>USER 3</td>\n", | |
" <td>1264.98</td>\n", | |
" <td>5.41</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>USER 4</td>\n", | |
" <td>1264.98</td>\n", | |
" <td>5.41</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>USER 5</td>\n", | |
" <td>1264.98</td>\n", | |
" <td>5.41</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>USER 6</td>\n", | |
" <td>1264.98</td>\n", | |
" <td>5.41</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>USER 7</td>\n", | |
" <td>1264.98</td>\n", | |
" <td>5.41</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>USER 8</td>\n", | |
" <td>1264.98</td>\n", | |
" <td>5.41</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>USER 9</td>\n", | |
" <td>1264.98</td>\n", | |
" <td>5.41</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>USER 10</td>\n", | |
" <td>1264.98</td>\n", | |
" <td>5.41</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>USER 11</td>\n", | |
" <td>1264.98</td>\n", | |
" <td>5.41</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>USER 12</td>\n", | |
" <td>1264.98</td>\n", | |
" <td>5.41</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" USER WALLET BALANCE INTEREST PERCENT\n", | |
"0 USER 1 735.27 -38.73\n", | |
"1 USER 2 1264.98 5.41\n", | |
"2 USER 3 1264.98 5.41\n", | |
"3 USER 4 1264.98 5.41\n", | |
"4 USER 5 1264.98 5.41\n", | |
"5 USER 6 1264.98 5.41\n", | |
"6 USER 7 1264.98 5.41\n", | |
"7 USER 8 1264.98 5.41\n", | |
"8 USER 9 1264.98 5.41\n", | |
"9 USER 10 1264.98 5.41\n", | |
"10 USER 11 1264.98 5.41\n", | |
"11 USER 12 1264.98 5.41" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"pot_size = user_monthy_deposit*N\n", | |
"user_premium_array = [0]*N # the reason we are not mixing premium and deposits array is that, we dont want a monthly deposit to get cut from aggregated premiums itself\n", | |
"user_interest_array = [0]*N #this array is internal, it wont be visible to user. User will only see the premiums array\n", | |
"user_loan_array = [0]*N\n", | |
"rosca_rounds = []\n", | |
"users_wallets = []\n", | |
"\n", | |
"user_deposits_array = [user_monthy_deposit]*N\n", | |
"\n", | |
"bid_array = [user_monthy_deposit*N]*N # each row represents the bid submitted by user\n", | |
"bid_array[0] = user_monthy_deposit*N*max_bid_ratio\n", | |
"bid_user = [i for i in range(N)] #index of user who bid that particular month\n", | |
"#initializeROSCA()\n", | |
"simulateROSCA()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 6. If a user deposits lumpsum money in the beginning of cycle" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>ROUND #</th>\n", | |
" <th>BID VALUE</th>\n", | |
" <th>BID USER</th>\n", | |
" <th>PREMIUM FOR OTHERS</th>\n", | |
" <th>TOTAL MONEY IN POOL</th>\n", | |
" <th>STAKING RETURNS</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>1</td>\n", | |
" <td>960.0</td>\n", | |
" <td>1</td>\n", | |
" <td>21.82</td>\n", | |
" <td>2300.00</td>\n", | |
" <td>28.75</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>2</td>\n", | |
" <td>960.0</td>\n", | |
" <td>2</td>\n", | |
" <td>21.82</td>\n", | |
" <td>2468.75</td>\n", | |
" <td>30.86</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>3</td>\n", | |
" <td>960.0</td>\n", | |
" <td>3</td>\n", | |
" <td>21.82</td>\n", | |
" <td>2639.61</td>\n", | |
" <td>33.00</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>4</td>\n", | |
" <td>960.0</td>\n", | |
" <td>4</td>\n", | |
" <td>21.82</td>\n", | |
" <td>2812.60</td>\n", | |
" <td>35.16</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>5</td>\n", | |
" <td>960.0</td>\n", | |
" <td>5</td>\n", | |
" <td>21.82</td>\n", | |
" <td>2987.76</td>\n", | |
" <td>37.35</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>6</td>\n", | |
" <td>960.0</td>\n", | |
" <td>6</td>\n", | |
" <td>21.82</td>\n", | |
" <td>3165.11</td>\n", | |
" <td>39.56</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>7</td>\n", | |
" <td>960.0</td>\n", | |
" <td>7</td>\n", | |
" <td>21.82</td>\n", | |
" <td>3344.67</td>\n", | |
" <td>41.81</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>8</td>\n", | |
" <td>960.0</td>\n", | |
" <td>8</td>\n", | |
" <td>21.82</td>\n", | |
" <td>3526.48</td>\n", | |
" <td>44.08</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>9</td>\n", | |
" <td>960.0</td>\n", | |
" <td>9</td>\n", | |
" <td>21.82</td>\n", | |
" <td>3710.56</td>\n", | |
" <td>46.38</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>10</td>\n", | |
" <td>960.0</td>\n", | |
" <td>10</td>\n", | |
" <td>21.82</td>\n", | |
" <td>3896.94</td>\n", | |
" <td>48.71</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>11</td>\n", | |
" <td>960.0</td>\n", | |
" <td>11</td>\n", | |
" <td>21.82</td>\n", | |
" <td>4085.66</td>\n", | |
" <td>51.07</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>12</td>\n", | |
" <td>960.0</td>\n", | |
" <td>12</td>\n", | |
" <td>21.82</td>\n", | |
" <td>4276.73</td>\n", | |
" <td>53.46</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" ROUND # BID VALUE BID USER PREMIUM FOR OTHERS TOTAL MONEY IN POOL \\\n", | |
"0 1 960.0 1 21.82 2300.00 \n", | |
"1 2 960.0 2 21.82 2468.75 \n", | |
"2 3 960.0 3 21.82 2639.61 \n", | |
"3 4 960.0 4 21.82 2812.60 \n", | |
"4 5 960.0 5 21.82 2987.76 \n", | |
"5 6 960.0 6 21.82 3165.11 \n", | |
"6 7 960.0 7 21.82 3344.67 \n", | |
"7 8 960.0 8 21.82 3526.48 \n", | |
"8 9 960.0 9 21.82 3710.56 \n", | |
"9 10 960.0 10 21.82 3896.94 \n", | |
"10 11 960.0 11 21.82 4085.66 \n", | |
"11 12 960.0 12 21.82 4276.73 \n", | |
"\n", | |
" STAKING RETURNS \n", | |
"0 28.75 \n", | |
"1 30.86 \n", | |
"2 33.00 \n", | |
"3 35.16 \n", | |
"4 37.35 \n", | |
"5 39.56 \n", | |
"6 41.81 \n", | |
"7 44.08 \n", | |
"8 46.38 \n", | |
"9 48.71 \n", | |
"10 51.07 \n", | |
"11 53.46 " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"total staking returns: 490.19\n", | |
"staking returns after commission: 465.68\n", | |
"\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>USER</th>\n", | |
" <th>WALLET BALANCE</th>\n", | |
" <th>INTEREST PERCENT</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>USER 1</td>\n", | |
" <td>1316.32</td>\n", | |
" <td>9.69</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>USER 2</td>\n", | |
" <td>1230.36</td>\n", | |
" <td>2.53</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>USER 3</td>\n", | |
" <td>1230.65</td>\n", | |
" <td>2.55</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>USER 4</td>\n", | |
" <td>1230.94</td>\n", | |
" <td>2.58</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>USER 5</td>\n", | |
" <td>1231.22</td>\n", | |
" <td>2.60</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>USER 6</td>\n", | |
" <td>1231.50</td>\n", | |
" <td>2.63</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>USER 7</td>\n", | |
" <td>1231.78</td>\n", | |
" <td>2.65</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>USER 8</td>\n", | |
" <td>1232.05</td>\n", | |
" <td>2.67</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>USER 9</td>\n", | |
" <td>1232.32</td>\n", | |
" <td>2.69</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>USER 10</td>\n", | |
" <td>1232.58</td>\n", | |
" <td>2.72</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>USER 11</td>\n", | |
" <td>1232.85</td>\n", | |
" <td>2.74</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>USER 12</td>\n", | |
" <td>1233.10</td>\n", | |
" <td>2.76</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" USER WALLET BALANCE INTEREST PERCENT\n", | |
"0 USER 1 1316.32 9.69\n", | |
"1 USER 2 1230.36 2.53\n", | |
"2 USER 3 1230.65 2.55\n", | |
"3 USER 4 1230.94 2.58\n", | |
"4 USER 5 1231.22 2.60\n", | |
"5 USER 6 1231.50 2.63\n", | |
"6 USER 7 1231.78 2.65\n", | |
"7 USER 8 1232.05 2.67\n", | |
"8 USER 9 1232.32 2.69\n", | |
"9 USER 10 1232.58 2.72\n", | |
"10 USER 11 1232.85 2.74\n", | |
"11 USER 12 1233.10 2.76" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"pot_size = user_monthy_deposit*N\n", | |
"user_premium_array = [0]*N # the reason we are not mixing premium and deposits array is that, we dont want a monthly deposit to get cut from aggregated premiums itself\n", | |
"user_interest_array = [0]*N #this array is internal, it wont be visible to user. User will only see the premiums array\n", | |
"user_loan_array = [0]*N\n", | |
"rosca_rounds = []\n", | |
"users_wallets = []\n", | |
"\n", | |
"user_deposits_array = [user_monthy_deposit]*N\n", | |
"user_deposits_array[0] = 1200\n", | |
"bid_array = [user_monthy_deposit*N*0.8]*N # each row represents the bid submitted by user\n", | |
"bid_user = [i for i in range(N)] #index of user who bid that particular month\n", | |
"simulateROSCA()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment