Exemplo n.º 1
0
                     saveName='earningDiff',
                     hlines=[],
                     title='earningDiff')
            MakePlot(merged_stock_earn['e_over_p_diff'],
                     merged_stock_earn[j],
                     xname='e_over_p_diff',
                     yname=j,
                     saveName='e_over_p_diff',
                     hlines=[],
                     title='e_over_p_diff')
    return merged_stock_earn


# collecting spy
sqlcursor = SQL_CURSOR()
ts = ALPHA_TIMESERIES()
j = 0

# reading in the spy data
spy, j = ConfigTable('SPY', sqlcursor, ts, readType, hoursdelay=2)
AddInfo(spy, spy, debug=debug)

# processing new earnings
connectionCal = SQL_CURSOR('earningsCalendar.db')
connectionCalv2 = SQL_CURSOR('earningsCalendarForTraining.db')
fd = ALPHA_FundamentalData()
my_3month_calendar = GetUpcomingEarnings(fd, ReDownload)
print(my_3month_calendar)
it = 0
preLoaded = []
if not ReDownload:
Exemplo n.º 2
0
def GenerateSignal(ticker,
                   out_file_name='out_bull_instructions.csv',
                   price_targets=[]):
    connectionCal = SQL_CURSOR('earningsCalendarv2.db')
    fd = ALPHA_FundamentalData()
    sqlcursor = SQL_CURSOR()
    ts = ALPHA_TIMESERIES()
    api = ALPACA_REST()

    stockInfoQuarter, stockInfoAnnual, company_overview = CollectEarnings(
        ticker, connectionCal)

    # annual balance sheet
    balance_sheet_annual = fd.get_balance_sheet_annual(ticker)[0]
    balance_sheet_annual['fiscalDateEnding'] = pd.to_datetime(
        balance_sheet_annual['fiscalDateEnding'], errors='coerce')
    for d in balance_sheet_annual.columns:
        if d not in ['fiscalDateEnding', 'totalAssets']:
            balance_sheet_annual[d] = pd.to_numeric(balance_sheet_annual[d],
                                                    errors='coerce')
    # quarterly income statement
    income_statement_quarterly = fd.get_income_statement_quarterly(ticker)[0]
    for d in income_statement_quarterly.columns:
        if d not in ['fiscalDateEnding', 'reportedCurrency']:
            income_statement_quarterly[d] = pd.to_numeric(
                income_statement_quarterly[d], errors='coerce')
    for d in ['fiscalDateEnding']:
        income_statement_quarterly[d] = pd.to_datetime(
            income_statement_quarterly[d], errors='coerce')
    if debug:
        print(income_statement_quarterly)
        print(income_statement_quarterly.dtypes)

    tstock_info, j = ConfigTable(ticker, sqlcursor, ts, 'full')
    spy, j = ConfigTable('SPY', sqlcursor, ts, 'compact')
    #print(spy.columns)
    est = pytz.timezone('US/Eastern')
    today = datetime.now(tz=est) + maindatetime.timedelta(minutes=-40)
    #today = datetime.utcnow() + maindatetime.timedelta(minutes=-30)
    d1 = today.strftime("%Y-%m-%dT%H:%M:%S-04:00")
    five_days = (
        today +
        maindatetime.timedelta(days=-7)).strftime("%Y-%m-%dT%H:%M:%S-04:00")
    minute_prices = []
    ntry = 0
    while ntry < 3:
        try:
            minute_prices = runTicker(api,
                                      ticker,
                                      timeframe=TimeFrame.Minute,
                                      start=five_days,
                                      end=d1)
            break
        except (requests.exceptions.ConnectionError):
            ntry += 1
    # may want to restrict to NYSE open times
    try:
        spy = AddInfo(spy, spy)
        tstock_info = AddInfo(tstock_info, spy, AddSupport=True)
    except (ValueError, KeyError):
        print('Error processing adding info %s' % ticker)

    recent_quotes = getQuotes(api, ticker)
    if debug:
        print(tstock_info[[
            'adj_close', 'sma20', 'sma20cen', 'vwap10cen', 'vwap10'
        ]][50:-10])
    earn = Earnings(ticker, income_statement_quarterly, company_overview,
                    balance_sheet_annual, stockInfoQuarter, stockInfoAnnual,
                    tstock_info, minute_prices, recent_quotes)
    #earn.BuildPDF()
    earn.WriteCSV(out_file_name, price_targets)