Exemplo n.º 1
0
def screen(tickerName):
    getData = GetData.getData(tickerName)
    f = Ratios.TickerFundamentals(tickerName, getData)
    fcfNow, fcfAvg, value, valueAvg = Value.getValue(tickerName, getData)
    debtToAssets = f.getDebt()
    goodwill = f.getGoodwill()
    ROIC = f.getROIC()[1][0]
    todaysPrice = HistoricalPrices.getTodaysPriceOffline(tickerName)
    price_thresholdBuy = todaysPrice + (todaysPrice) * .20

    if (value[0] > price_thresholdBuy):
        if (debtToAssets > 0.75):
            print("Debt is very high")
        if (goodwill > .5):
            print("Goodwill very high")
        print(tickerName + " - buy signal")
        print("Todays Price = " + str(todaysPrice))
        print("ROIC = " + str(ROIC))
        print("FCF Now : " + "{:,}".format(fcfNow))
        print("FCF 3yr Avg : " + "{:,}".format(fcfAvg))
        print("Value : " + str(value))
        print("Value Avg : " + str(valueAvg))
        print("")
        return True
Exemplo n.º 2
0
def exactEarnings(tickerName, quarterlyDates):
    exactDates = []
    zacksWebsite = "https://www.zacks.com/stock/research/" + tickerName + "/earnings-announcements"

    tempWebFile = request.urlopen(zacksWebsite).read()
    tempData = BeautifulSoup(tempWebFile, "lxml")
    html = tempData.prettify()

    lines = tempData.find_all('script')
    keyword = 'document.obj_data ='
    keyword1 = '"earnings_announcements_earnings_table"'
    keyword2 = '"earnings_announcements_webcasts_table"'

    #     '''Will get SQL data too '''
    #     sqlData = sql.getData(tickerName)

    #     for i in sqlData:
    #         print(i)
    """Get exact earnings dates from Zack's research """
    for i in lines:
        #         print(i)
        stringTemp = str(i)
        keywordIndex = stringTemp.find(keyword)

        payload = ''

        if (keywordIndex > -1):
            stringTemp = stringTemp[keywordIndex:]
            keywordIndex1 = stringTemp.find(keyword1)
            keywordIndex2 = stringTemp.find(keyword2)

            payload = stringTemp[keywordIndex1 + len(keyword1) +
                                 4:keywordIndex2]
            """Get string with dates. """
            k = 0
            while (payload[k] != '['):
                k += 1

            payload = payload[k + 1:]

            lastBracket = ''
            for k in range(0, len(payload)):
                if (payload[k] == ']' and lastBracket == ']'):
                    payload = payload[:k].strip()
                    break

                if (payload[k] == ']'):
                    lastBracket = ']'
                elif (payload[k] == '['):
                    lastBracket = '['
            break

    dates = payload.split(',')

    for i in dates:
        i = i.replace('"', '')
        i = i.replace('[', '')
        i = i.replace(']', '')
        i = i.strip()

        split = i.split('/')
        """Dates are in format : MM/DD/YYYY"""

        if (len(split) > 2):
            """Dates are reformatted : YYYY/MM/DD """
            newDate = str(split[2]) + '/' + str(split[0]) + '/' + str(split[1])
            exactDates.append(newDate)

    if (len(exactDates) < 1):
        return None

    if ('dates' in quarterlyDates):
        quarterlyDates.remove('dates')
    elif ('dates-adj' in quarterlyDates):
        quarterlyDates.remove('dates-adj')

    adjustedDates = adjustedDate(quarterlyDates)[1:]
    """Make sure exactDates matches with adjusted earnings data. Compare exact dates to adjusted dates by making a 2 month window """
    """Initially append exact date for later insertion into sql """
    exactDatesAppend = []

    for i in exactDates:
        #         print('i = ' + i)
        temp = i.split('/')
        exactDate = []
        exactDate.append(float(temp[0]))
        exactDate.append(float(temp[1]))
        exactDate.append(float(temp[2]))

        for j in adjustedDates:
            temp = j.split('/')
            adjDate = []
            adjDate.append(float(temp[0]))
            adjDate.append(float(temp[1]))
            adjDate.append(float(temp[2]))
            """Create a 2 month window for exact date"""
            """ YYYY/MM/DD """
            left = exactDate[1] - 1
            right = exactDate[1] + 1
            year_left = exactDate[0]
            year_right = exactDate[0]

            if (left < 1):
                year_left -= 2
                left += 12
            elif (right > 12):
                year_right += 2
                right -= 12

            if (year_right == adjDate[0]):

                if (left > right):
                    if ((left <= adjDate[1] and adjDate[1] <= 12)
                            or (1 <= adjDate[1] and adjDate[1] <= right)):
                        #                         print(str(left) + " : " + str(right) + ' : ' + str(year_left) + ' : ' + str(year_right))
                        #                         print(adjDate)
                        exactDatesAppend.append(i)
                        continue
                else:
                    if (left <= adjDate[1] and adjDate[1] <= right):
                        #                         print(str(left) + " : " + str(right) + ' : ' + str(year_left) + ' : ' + str(year_right))
                        #                         print(adjDate)
                        exactDatesAppend.append(i)
                        continue

