Randomize similar companies before selecting 10 for analysis

This is for the case when more than 10 similar companies
are available. This allows getting better representation compared to
always getting the first 10 similar companies from the list that's
ordered alphabetically
This commit is contained in:
Theodore Aptekarev
2021-04-13 13:20:05 +03:00
parent dff7ef69a3
commit 85e19c1c7e

View File

@@ -3,6 +3,7 @@ __docformat__ = "numpy"
import argparse
import requests
import random
from typing import List
from datetime import datetime
import pandas as pd
@@ -172,9 +173,11 @@ class ComparisonAnalysisController:
if len(self.similar) > 10:
print(
"\nThe limit of stocks to compare with are 10. Hence, the similar stocks list will be:"
"\nThe limit of stocks to compare with are 10. Hence, 10 random similar stocks will be displayed.",
"\nThe selected list will be:"
)
self.similar = self.similar[:10]
random.shuffle(self.similar)
self.similar = sorted(self.similar[:10])
print(", ".join(self.similar))
except Exception as e: