コード例 #1
0
ファイル: test_settings.py プロジェクト: fagan2888/Betasmartz
    def setUp(self):
        self.support_group = GroupFactory(name=GROUP_SUPPORT_STAFF)
        self.personal_account_type = AccountType.objects.create(
            id=ACCOUNT_TYPE_PERSONAL)
        self.r401k_account_type = AccountType.objects.create(
            id=ACCOUNT_TYPE_ROTH401K)
        self.bonds_type = InvestmentType.Standard.BONDS.get()
        self.stocks_type = InvestmentType.Standard.STOCKS.get()
        self.bonds_asset_class = AssetClassFactory.create(
            investment_type=self.bonds_type)
        self.stocks_asset_class = AssetClassFactory.create(
            investment_type=self.stocks_type)
        self.portfolio_set = PortfolioSetFactory.create()
        self.portfolio_set.asset_classes.add(self.bonds_asset_class,
                                             self.stocks_asset_class)

        self.risk_score_metric = {
            "type": GoalMetric.METRIC_TYPE_RISK_SCORE,
            "comparison": GoalMetric.METRIC_COMPARISON_EXACTLY,
            "configured_val": 0.4,
            "rebalance_type": GoalMetric.REBALANCE_TYPE_RELATIVE,
            "rebalance_thr": 0.1
        }
        self.bonds_index = MarketIndexFactory.create()
        self.stocks_index = MarketIndexFactory.create()
        self.bonds_ticker = TickerFactory.create(
            asset_class=self.bonds_asset_class, benchmark=self.bonds_index)
        self.stocks_ticker = TickerFactory.create(
            asset_class=self.stocks_asset_class, benchmark=self.stocks_index)
コード例 #2
0
ファイル: test_advice.py プロジェクト: brightgems/beta_python
    def setUp(self):
        # Mocked to speed up tests, no need run them every time
        PDFStatement.save_pdf = MagicMock()

        self.support_group = GroupFactory(name=GROUP_SUPPORT_STAFF)
        self.plan = RetirementPlanFactory.create()
        self.plan2 = RetirementPlanFactory.create(client=self.plan.client)
        self.plan3 = RetirementPlanFactory.create()
        # self.advice_url = reverse('api:v1:client-retirement-advice', args=[self.plan.client.id, self.plan.id])
        self.plan_url = '/api/v1/clients/{}/retirement-plans/{}'.format(
            self.plan.client.id, self.plan.id)
        self.advice_url = '/api/v1/clients/{}/retirement-plans/{}/advice-feed'.format(
            self.plan.client.id, self.plan.id)
        self.invite = EmailInviteFactory.create(
            user=self.plan.client.user, status=EmailInvite.STATUS_ACCEPTED)

        self.bonds_type = InvestmentType.Standard.BONDS.get()
        self.stocks_type = InvestmentType.Standard.STOCKS.get()
        self.bonds_asset_class = AssetClassFactory.create(
            investment_type=self.bonds_type)
        self.stocks_asset_class = AssetClassFactory.create(
            investment_type=self.stocks_type)
        self.portfolio_set = PortfolioSetFactory.create()
        self.portfolio_set.asset_classes.add(self.bonds_asset_class,
                                             self.stocks_asset_class)
コード例 #3
0
ファイル: test_settings.py プロジェクト: fagan2888/Betasmartz
    def test_get_portfolio_sets(self):
        portfolio_set = PortfolioSetFactory.create()

        url = '/api/v1/settings/portfolio-sets'
        self.client.force_authenticate(user=Fixture1.client1().user)
        response = self.client.get(url)

        self.assertEqual(len(response.data),
                         PortfolioSet.objects.all().count())
        self.assertTrue('name' in response.data[0])
        self.assertTrue('portfolio_provider' in response.data[0])
コード例 #4
0
    def setUp(self):
        self.t1 = TickerFactory.create(symbol='SPY', unit_price=5)
        self.t2 = TickerFactory.create(symbol='VEA', unit_price=5)
        self.t3 = TickerFactory.create(symbol='TIP', unit_price=100)
        self.t4 = TickerFactory.create(symbol='IEV', unit_price=100)

        self.t5 = TickerFactory.create(symbol='IEV2',
                                       unit_price=100,
                                       asset_class=self.t4.asset_class)

        self.equity = AssetFeatureValueFactory.create(
            name='equity', assets=[self.t1, self.t2])
        self.bond = AssetFeatureValueFactory.create(name='bond',
                                                    assets=[self.t3, self.t4])

        self.goal_settings = GoalSettingFactory.create()
        asset_classes = [
            self.t1.asset_class, self.t2.asset_class, self.t3.asset_class,
            self.t4.asset_class
        ]
        portfolio_set = PortfolioSetFactory.create(name='set',
                                                   risk_free_rate=0.01,
                                                   asset_classes=asset_classes)
        self.goal = GoalFactory.create(approved_settings=self.goal_settings,
                                       active_settings=self.goal_settings,
                                       cash_balance=100,
                                       portfolio_set=portfolio_set)

        self.tickers = [self.t1, self.t2, self.t3, self.t4, self.t4]
        self.prices = [4, 4, 90, 90, 95]
        self.quantities = [5, 5, 5, 5, 5]
        self.executed = [
            date(2015, 1, 1),
            date(2016, 1, 1),
            date(2015, 1, 1),
            date(2016, 1, 1),
            date(2016, 1, 1)
        ]

        self.execution_details = []
        for i in range(5):
            execution = Fixture1.create_execution_details(
                self.goal, self.tickers[i], self.quantities[i], self.prices[i],
                self.executed[i])
            self.execution_details.append(execution)

        self.data_provider = DataProviderDjango(mocked_now.date())
        self.execution_provider = ExecutionProviderDjango()
        MarkowitzScaleFactory.create()
        self.setup_performance_history()
        self.idata = get_instruments(self.data_provider)

        self.portfolio = PortfolioFactory.create(setting=self.goal_settings)
        self.current_weights = get_held_weights(self.goal)
コード例 #5
0
ファイル: test_rebalance.py プロジェクト: dan0712/django-app
    def setUp(self):
        self.t1 = TickerFactory.create(symbol='SPY', unit_price=5)
        self.t2 = TickerFactory.create(symbol='VEA', unit_price=5)
        self.t3 = TickerFactory.create(symbol='TIP', unit_price=100)
        self.t4 = TickerFactory.create(symbol='IEV', unit_price=100)

        self.equity = AssetFeatureValueFactory.create(
            name='equity', assets=[self.t1, self.t2])
        self.bond = AssetFeatureValueFactory.create(name='bond',
                                                    assets=[self.t3, self.t4])

        self.goal_settings = GoalSettingFactory.create()
        asset_classes = [
            self.t1.asset_class, self.t2.asset_class, self.t3.asset_class,
            self.t4.asset_class
        ]
        portfolio_set = PortfolioSetFactory.create(name='set',
                                                   risk_free_rate=0.01,
                                                   asset_classes=asset_classes)
        self.goal = GoalFactory.create(approved_settings=self.goal_settings,
                                       cash_balance=100,
                                       portfolio_set=portfolio_set)

        Fixture1.create_execution_details(self.goal, self.t1, 5, 4,
                                          date(2016, 1, 1))
        Fixture1.create_execution_details(self.goal, self.t2, 5, 4,
                                          date(2016, 1, 1))
        Fixture1.create_execution_details(self.goal, self.t3, 5, 90,
                                          date(2016, 1, 1))
        Fixture1.create_execution_details(self.goal, self.t4, 5, 90,
                                          date(2016, 1, 1))
        Fixture1.create_execution_details(self.goal, self.t4, 5, 90,
                                          date(2016, 1, 1))

        self.data_provider = DataProviderDjango()
        self.execution_provider = ExecutionProviderDjango()
        MarkowitzScaleFactory.create()
        self.setup_performance_history()
        self.idata = get_instruments(self.data_provider)
