def test_calculate_portfolio(self):
     goal1 = Fixture1.goal1()
     goal1.portfolio_set.asset_classes = [
         AssetClass.objects.get(name="US_BONDS"),
         AssetClass.objects.get(name="AU_STOCKS"),
         AssetClass.objects.get(name="AU_STOCK_MUTUALS")
     ]
     goal1.selected_settings.metric_group.metrics = [GoalMetric.objects.create(group=Fixture1.metric_group1(),
                                                                               type=GoalMetric.METRIC_TYPE_RISK_SCORE,
                                                                               rebalance_type="1",
                                                                               configured_val=0.0,
                                                                               comparison=2,
                                                                               rebalance_thr=0.05)
                                                    ]
     goal1.selected_settings.SYSTEM_CURRENCY = 'USD'
     goal1.cash_balance = 1000
     idata = get_instruments(self._data_provider)
     portfolio, er, var = calculate_portfolio(settings=goal1.selected_settings,
                                              data_provider=self._data_provider,
                                              execution_provider=self._execution_provider,
                                              idata=idata)
     self.assertEqual(len(portfolio), 4)
 def test_calculate_portfolios(self):
     goal1 = Fixture1.goal1()
     goal1.portfolio_set.asset_classes = [
         AssetClass.objects.get(name="US_BONDS"),
         AssetClass.objects.get(name="AU_STOCKS"),
         AssetClass.objects.get(name="AU_STOCK_MUTUALS")
     ]
     goal1.selected_settings.metric_group.metrics = [GoalMetric.objects.create(group=Fixture1.metric_group1(),
                                                                               type=GoalMetric.METRIC_TYPE_RISK_SCORE,
                                                                               rebalance_type="1",
                                                                               configured_val=0.0,
                                                                               comparison=2,
                                                                               rebalance_thr=0.05)
                                                    ]
     goal1.selected_settings.SYSTEM_CURRENCY = 'USD'
     goal1.cash_balance = 1000
     portfolio = Portfolio.objects.create(id=1, er=1, stdev=2, setting=goal1.selected_settings)
     PortfolioItem.objects.create(asset=Ticker.objects.get(symbol='ASS'),
                                  portfolio=portfolio,
                                  weight=0.1,
                                  volatility=0.2)
     portfolios = calculate_portfolios(goal1.selected_settings, data_provider=self._data_provider,
                                       execution_provider=self._execution_provider)
     self.assertEqual(len(portfolios), 101)