Skip to content

Instantly share code, notes, and snippets.

@welmends
Last active August 24, 2022 20:36
Show Gist options
  • Save welmends/44c991cf848eccbdd5f89fda732abe29 to your computer and use it in GitHub Desktop.
Save welmends/44c991cf848eccbdd5f89fda732abe29 to your computer and use it in GitHub Desktop.
Investment simulation on FIIs over years
# 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)
@welmends
Copy link
Author

welmends commented Oct 3, 2021

Example:

  • 5 years with 5k after that 10 years with 0k (price: 10, dividends: 0.08)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment