diff --git a/stockscore/data.py b/stockscore/data.py index a25a36c..8e9ac4f 100644 --- a/stockscore/data.py +++ b/stockscore/data.py @@ -172,7 +172,10 @@ def get_dividends(self, time="5y"): for symbol in batch_dict } data = { - "count": [len(v) for _, v in div_json.items()], + "count": [ + len(v) if all(isinstance(i["amount"], (float)) for i in v) else 0 + for _, v in div_json.items() + ], "amount": [ [div_json[k][i]["amount"] for i in range(len(div_json[k]))] for k, _ in div_json.items() diff --git a/stockscore/scores.py b/stockscore/scores.py index 32ce354..9fc6a04 100644 --- a/stockscore/scores.py +++ b/stockscore/scores.py @@ -24,7 +24,7 @@ def trading_volume_screen(self): if self.volume is None: self.get_volume() self.scores.loc[ - self.volume.latestVolume >= 100000, ["Value Score", "Momentum Score"] + self.volume.latestVolume >= 100_000, ["Value Score", "Momentum Score"] ] += 1 self.scores.loc[ self.volume.latestVolume <= 50000, ["Value Score", "Momentum Score"] @@ -57,7 +57,7 @@ def splits_screen(self, time="1y"): except (ValueError, KeyError): continue - def net_income_test(self): + def net_income_screen(self): # Get data for screen if self.financials is None: self.get_financials() @@ -82,7 +82,7 @@ def net_income_test(self): except (KeyError, TypeError): continue # Skip to next stock if unable to get data - def current_ratio_test(self): + def current_ratio_screen(self): # Get data for screen if self.financials is None: self.get_financials() @@ -119,7 +119,7 @@ def current_ratio_test(self): except (KeyError, TypeError): continue # If current assets and current debt stats are not available, skip to next stock - def p_to_b_test(self): + def p_to_b_screen(self): # Get data for screen if self.stats is None: self.get_stats() @@ -129,7 +129,7 @@ def p_to_b_test(self): ["Value Score"], ] += 1 - def pe_ratio_test(self): + def pe_ratio_screen(self): # Get data for screen if self.stats is None: self.get_stats() @@ -147,18 +147,18 @@ def pe_ratio_test(self): self.scores.loc[self.stats["peRatio"] <= 30, "Value Score"] += 1 self.scores.loc[self.stats["peRatio"] <= 15, "Value Score"] += 1 - def profit_margin_test(self): + def profit_margin_screen(self): if self.stats is None: self.get_stats() self.scores.loc[self.stats["profitMargin"] > 10, "Value Score"] += 1 self.scores.loc[self.stats["profitMargin"] > 20, "Value Score"] += 1 # Needs updating - def dividend_test(self): + def dividend_screen(self): if self.dividends is None: self.get_dividends() # Get data for screen - self.scores.loc[:, "Value Score"] += dividends["count"] // 4 + self.scores.loc[:, "Value Score"] += self.dividends["count"] // 4 # Need to account for monthly dividend stocks (add max function to exclude # monthly dividend payers from being disproportionately rewarded @@ -166,11 +166,11 @@ def score(self): self.moving_avg_screen() self.trading_volume_screen() self.splits_screen() - self.net_income_test() - self.current_ratio_test() - self.p_to_b_test() - self.pe_ratio_test() - self.profit_margin_test() + self.net_income_screen() + self.current_ratio_screen() + self.p_to_b_screen() + self.pe_ratio_screen() + self.profit_margin_screen() _scores = ["Value Score", "Growth Score", "Momentum Score"] self.scores["Score"] = sum([self.scores[_score] for _score in _scores])