Exemplo n.º 1
0
def stocks_all():
    listOfStocks = lst.main('nasdaq/nasdaq_result_list.csv')
    exceptionDF = pd.read_csv('nasdaq/exceptionList.csv',
                              sep=',',
                              header=0,
                              engine='python')

    stock_df = pd.DataFrame(listOfStocks)

    stock_df_wo_rating = pd.merge(stock_df,
                                  exceptionDF,
                                  how='inner',
                                  on=['Symbol', 'Symbol'])
    print("stock_df shpe: ", stock_df.shape)
    print("shape: ", stock_df_wo_rating.shape)

    stock_df = pd.concat([stock_df, stock_df_wo_rating,
                          stock_df_wo_rating]).drop_duplicates(keep=False)

    print("stock_df shpe: ", stock_df.shape)

    stock_df.insert(2, "Market", "NASDAQ", True)

    response = stock_df.to_json(orient='records')
    return Response(response, mimetype='text/plain')
Exemplo n.º 2
0
def getStockSector(stock_symbol):
    listOfStocks = lst.main('nasdaq/nasdaq_result_list.csv')
    print(listOfStocks['Sector'].unique())
    df = listOfStocks.loc[listOfStocks['Symbol'] == stock_symbol]
    response = df.to_json(orient='records')

    return Response(response, mimetype='text/plain')
Exemplo n.º 3
0
def listOfStocks():
    listOfStocks = lst.main('nasdaq/nasdaq_result_list.csv')
    listOfStocks_res = listOfStocks['Symbol'] + ': ' + listOfStocks[
        'Security Name'].map(lambda x: x.split('-')[0].strip())
    print(listOfStocks[0:5])
    response = listOfStocks_res.to_json()
    return Response(response, mimetype='text/plain')
Exemplo n.º 4
0
def getRecommendationList_Test(stock_symbol):
    listOfStocks = lst.main('nasdaq/nasdaq_result_list.csv')
    RatingList = ['BUY', 'SELL', 'HOLD']
    stock_df = pd.DataFrame(
        columns=['seq', 'stockSymbol', 'stockName', 'sector', 'rating'])

    for x in range(0, 5):
        randomRow = random.randint(1, len(listOfStocks))
        randomRating = random.randint(0, 2)
        print(
            'reco: ', randomRow, randomRating, RatingList[randomRating],
            ('' if isNaN(listOfStocks.iloc[randomRow, 1]) else
             listOfStocks.iloc[randomRow, 1].tostring().split('-')[0].strip()),
            listOfStocks.iloc[randomRow, 2])
        stock_df = stock_df.append(
            {
                'seq':
                x + 1,
                'stockSymbol':
                listOfStocks.iloc[randomRow, 0],
                'stockName':
                ('' if isNaN(listOfStocks.iloc[randomRow, 1]) else
                 listOfStocks.iloc[randomRow, 1].split('-')[0].strip()),
                'sector': ('' if isNaN(listOfStocks.iloc[randomRow, 2]) else
                           listOfStocks.iloc[randomRow, 2]),
                'rating':
                RatingList[randomRating]
            },
            ignore_index=True)

    response = stock_df.to_json(orient='records')
    return Response(response, mimetype='text/plain')
def stock_list_t(stockFirstChar):
    listOfStocks = lst.main('nasdaq/nasdaq_result_list.csv')['Symbol'].tolist()
    exceptionDF = pd.read_csv('nasdaq/exceptionList.csv',
                              sep=',',
                              header=0,
                              engine='python')
    exceptionList = exceptionDF['Symbol'].tolist()

    relevantStocks = []

    # input is a stock symbol and not starting character
    if len(stockFirstChar) > 1:
        relevantStocks = [stockFirstChar]

    if stockFirstChar.isalnum():
        for item in listOfStocks:
            if item[0].lower() == stockFirstChar and item not in exceptionList:
                relevantStocks.append(item)
    else:
        for item in listOfStocks:
            if not item[0].isalpha() and item not in exceptionList:
                relevantStocks.append(item)
    return relevantStocks
Exemplo n.º 6
0
def getRecommendationList(stock_symbol):
    listOfStocks = lst.main('nasdaq/nasdaq_result_list.csv')
    listOfStocks.set_index('Symbol', inplace=True)

    # print(listOfStocks.head(5))
    recoDF = reco.main(stock_symbol)
    recoList = recoDF['Symbol'].values.tolist()

    xrow = listOfStocks.index.isin(recoList)
    nasdaqDF = listOfStocks[xrow]

    # print(nasdaqDF.head(5))

    ratingDict = {-1: 'SELL', 0: 'HOLD', 1: 'BUY'}

    stock_df = pd.DataFrame(
        columns=['seq', 'stockSymbol', 'stockName', 'sector', 'rating'])

    stock_df['stockSymbol'] = recoDF['Symbol']
    stock_df['rating'] = recoDF['analyst_rating'].map(lambda x: ratingDict[x])
    stock_df['stockName'] = nasdaqDF['Security Name'].map(
        lambda x: x.split('-')[0].strip())
    stock_df['sector'] = nasdaqDF['Sector']

    stock_df.reset_index(level=None,
                         drop=False,
                         inplace=True,
                         col_level=0,
                         col_fill='')

    stock_df['seq'] = stock_df.index

    print(stock_df.head(5))

    response = stock_df.to_json(orient='records')
    return Response(response, mimetype='text/plain')