Last active
August 24, 2022 20:36
-
-
Save welmends/44c991cf848eccbdd5f89fda732abe29 to your computer and use it in GitHub Desktop.
Investment simulation on FIIs over years
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
# Investment simulation on FIIs over years | |
import math | |
import matplotlib.pyplot as plt | |
import locale | |
locale.setlocale(locale.LC_ALL, '') | |
# FII | |
price = 10 | |
dividends = 0.08 | |
shares = 0 | |
# Input | |
months = 12*10 | |
monthly_invest = 5000.0 | |
init = fund = 0.0 | |
hist = [init+monthly_invest] | |
# Share Update | |
su = lambda shares,fund,price: (shares+int(fund/price), fund%price) | |
# Compound Interest | |
for i in range(months): | |
fund += monthly_invest | |
shares, fund = su(shares,fund,price) | |
fund += shares*dividends | |
hist.append(fund+shares*price) | |
shares, fund = su(shares,fund,price) | |
legacy = round(shares*price+fund,2) | |
invest = round(abs(init+months*monthly_invest), 2) | |
profit = round(legacy-invest, 2) | |
profit_month = round(shares*dividends, 2) | |
# Display | |
print('legacy: {}'.format(locale.currency(legacy, grouping=True))) | |
print('total investment: {}'.format(locale.currency(invest, grouping=True))) | |
print('total profit: {}'.format(locale.currency(profit, grouping=True))) | |
print('monthly profit: {} ({}% a.m.)'.format(locale.currency(profit_month, grouping=True), round(dividends*100/price, 2))) | |
print('shares: {}'.format(shares)) | |
plt.plot(hist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: