|
Revision 375, 1.0 kB
(checked in by simon, 4 years ago)
|
|
Miscellaneous small scripts.
|
-
Property svn:mime-type set to
text/python-source
-
Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 | import sys |
|---|
| 2 | |
|---|
| 3 | def Usage(aArgs): |
|---|
| 4 | print "usage:", aArgs[0], "<bond amount>", "<months>", "<rate>" |
|---|
| 5 | print " Outputs monthly repayments." |
|---|
| 6 | print " <bond amount> in some currency." |
|---|
| 7 | print " <months> over which loan will be repayed." |
|---|
| 8 | print " <rate> as an annual percentage which is compounded monthly." |
|---|
| 9 | |
|---|
| 10 | def Main(aArgs): |
|---|
| 11 | if len(aArgs) != 4: |
|---|
| 12 | Usage(aArgs) |
|---|
| 13 | return 1 |
|---|
| 14 | |
|---|
| 15 | X = float(aArgs[1]) |
|---|
| 16 | M = int(aArgs[2]) |
|---|
| 17 | r = float(aArgs[3]) |
|---|
| 18 | |
|---|
| 19 | q = r/(100.0*12.0) |
|---|
| 20 | p = 1.0 + q |
|---|
| 21 | |
|---|
| 22 | Z = [p**n for n in range(0,M+1)] |
|---|
| 23 | D = X * Z[M] / sum(Z[0:M]) # Repayments |
|---|
| 24 | |
|---|
| 25 | An = [X*Z[n] - D*sum(Z[0:n]) for n in range(0,M+1)] # Amounts owed |
|---|
| 26 | Rn = [An[n] - An[n+1] for n in range(0,M)] |
|---|
| 27 | |
|---|
| 28 | print "Repayments:", D |
|---|
| 29 | print "Amounts:" |
|---|
| 30 | print "\n".join([str(x) + " : " + str(An[x]) for x in range(0,M,24)]) |
|---|
| 31 | print "Reductions:" |
|---|
| 32 | print "\n".join([str(x) + " : " + str(Rn[x]) for x in range(0,M,24)]) |
|---|
| 33 | return 0 |
|---|
| 34 | |
|---|
| 35 | if __name__ == "__main__": |
|---|
| 36 | sys.exit(Main(sys.argv)) |
|---|