transaction-accounts


Nametransaction-accounts JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/igormusic/transaction-accounts
SummaryCreate configuration for transactional accounts and implement account runtime
upload_time2023-07-08 15:00:16
maintainer
docs_urlNone
authorIgor Music
requires_python
licenseMIT
keywords transaction processing loans savings accounts finance banking
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
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)
    
    

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/igormusic/transaction-accounts",
    "name": "transaction-accounts",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "TRANSACTION PROCESSING,LOANS,SAVINGS,ACCOUNTS,FINANCE,BANKING",
    "author": "Igor Music",
    "author_email": "igormusich@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c0/94/c32902234089c7d2986e2ce7ed077bb81d00c1ae0669107373285d00e730/transaction-accounts-0.2.1.tar.gz",
    "platform": null,
    "description": "\nTransaction Accounts\n====================\n\nThis library provides basic functionality for working with transaction accounts.\n\nYou can use it to make any type of transaction account, such as a savings account, a credit card, or a loan.\n\nAssume we would like to create simple Savings Account that has 3 types of balances:\n\n- current balance\n- interest accrued\n- withholding tax\n\nWe would like to have 4 types of transactions:\n\n- deposit\n- interest accrued\n- interest capitalized\n- withholding tax\n\nWe would like to have 2 types of schedules:\n\n- accrual schedule\n- compounding schedule\n\nWe would like to have interest rate with 3 tiers:\n\n- 0 - 10000: 3%\n- 10000 - 50000: 3.5%\n- 50000+: 4%\n\nWe would like to have monthly fee of 1.00 charged at the end of each month to the account before interest is accrued.\n\nDeposit transaction will increase current balance, and it will be used to deposit money to the account. \nThis transaction will be externally created and posted to the account.\n\nInterest accrued transaction will increase interest accrued balance, and it will be used to accrue interest on the account.\n\nInterest will be accrued daily, and it will be calculated based on current balance and interest rate.\n\nInterest capitalized transaction will increase current balance and decrease interest accrued balance.\nThis transaction will be internally created and posted to the account at the end of each month.\n\nWithholding tax transaction will decrease withholding tax balance, and it will be used to pay withholding tax on the account. \nIt will be calculated as 20% of interest capitalized transaction.\n\nWe will use accrual schedule to accrue interest daily, and we will use compounding schedule to capitalize interest at the end of each month.\n\nWe will use interest rate to calculate interest.\n\nWe will use trigger transaction to calculate withholding tax.\n\nWe will use monthly fee property to specify monthly fee. This amount will be charged at the end of each month.\n\nNote that this framework is not limited to this configuration, and it can be used to create any type of transaction account.\n\nYou can define custom calculations when calculating either schedules or transactions. In this context you can use any of the following variables:\n\n- account: Account\n- transaction: Transaction\n- config: Configuration\n\nHere is a code that will create this configuration:\n\n.. code:: python\n\n def create_savings_account() -> AccountType:\n    acc = AccountType(name=\"savingsAccount\", label=\"Savings Account\")\n\n    current = acc.add_position_type(\"current\", \"current balance\")\n    interest_accrued = acc.add_position_type(\"accrued\", \"interest accrued\")\n    withholding = acc.add_position_type(\"withholding\", \"withholding tax\")\n\n    montly_fee = acc.add_property_type(\"monthlyFee\", \"Monthly Fee\", DataType.DECIMAL, True)\n\n    acc.add_transaction_type(\"deposit\", \"Deposit\").add_position_rule(TransactionOperation.CREDIT, current)\n\n    fee_tt = acc.add_transaction_type(\"fee\", \"Fee\").add_position_rule(TransactionOperation.DEBIT, current)\n\n    interest_accrued_tt = acc.add_transaction_type(\"interestAccrued\", \"Interest Accrued\").add_position_rule(TransactionOperation.CREDIT, interest_accrued)\n\n    capitalized_tt = acc.add_transaction_type(\"capitalized\", \"Interest Capitalized\").add_position_rule(TransactionOperation.CREDIT, current).add_position_rule(TransactionOperation.DEBIT, interest_accrued)\n\n    withholding_tt = acc.add_transaction_type(\"withholdingTax\", \"Withholding Tax\").add_position_rule(TransactionOperation.CREDIT, withholding)\n\n    accrual_schedule = ScheduleType(name=\"accrual\", label=\"Accrual Schedule\", frequency=ScheduleFrequency.DAILY,\n                                    end_type=ScheduleEndType.NO_END,\n                                    business_day_adjustment=BusinessDayAdjustment.NO_ADJUSTMENT,\n                                    interval_expression=\"1\", start_date_expression=\"account.start_date\")\n\n    acc.add_schedule_type(accrual_schedule)\n\n    compounding_schedule = ScheduleType(name=\"compounding\", label=\"Compounding Schedule\",\n                                        frequency=ScheduleFrequency.MONTHLY,\n                                        end_type=ScheduleEndType.NO_END,\n                                        business_day_adjustment=BusinessDayAdjustment.NO_ADJUSTMENT,\n                                        interval_expression=\"1\",\n                                        start_date_expression=\"account.start_date + relativedelta(month=+1) + relativedelta(days=-1)\")\n\n    acc.add_schedule_type(compounding_schedule)\n\n    acc.add_scheduled_transaction(compounding_schedule, ScheduledTransactionTiming.END_OF_DAY,\n                                  fee_tt,\n                                  \"account.monthlyFee\")\n\n    acc.add_scheduled_transaction(accrual_schedule, ScheduledTransactionTiming.END_OF_DAY,\n                                  interest_accrued_tt,\n                                  \"account.current * accountType.interest.get_rate(account.current) / Decimal(365)\")\n\n    acc.add_scheduled_transaction(compounding_schedule, ScheduledTransactionTiming.END_OF_DAY,\n                                  capitalized_tt, \"account.accrued\")\n\n    interest_rate = acc.add_rate_type(\"interest\", \"Interest Rate\")\n\n    interest_rate.add_tier(Decimal(10000), Decimal(0.03))\n    interest_rate.add_tier(Decimal(100000), Decimal(0.035))\n    interest_rate.add_tier(Decimal(50000), Decimal(0.04))\n\n    acc.add_trigger_transaction(capitalized_tt, withholding_tt, \"transaction.amount * Decimal(0.2)\")\n\n    return acc\n\n\n\nGiven configuration, we can create an account:\n\n.. code:: python\n\n def test_valuation(self):\n        account_type = create_savings_account()\n\n        account = Account(start_date=date(2019, 1, 1), account_type_name=account_type.name,\n                          account_type=account_type, properties={\"monthlyFee\": Decimal(1.00)})\n\n        valuation = AccountValuation(account, account_type, date(2020, 1, 1))\n\n        deposit_transaction_type = account_type.get_transaction_type(\"deposit\")\n\n        external_transactions = group_by_date([\n            ExternalTransaction(transaction_type_name=deposit_transaction_type.name,\n                                amount=Decimal(1000), value_date=date(2019, 1, 1))])\n\n        valuation.forecast(date(2020, 1, 1), external_transactions)\n\n        self.assertAlmostEqual(account.positions['current'].amount, Decimal(1018.24775), places=4)\n        self.assertAlmostEqual(account.positions['withholding'].amount, Decimal(6.04955), places=4)\n        self.assertAlmostEqual(account.transactions[1].amount, Decimal('0.08219'), places=4)\n    \n    \n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Create configuration for transactional accounts and implement account runtime",
    "version": "0.2.1",
    "project_urls": {
        "Download": "https://github.com/igormusic/transaction-accounts/archive/refs/tags/0.0.6.tar.gz",
        "Homepage": "https://github.com/igormusic/transaction-accounts"
    },
    "split_keywords": [
        "transaction processing",
        "loans",
        "savings",
        "accounts",
        "finance",
        "banking"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c094c32902234089c7d2986e2ce7ed077bb81d00c1ae0669107373285d00e730",
                "md5": "ffa525e226da665b020a866c4037df47",
                "sha256": "64ae3c9caf305caf675851122b0ec9f3bce78d2265a12ba5aa0d4f1281541805"
            },
            "downloads": -1,
            "filename": "transaction-accounts-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ffa525e226da665b020a866c4037df47",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 18754,
            "upload_time": "2023-07-08T15:00:16",
            "upload_time_iso_8601": "2023-07-08T15:00:16.287372Z",
            "url": "https://files.pythonhosted.org/packages/c0/94/c32902234089c7d2986e2ce7ed077bb81d00c1ae0669107373285d00e730/transaction-accounts-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-08 15:00:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "igormusic",
    "github_project": "transaction-accounts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "transaction-accounts"
}
        
Elapsed time: 0.08804s