コード例 #1
0
ファイル: stocks.py プロジェクト: samholt/Stock-Analyzer
def add_stock(market, ticker):
    try:
        stock = Stock(market, ticker)
        stock.generate_metrics()
        if stock.data and stock.data['price']:
            stock_list_entry = StockListEntry(market.upper(), ticker.upper())
            db.session.add(stock_list_entry)
            db.session.commit()
        return stock
    except Exception as e:
        logger.error(traceback.format_exc())
コード例 #2
0
ファイル: stocks.py プロジェクト: samholt/Stock-Analyzer
def get_stocks_from_google():
    try:
        stocks = []
        stock_list_entries = StockListEntry.query.all()

        for stock_list_entry in stock_list_entries:
            stock = Stock(stock_list_entry.market, stock_list_entry.ticker)
            stock.generate_metrics()

            for key, value in stock.data.items():
                setattr(stock_list_entry, key, value)

            db.session.commit()
            stocks.append(object_to_dict(stock_list_entry))

        return stocks
    except Exception as e:
        logger.error(traceback.format_exc())
コード例 #3
0
    def test_generate_metrics(self):
        with self.client:
            stock = Stock('NASDAQ', 'AAPL')
            stock.generate_metrics()
            self.assertTrue(stock.data['price'])
            self.assertTrue(stock.data['current_ratio'])
            self.assertTrue(stock.data['quick_ratio'])
            self.assertTrue(stock.data['return_on_equity'])
            self.assertTrue(stock.data['debt_equity_ratio'])
            self.assertTrue(stock.data['net_profit_margin'])
            self.assertTrue(stock.data['free_cash_flow'])
            self.assertTrue(stock.data['price_to_earnings_ratio'])

            stock = Stock('NASDAQ', 'AAPLL')
            stock.generate_metrics()
            self.assertFalse(stock.data)
コード例 #4
0
 def test_price_to_earnings_ratio_success(self):
     with self.client:
         stock = Stock('NASDAQ', 'AAPL')
         self.assertTrue(stock._get_price_to_earnings_ratio())
コード例 #5
0
 def test_free_cash_flow_fail(self):
     with self.client:
         stock = Stock('NASDAQ', 'TSLAA')
         self.assertFalse(stock._compute_free_cash_flow())
コード例 #6
0
 def test_free_cash_flow_success(self):
     with self.client:
         stock = Stock('NASDAQ', 'TSLA')
         self.assertTrue(stock._compute_free_cash_flow())
コード例 #7
0
 def test_net_profit_margin_fail(self):
     with self.client:
         stock = Stock('NASDAQ', 'TSLAA')
         self.assertFalse(stock._compute_net_profit_margin())
コード例 #8
0
 def test_net_profit_margin_success(self):
     with self.client:
         stock = Stock('NASDAQ', 'TSLA')
         self.assertTrue(stock._compute_net_profit_margin())
コード例 #9
0
 def test_debt_equity_ratio_success(self):
     with self.client:
         stock = Stock('NASDAQ', 'TSLA')
         self.assertTrue(stock._compute_debt_equity_ratio())
コード例 #10
0
 def test_debt_equity_ratio_fail(self):
     with self.client:
         stock = Stock('NASDAQ', 'TSLAA')
         self.assertFalse(stock._compute_debt_equity_ratio())
コード例 #11
0
 def test_return_on_equity_fail(self):
     with self.client:
         stock = Stock('NASDAQ', 'TSLAA')
         self.assertFalse(stock._compute_return_on_equity())
コード例 #12
0
 def test_return_on_equity_success(self):
     with self.client:
         stock = Stock('NASDAQ', 'TSLA')
         self.assertTrue(stock._compute_return_on_equity())
コード例 #13
0
 def test_shareholders_equity_fail(self):
     with self.client:
         stock = Stock('NASDAQ', 'TSLAA')
         self.assertFalse(stock._compute_shareholders_equity())
コード例 #14
0
 def test_shareholders_equity_success(self):
     with self.client:
         stock = Stock('NASDAQ', 'TSLA')
         self.assertTrue(stock._compute_shareholders_equity())
コード例 #15
0
 def test_price_to_earnings_ratio_fail(self):
     with self.client:
         stock = Stock('NASDAQ', 'TSLAA')
         self.assertFalse(stock._get_price_to_earnings_ratio())