-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
176 lines (119 loc) · 7.45 KB
/
setup.py
File metadata and controls
176 lines (119 loc) · 7.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
from setuptools import setup, find_packages
setup(
name='transaction-accounts',
version='0.2.1',
description='Create configuration for transactional accounts and implement account runtime',
long_description='''
Transaction Accounts
====================
This library provides basic functionality for working with transaction accounts.
You can use it to make any type of transaction account, such as a savings account, a credit card, or a loan.
Assume we would like to create simple Savings Account that has 3 types of balances:
- current balance
- interest accrued
- withholding tax
We would like to have 4 types of transactions:
- deposit
- interest accrued
- interest capitalized
- withholding tax
We would like to have 2 types of schedules:
- accrual schedule
- compounding schedule
We would like to have interest rate with 3 tiers:
- 0 - 10000: 3%
- 10000 - 50000: 3.5%
- 50000+: 4%
We would like to have monthly fee of 1.00 charged at the end of each month to the account before interest is accrued.
Deposit transaction will increase current balance, and it will be used to deposit money to the account.
This transaction will be externally created and posted to the account.
Interest accrued transaction will increase interest accrued balance, and it will be used to accrue interest on the account.
Interest will be accrued daily, and it will be calculated based on current balance and interest rate.
Interest capitalized transaction will increase current balance and decrease interest accrued balance.
This transaction will be internally created and posted to the account at the end of each month.
Withholding tax transaction will decrease withholding tax balance, and it will be used to pay withholding tax on the account.
It will be calculated as 20% of interest capitalized transaction.
We will use accrual schedule to accrue interest daily, and we will use compounding schedule to capitalize interest at the end of each month.
We will use interest rate to calculate interest.
We will use trigger transaction to calculate withholding tax.
We will use monthly fee property to specify monthly fee. This amount will be charged at the end of each month.
Note that this framework is not limited to this configuration, and it can be used to create any type of transaction account.
You can define custom calculations when calculating either schedules or transactions. In this context you can use any of the following variables:
- account: Account
- transaction: Transaction
- config: Configuration
Here is a code that will create this configuration:
.. code:: python
def create_savings_account() -> AccountType:
acc = AccountType(name="savingsAccount", label="Savings Account")
current = acc.add_position_type("current", "current balance")
interest_accrued = acc.add_position_type("accrued", "interest accrued")
withholding = acc.add_position_type("withholding", "withholding tax")
montly_fee = acc.add_property_type("monthlyFee", "Monthly Fee", DataType.DECIMAL, True)
acc.add_transaction_type("deposit", "Deposit").add_position_rule(TransactionOperation.CREDIT, current)
fee_tt = acc.add_transaction_type("fee", "Fee").add_position_rule(TransactionOperation.DEBIT, current)
interest_accrued_tt = acc.add_transaction_type("interestAccrued", "Interest Accrued").add_position_rule(TransactionOperation.CREDIT, interest_accrued)
capitalized_tt = acc.add_transaction_type("capitalized", "Interest Capitalized").add_position_rule(TransactionOperation.CREDIT, current).add_position_rule(TransactionOperation.DEBIT, interest_accrued)
withholding_tt = acc.add_transaction_type("withholdingTax", "Withholding Tax").add_position_rule(TransactionOperation.CREDIT, withholding)
accrual_schedule = ScheduleType(name="accrual", label="Accrual Schedule", frequency=ScheduleFrequency.DAILY,
end_type=ScheduleEndType.NO_END,
business_day_adjustment=BusinessDayAdjustment.NO_ADJUSTMENT,
interval_expression="1", start_date_expression="account.start_date")
acc.add_schedule_type(accrual_schedule)
compounding_schedule = ScheduleType(name="compounding", label="Compounding Schedule",
frequency=ScheduleFrequency.MONTHLY,
end_type=ScheduleEndType.NO_END,
business_day_adjustment=BusinessDayAdjustment.NO_ADJUSTMENT,
interval_expression="1",
start_date_expression="account.start_date + relativedelta(month=+1) + relativedelta(days=-1)")
acc.add_schedule_type(compounding_schedule)
acc.add_scheduled_transaction(compounding_schedule, ScheduledTransactionTiming.END_OF_DAY,
fee_tt,
"account.monthlyFee")
acc.add_scheduled_transaction(accrual_schedule, ScheduledTransactionTiming.END_OF_DAY,
interest_accrued_tt,
"account.current * accountType.interest.get_rate(account.current) / Decimal(365)")
acc.add_scheduled_transaction(compounding_schedule, ScheduledTransactionTiming.END_OF_DAY,
capitalized_tt, "account.accrued")
interest_rate = acc.add_rate_type("interest", "Interest Rate")
interest_rate.add_tier(Decimal(10000), Decimal(0.03))
interest_rate.add_tier(Decimal(100000), Decimal(0.035))
interest_rate.add_tier(Decimal(50000), Decimal(0.04))
acc.add_trigger_transaction(capitalized_tt, withholding_tt, "transaction.amount * Decimal(0.2)")
return acc
Given configuration, we can create an account:
.. code:: python
def test_valuation(self):
account_type = create_savings_account()
account = Account(start_date=date(2019, 1, 1), account_type_name=account_type.name,
account_type=account_type, properties={"monthlyFee": Decimal(1.00)})
valuation = AccountValuation(account, account_type, date(2020, 1, 1))
deposit_transaction_type = account_type.get_transaction_type("deposit")
external_transactions = group_by_date([
ExternalTransaction(transaction_type_name=deposit_transaction_type.name,
amount=Decimal(1000), value_date=date(2019, 1, 1))])
valuation.forecast(date(2020, 1, 1), external_transactions)
self.assertAlmostEqual(account.positions['current'].amount, Decimal(1018.24775), places=4)
self.assertAlmostEqual(account.positions['withholding'].amount, Decimal(6.04955), places=4)
self.assertAlmostEqual(account.transactions[1].amount, Decimal('0.08219'), places=4)
''',
author='Igor Music',
author_email='igormusich@gmail.com',
packages=find_packages(),
license='MIT',
url='https://github.com/igormusic/transaction-accounts',
download_url='https://github.com/igormusic/transaction-accounts/archive/refs/tags/0.0.6.tar.gz',
keywords=['TRANSACTION PROCESSING', 'LOANS', 'SAVINGS', 'ACCOUNTS', 'FINANCE', 'BANKING'],
install_requires=[
'python-dateutil',
'pydantic',
'scipy'
],
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers', # Define that your audience are developers
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.9',
],
)