コード例 #1
0
    def test_internalization_explicit(self, entries, errors, _):
        """
        2014-01-01 open Assets:Invest:Cash      USD
        2014-01-01 open Assets:Invest:BOOG      BOOG
        2014-01-01 open Income:Invest:Dividends USD
        2014-01-01 open Assets:Bank:Checking    USD

        2014-01-10 * "Transferring money for investing"
          Assets:Bank:Checking      -1000.00 USD
          Assets:Invest:Cash         1000.00 USD

        2014-02-01 * "Buying"
          Assets:Invest:Cash       -1000.00 USD
          Assets:Invest:BOOG             10 BOOG {100 USD}

        2014-03-01 * "Dividend"
          Income:Invest:Dividends     -90.00 USD
          Assets:Invest:Cash           90.00 USD

        2015-01-01 balance Assets:Invest:BOOG         10 BOOG
        2015-01-01 balance Assets:Invest:Cash      90.00 USD
        """
        self.assertFalse(errors)

        # Check internalizing when including cash accounts.
        new_entries, replaced_entries = returns.internalize(
            entries, 'Equity:Internalized',
            {'Assets:Invest:Cash', 'Assets:Invest:BOOG'},
            {'Income:Invest:Dividends'})
        self.assertEqual([], replaced_entries)

        # Check internalizing when excluding cash accounts.
        new_entries, replaced_entries = returns.internalize(
            entries, 'Equity:Internalized',
            {'Assets:Invest:BOOG'},
            {'Income:Invest:Dividends'},
            {'Income:Invest:Dividends'})

        self.assertEqualEntries("""
        2014-03-01 * "Dividend"
          Income:Invest:Dividends     -90.00 USD
          Assets:Invest:Cash           90.00 USD
        """, replaced_entries)
コード例 #2
0
 def test_internalization_explicit_fails(self):
     with self.assertRaises(ValueError):
         returns.internalize([], 'Equity:Internalized',
                             {'Assets:Invest:Cash'}, {'Expenses:Fees'},
                             {'Income:Invest:PnL'})
コード例 #3
0
    def test_internalization_implicit(self, entries, errors, _):
        """
        ;; Value accounts
        2014-01-01 open Assets:Invest:Cash      USD
        2014-01-01 open Assets:Invest:BOOG      BOOG

        ;; Internal accounts (non-value)
        2014-01-01 open Income:Invest:PnL       USD
        2014-01-01 open Income:Invest:Dividends USD
        2014-01-01 open Expenses:Commissions    USD
        2014-01-01 open Expenses:Fees           USD

        ;; External accounts
        2014-01-01 open Assets:Bank:Checking    USD
        2014-01-01 open Income:Salary           USD
        2014-01-01 open Expenses:Taxes          USD

        ;; EXTERNAL ONLY
        2014-01-02 * "Salary Pay"
          Income:Salary            -3461.54 USD
          Expenses:Taxes            1176.92 USD
          Assets:Bank:Checking      2284.62 USD

        ;; VALUE + EXTERNAL
        2014-01-10 * "Transferring money for investing"
          Assets:Bank:Checking      -500.00 USD
          Assets:Invest:Cash         500.00 USD

        ;; VALUE ONLY
        2014-02-01 * "Buying some BOOG"
          Assets:Invest:Cash        -650.00 USD
          Assets:Invest:BOOG             10 BOOG {65 USD}

        ;; VALUE + INTERNAL
        2014-02-15 * "Selling half my position"
          Assets:Invest:BOOG             -5 BOOG {65 USD} @ 70 USD
          Assets:Invest:Cash         340.05 USD
          Expenses:Commissions         9.95 USD
          Income:Invest:PnL          -25.00 USD

        ;; VALUE + INTERNAL
        2014-02-20 * "Dividends from BOOG position"
          Assets:Invest:Cash          12.00 USD
          Income:Invest:Dividends    -12.00 USD

        ;; INTERNAL + EXTERNAL
        2014-03-17 * "Monthly fees"
          Assets:Bank:Checking        -4.00 USD
          Expenses:Fees                4.00 USD

        ;; INTERNAL + EXTERNAL
        2014-03-20 * "Dividend payment correction with fee"
          Income:Invest:Dividends     -9.00 USD
          Assets:Bank:Checking         9.00 USD

        ;; INTERNAL ONLY
        2014-03-20 * "Dividend payment with fee"
          Income:Invest:Dividends     -9.00 USD
          Expenses:Fees                9.00 USD

        ;; VALUE + INTERNAL + EXTERNAL
        2014-04-01 * "Transferring money by wire"
          Assets:Bank:Checking      -500.00 USD
          Assets:Invest:Cash         480.00 USD
          Expenses:Fees               20.00 USD

        ;; VALUE + EXTERNAL
        2014-06-30 * "Taking some money out for car repairs"
          Assets:Invest:Cash        -400.00 USD
          Assets:Bank:Checking       400.00 USD

        2015-01-01 balance Assets:Invest:Cash     282.05 USD
        2015-01-01 balance Assets:Bank:Checking  1689.62 USD
        """
        self.assertFalse(errors)

        accounts_value = {'Assets:Invest:Cash', 'Assets:Invest:BOOG'}
        accounts_intflows = {
            'Income:Invest:PnL', 'Income:Invest:Dividends',
            'Expenses:Commissions', 'Expenses:Fees'
        }
        new_entries, replaced_entries = returns.internalize(
            entries, 'Equity:Internalized', accounts_value, accounts_intflows)

        # Check that the split entry has been replaced.
        self.assertEqualEntries(
            """
        2014-04-01 * "Transferring money by wire"
          Assets:Bank:Checking      -500.00 USD
          Assets:Invest:Cash         480.00 USD
          Expenses:Fees               20.00 USD
        """, replaced_entries)

        # Look for the replaced entries and assert them.
        self.assertIncludesEntries(
            """
        2014-04-01 R "Transferring money by wire" ^internalized-00001
          Assets:Invest:Cash    480.00 USD
          Expenses:Fees          20.00 USD
          Equity:Internalized  -500.00 USD

        2014-04-01 R "Transferring money by wire" ^internalized-00001
          Equity:Internalized    500.00 USD
          Assets:Bank:Checking  -500.00 USD
        """, new_entries)

        # Check that the internalized account is present.
        self.assertIncludesEntries(
            """
        2014-01-01 open Equity:Internalized
        """, new_entries)