Skip to content

Commit

Permalink
Rename functions and fix dividend screening
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmoody11 committed Feb 6, 2019
1 parent 22f565b commit d3b9114
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
5 changes: 4 additions & 1 deletion stockscore/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
26 changes: 13 additions & 13 deletions stockscore/scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -147,30 +147,30 @@ 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

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])

0 comments on commit d3b9114

Please sign in to comment.