コード例 #6
0
    def initialize_backtest(cls, tickers):
        ticker_list = list()
        equity_asset_class = AssetClassFactory\
            .create(name='US_MUNICIPAL_BONDS', investment_type=InvestmentTypeFactory.create(name='US_MUNICIPAL_BONDS'))

        for t in tickers:
            market_index = MarketIndexFactory.create()
            ticker = TickerFactory.create(symbol=t,
                                          asset_class=equity_asset_class,
                                          benchmark=market_index)
            ticker_list.append(ticker)

        portfolio_set = PortfolioSetFactory.create(
            name='portfolio_set1',
            risk_free_rate=0.02,
            asset_classes=[equity_asset_class],
            portfolio_provider=get_default_provider())
        goal_settings = GoalSettingFactory.create(
            target=100000,
            completion=datetime.date(2000, 1, 1),
            hedge_fx=False,
            rebalance=True,
        )
        goal_metric = GoalMetricFactory.create(
            group=goal_settings.metric_group,
            type=GoalMetric.METRIC_TYPE_RISK_SCORE)
        PortfolioFactory.create(setting=goal_settings)
        #GoalMetricGroupFactory.create()

        return GoalFactory.create(account=Fixture1.personal_account1(),
                                  name='goal1',
                                  type=Fixture1.goal_type1(),
                                  cash_balance=10000,
                                  approved_settings=goal_settings,
                                  selected_settings=goal_settings,
                                  active_settings=goal_settings,
                                  portfolio_set=portfolio_set)
コード例 #7
0
    def test_calc_opt_inputs_no_assets_for_constraint(self):
        """
        Makes sure when we have no assets filling a constraint, we behave appropriately.
        """

        # This fund has a different feature to the one in the mix metric, but it is in the correct portfolio set.
        fund1 = TickerFactory.create()
        AssetFeatureValueFactory.create(assets=[fund1])
        ps1 = PortfolioSetFactory.create(asset_classes=[fund1.asset_class])

        # Create a settings object with a metric for a feature with no instruments in the current portfolio set.
        feature = AssetFeatureValueFactory.create()
        settings = GoalSettingFactory.create()
        risk_metric = GoalMetricFactory.create(group=settings.metric_group)
        mix_metric = GoalMetricFactory.create(
            group=settings.metric_group,
            type=GoalMetric.METRIC_TYPE_PORTFOLIO_MIX,
            feature=feature,
            comparison=GoalMetric.METRIC_COMPARISON_MAXIMUM,
            configured_val=.3)
        goal = GoalFactory.create(selected_settings=settings,
                                  portfolio_set=ps1)

        # The below fund has the desired feature, but is not in the goal's portfolio set.
        fund2 = TickerFactory.create()
        feature.assets.add(fund2)

        # Create some instrument data for the two assets
        self.m_scale = MarkowitzScaleFactory.create()
        # populate the data needed for the prediction
        # We need at least 500 days as the cycles go up to 70 days and we need at least 7 cycles.
        populate_prices(500, asof=mocked_now.date())
        populate_cycle_obs(500, asof=mocked_now.date())
        populate_cycle_prediction(asof=mocked_now.date())
        data_provider = DataProviderDjango()
        idata = build_instruments(data_provider)

        execution_provider = ExecutionProviderDjango()

        # Get the opt inputs, there should be no constraint for the max for the feature with no funds.
        result = calc_opt_inputs(settings=settings,
                                 idata=idata,
                                 data_provider=data_provider,
                                 execution_provider=execution_provider)
        xs, lam, constraints, settings_instruments, settings_symbol_ixs, lcovars = result
        self.assertEqual(len(constraints), 3)  # All positive, and sum to 1

        # Then create a fund in the portfolio I want. We should get a constraint for the maximum for the feature.
        fund3 = TickerFactory.create(asset_class=fund1.asset_class)
        feature.assets.add(fund3)
        delete_data()
        populate_prices(500, asof=mocked_now.date())
        populate_cycle_obs(500, asof=mocked_now.date())
        populate_cycle_prediction(asof=mocked_now.date())
        idata = build_instruments(data_provider)
        result = calc_opt_inputs(settings=settings,
                                 idata=idata,
                                 data_provider=data_provider,
                                 execution_provider=execution_provider)
        xs, lam, constraints, settings_instruments, settings_symbol_ixs, lcovars = result
        self.assertEqual(len(constraints),
                         4)  # All positive, sum to 1, and the max constraint