#     print(exactDates)
    """Data from Zacks may skip a date. If date is skipped, make sure to estimate date """
    start = 0
    end = len(exactDatesAppend)
    #     print(exactDatesAppend)
    missing = []
    """This year"""
    todaysDate = Utility.getTodaysDate().split('/')
    todaysYear = round(float(todaysDate[2]))
    todaysMonth = round(float(todaysDate[0]))
    """ Previous year in loop"""
    previousYear = todaysYear
    """quaterly date template """
    template = []
    four = 0
    """Goes through each date. If exactYear = todaysYear skip. Otherwise see if 
    there are 4 entries per year for quarterly dates. Also first full year is made
    as template. First get template for year """
    for i in exactDatesAppend:
        exactYear = round(float(i.split('/')[0]))
        if (exactYear == todaysYear):
            previousYear = todaysYear - 1
            start += 1
            continue

        if (exactYear != previousYear):
            #             print('difference')
            #             print(four)
            if (four == 4 and len(template) == 0 and start >= 4):
                template.append(exactDatesAppend[start - 1].split('/'))
                template.append(exactDatesAppend[start - 2].split('/'))
                template.append(exactDatesAppend[start - 3].split('/'))
                template.append(exactDatesAppend[start - 4].split('/'))
                break
            four = 0
        previousYear = exactYear
        start += 1
        four += 1

    four, start = 0, 0
    """Go through loop all over again and this time plug in missing dates 
    One thing that I may have to add later is to check if current year dates exist. """
    four, start = 0, 0
    while (start < len(exactDatesAppend)):
        exactYear = round(float(exactDatesAppend[start].split('/')[0]))
        #     print(exactDatesAppend[start])
        if (exactYear == todaysYear):
            previousYear = todaysYear - 1
            start += 1
            continue

        if (exactYear != previousYear):
            #         print(start)
            #         print(four)
            if (four < 4):
                for back in range(0, 4):
                    index = start - (back + 1)
                    #                 print(index)
                    check = exactDatesAppend[index].split('/')
                    checkMonth = float(check[1])
                    templateMonth = float(template[back][1])
                    if (templateMonth - 2 <= checkMonth
                            and checkMonth <= templateMonth + 2):
                        #                     print('ok')
                        pass
                    else:
                        #                         print(str(exactYear + 1) + '/' + template[back][1] + '/' + template[back][2])
                        exactDatesAppend.insert(
                            index + 1,
                            str(exactYear + 1) + '/' + template[back][1] +
                            '/' + template[back][2])
                        start += 1

            four = 0
        previousYear = exactYear
        start += 1
        four += 1
# #     print(todaysYear)
#     exactYear = round(float(exactDatesAppend[start].split('/')[0]))
#     while(exactYear != todaysYear):

#     for i in range(0, 4):
#         date = exactDatesAppend[i].split('/')
#         year = round(float(date[0]) - 1)
#         day = float(date[2])
#         month = float(date[1])   #month
#         start = i + 4
#
#         print('date = ' + str(date))
#         while(start < end):
#             date2 = exactDatesAppend[start].split('/')
# #             print(date2)
#             month2 = float(date2[1]) #month
#             print('date2 = ' + str(date2))
#             if(month2 - 2 <= month and month <= month2 + 2):
#                 pass
#             else:
#                 temp.append([start, str(year) + '/' + str(round(month)) + '/' + str(round(day))])
# #                 exactDatesAppend.insert(start, str(year) + '/' + str(round(month)) + '/' + str(round(day)))
#
#             start += 4
#             year -= 1

#     count = 0
#     for i in exactDatesAppend:
#         print(i + " : " + str(count))
#         count += 1
#     print(temp)
    """ExactDatesAppend from zacks research may not cover EPS data from stockrow. In this case, estimate past
    dates and add to exactDatesAppend """
    #     print(exactDatesAppend)
    index = len(exactDatesAppend)
    oldLength = len(exactDatesAppend)
    while (index < len(adjustedDates)):
        index += 1
        exactDatesAppend.append('')
#         print(exactDatesAppend)

#     for i in range(0,len(exactDatesAppend)):
#         print(str(i) + ' ' + exactDatesAppend[i])
#
    """For each quater, estimate date and then add into exact date """
    for i in range(0, 4):
        start = i

        while (start < oldLength):
            date = exactDatesAppend[start].split('/')
            year = round(float(date[0]) - 1)  #year
            month = date[1]  #month
            day = date[2]  #day

            start += 4

#         print(month)
#         print(day)

#         print(start)
        while (start < len(exactDatesAppend)):
            exactDatesAppend[start] = str(year) + '/' + month + '/' + day
            year -= 1
            start += 4


#     print()
    try:
        prices = getHistoricalPrices(tickerName, exactDatesAppend, 'll')
    except:
        historicalPrices.updateHistoricalPrice(tickerName)
        prices = getHistoricalPrices(tickerName, exactDatesAppend, 'll')

    prices[0].insert(0, 'Exact Date')

    return prices