Exemple #1
0
 def test_perturbate_withdrawal(self):
     Fixture1.create_execution_details(self.goal, self.t4,
                                       self.goal.available_balance / 90, 90,
                                       date(2016, 1, 1))
     TransactionFactory.create(from_goal=self.goal,
                               status=Transaction.STATUS_PENDING,
                               amount=self.goal.total_balance / 2)
     weights = perturbate_withdrawal(self.goal)
     self.assertTrue(sum(weights.values()) < 1)
Exemple #2
0
    def setUp(self):
        super(FirmAnalyticsMixinTests, self).setUp()
        self.support_group = GroupFactory(name=GROUP_SUPPORT_STAFF)
        self.bonds_type = InvestmentType.Standard.BONDS.get()
        self.stocks_type = InvestmentType.Standard.STOCKS.get()

        self.view = self.DummyView()
        self.today = today = timezone.now().date()
        # Populate the AccountType -> RiskProfileGroup mapping
        for atid, _ in constants.ACCOUNT_TYPES:
            AccountTypeRiskProfileGroupFactory.create(account_type=atid)
        # first client
        self.betasmartz_client = ClientFactory.create()
        self.client_account = ClientAccountFactory.create(
            primary_owner=self.betasmartz_client,
            account_type=constants.ACCOUNT_TYPE_PERSONAL)
        self.firm = self.betasmartz_client.advisor.firm

        self.external_asset1 = ExternalAssetFactory.create(
            owner=self.betasmartz_client)
        self.external_asset2 = ExternalAssetFactory.create(
            owner=self.betasmartz_client)
        self.goal = GoalFactory.create(account=self.client_account)
        self.goal2 = GoalFactory.create(account=self.client_account)
        self.transaction = TransactionFactory.create(
            to_goal=self.goal,
            from_goal=self.goal2,
            amount=self.goal.cash_balance,
            status=Transaction.STATUS_EXECUTED,
            reason=Transaction.REASON_TRANSFER,
            executed=self.today)

        # second client
        self.betasmartz_client2 = ClientFactory.create(
            advisor=self.betasmartz_client.advisor)
        self.client_account2 = ClientAccountFactory.create(
            primary_owner=self.betasmartz_client2,
            account_type=constants.ACCOUNT_TYPE_PERSONAL)
        self.external_asset1 = ExternalAssetFactory.create(
            owner=self.betasmartz_client2)
        self.external_asset2 = ExternalAssetFactory.create(
            owner=self.betasmartz_client2)

        self.goal3 = GoalFactory.create(account=self.client_account2)
        self.goal4 = GoalFactory.create(account=self.client_account2)
        self.transaction2 = TransactionFactory.create(
            to_goal=self.goal3,
            from_goal=self.goal4,
            amount=self.goal3.cash_balance,
            status=Transaction.STATUS_EXECUTED,
            reason=Transaction.REASON_TRANSFER,
            executed=self.today)
    def setUp(self):
        for atid, _ in constants.ACCOUNT_TYPES:
            AccountTypeRiskProfileGroupFactory.create(account_type=atid)
        self.today = today = date(2016, 5, 1)
        self.older_fiscal_year = FiscalYearFactory.create()
        self.older_fiscal_year2 = FiscalYearFactory.create()
        self.current_fiscal_year = FiscalYearFactory.create(
            year=today.year,
            begin_date=datetime(year=today.year, month=1, day=1),
            end_date=datetime(year=today.year, month=12, day=31))
        self.firm = FirmFactory.create()
        self.firm.fiscal_years.add(self.older_fiscal_year)
        self.firm.fiscal_years.add(self.older_fiscal_year2)
        self.firm.fiscal_years.add(self.current_fiscal_year)
        # add an advisor for the firm
        self.advisor = AdvisorFactory.create(firm=self.firm)
        # add a client account for the firm
        self.betasmartz_client = ClientFactory.create(advisor=self.advisor)
        self.client_account = ClientAccountFactory.create(
            primary_owner=self.betasmartz_client)
        # add some goals
        self.goal1 = GoalFactory.create(account=self.client_account)
        self.goal2 = GoalFactory.create(account=self.client_account)
        # add some transaction fees associated with the goals
        # there are two fees here, one for the from_goal1, and one for the to_goal2
        self.fee1 = TransactionFactory.create(
            reason=Transaction.REASON_FEE,
            status=Transaction.STATUS_EXECUTED,
            from_goal=self.goal1,
            to_goal=self.goal2,
            amount=500,
            executed=today - relativedelta(months=1))

        # add new advisor to firm
        # add new clientacounts for advisor and fees
        self.advisor2 = AdvisorFactory.create(firm=self.firm)
        self.betasmartz_client2 = ClientFactory.create(advisor=self.advisor2)
        self.client_account2 = ClientAccountFactory.create(
            primary_owner=self.betasmartz_client2)
        self.goal3 = GoalFactory.create(account=self.client_account2)
        # add some more fees
        self.fee2 = TransactionFactory.create(
            reason=Transaction.REASON_FEE,
            status=Transaction.STATUS_EXECUTED,
            to_goal=self.goal3,
            amount=800,
            executed=self.older_fiscal_year.begin_date +
            relativedelta(months=1))
Exemple #4
0
    def create_execution_details(cls, goal, ticker, quantity, price, executed):
        mor = MarketOrderRequest.objects.create(
            state=MarketOrderRequest.State.COMPLETE.value,
            account=goal.account)
        er = ExecutionRequest.objects.create(
            reason=ExecutionRequest.Reason.DRIFT.value,
            goal=goal,
            asset=ticker,
            volume=quantity,
            order=mor)
        execution = ExecutionFactory.create(asset=ticker,
                                            volume=quantity,
                                            order=mor,
                                            price=price,
                                            executed=executed,
                                            amount=quantity * price)
        transaction = TransactionFactory.create(
            reason=Transaction.REASON_EXECUTION,
            to_goal=None,
            from_goal=goal,
            status=Transaction.STATUS_EXECUTED,
            executed=executed,
            amount=quantity * price)
        distribution = ExecutionDistributionFactory.create(
            execution=execution,
            transaction=transaction,
            volume=quantity,
            execution_request=er)
        position_lot = PositionLotFactory.create(
            quantity=quantity, execution_distribution=distribution)

        return_values = list()
        return_values.extend(
            (mor, execution, transaction, distribution, position_lot))
        return return_values
 def setUp(self):
     # self.user = SuperUserFactory.create()
     self.user = User.objects.create_superuser('superadmin',
                                               '*****@*****.**',
                                               'test')
     self.platform = PlatformFactory.create()
     self.transaction = TransactionFactory.create()
Exemple #6
0
 def test_fees_ytd(self):
     expected_fees_ytd = self.fee1.amount * 2
     # check setUp fees match expected
     self.assertEqual(self.firm.fees_ytd, expected_fees_ytd)
     # add new fee and check new estimate matches expectation
     new_fee = TransactionFactory.create(reason=Transaction.REASON_FEE,
                                         status=Transaction.STATUS_EXECUTED,
                                         to_goal=self.goal1,
                                         amount=100,
                                         executed=self.today - relativedelta(days=1))
     self.assertEqual(self.firm.fees_ytd, new_fee.amount + expected_fees_ytd)
Exemple #7
0
    def test_pending_transaction_status_executed_after_charge(self):
        trans = TransactionFactory.create(
            stripe_id=self.transfer['data']['object']['id'],
            status=Transaction.STATUS_PENDING)
        self.assertEqual(trans.status, Transaction.STATUS_PENDING)

        url = reverse('api:v1:stripe-webhook')
        data = self.transfer
        request = self.client.post(url, data)
        self.assertEqual(request.status_code, status.HTTP_200_OK)
        lookup_trans = Transaction.objects.get(pk=trans.id)
        self.assertEqual(lookup_trans.status, Transaction.STATUS_EXECUTED)
Exemple #8
0
    def test_transfer_failed(self):
        trans = TransactionFactory.create(
            stripe_id=self.transfer['data']['object']['id'],
            status=Transaction.STATUS_PENDING)
        self.assertEqual(trans.status, Transaction.STATUS_PENDING)

        url = reverse('api:v1:stripe-webhook')
        data = self.transfer
        data['type'] = 'transfer.failed'
        data['data']['object']['failure_code'] = 1
        data['data']['object'][
            'failure_message'] = 'Some error occurred trying to process transfer'
        request = self.client.post(url, data)
        self.assertEqual(request.status_code, status.HTTP_200_OK)
        lookup_trans = Transaction.objects.get(pk=trans.id)
        self.assertEqual(lookup_trans.status, Transaction.STATUS_FAILED)