Exemplo n.º 1
0
def news_stock_analyzer(stock_ticker):
    stock_score = 0
    stock_score += nc.sentiment_analyzer(news.get_news(stock_ticker))
    print(stock_ticker, "news score:", stock_score)
    if stock_score >= 0.35 and stock_ticker not in all_active_positions.keys():
        alpaca.create_order(stock_ticker, 1)  #todo: calculate order amount
        active_positions_to_check[stock_ticker] = sdg.get_current_stock_data(
            stock_ticker)['Close']
        all_active_positions[stock_ticker] = sdg.get_current_stock_data(
            stock_ticker)['Close']
        print("Based on News analysis, buying", stock_ticker)
Exemplo n.º 2
0
def daytrading_stock_analyzer(stocks):
    for stock_ticker in stocks: #purchases stocks based on daytrading patterns
        try:
            stock_score = 0
            stock_score += sa.moving_average_checker(stock_ticker)
            stock_score += sa.volume_checker(stock_ticker)
            if stock_score >= 0.2 and stock_ticker not in all_active_positions.keys():
                alpaca.create_order(stock_ticker, 1) #todo: calculate order amount
                active_positions_to_check[stock_ticker] = sdg.get_current_stock_data(stock_ticker)['Close']
                all_active_positions[stock_ticker] = sdg.get_current_stock_data(stock_ticker)['Close']
                print("Based on daytrading pattern analysis, buying", stock_ticker, "Stock Score: ", stock_score)
        except Exception as e:
            pass
Exemplo n.º 3
0
def moving_average_checker(ticker_symbol) -> int:
   stock_status = sdg.get_current_stock_data(ticker_symbol)
   if stock_status['Close'] > stock_status['EMA'] and stock_status['PREVPRICE'] < stock_status['PREVSMA']:
       return 0.3
   elif stock_status['Close'] < stock_status['SMA'] and stock_status['PREVPRICE'] > stock_status['PREVSMA']:
       return -0.3
   return 0
Exemplo n.º 4
0
def volume_checker(ticker_symbol) -> int:
    stock_status = sdg.get_current_stock_data(ticker_symbol)
    print(ticker_symbol, ": Price: ", sdg.get_price_slope(ticker_symbol)/(0.2*stock_status['Close']), " Volume: ", sdg.get_volume_slope(ticker_symbol)/(0.2*stock_status['Volume']))
    if sdg.get_price_slope(ticker_symbol)/(0.2*stock_status['Close']) > 0.04 and sdg.get_volume_slope(ticker_symbol)/(0.2*stock_status['Volume']) > 1:
        return 0.2
    elif sdg.get_price_slope(ticker_symbol)/(0.2*stock_status['Close']) < -0.03 and sdg.get_volume_slope(ticker_symbol)/(0.2*stock_status['Volume']) > 0.8:
        return -0.2
    return 0
Exemplo n.º 5
0
def check_perform_sell(stock_ticker, purchase_price):
    while True:
        current_stock_price = sdg.get_current_stock_data(stock_ticker)['Close']
        price_change_percent = util.calculate_price_change(current_stock_price, all_active_positions[stock_ticker])
        print("Checking", stock_ticker, "Gains/Losses", price_change_percent, "Price: $", current_stock_price) 
        if sa.moving_average_checker(stock_ticker) < 0 or price_change_percent <= -const.MAX_STOP_LOSS_PERCENT or sa.volume_checker(stock_ticker) < 0:
            alpaca.sell_position(stock_ticker)
            del all_active_positions[stock_ticker]
            break
Exemplo n.º 6
0
def volume_checker(ticker_symbol) -> int:
    stock_status = sdg.get_current_stock_data(ticker_symbol)
    try:
        volume = sdg.get_volume_slope(ticker_symbol) / (0.2 *
                                                        stock_status['Volume'])
    except ZeroDivisionError:
        volume = 0
    try:
        price = sdg.get_price_slope(ticker_symbol) / (0.2 *
                                                      stock_status['Close'])
    except ZeroDivisionError:
        price = 0

    print(ticker_symbol, ": Price: ", price, " Volume: ", volume)
    if price > 0.04 and volume > 1:
        return 0.2
    elif price < -0.03 and volume > 0.8:
        return -0.2
    return 0
import matplotlib.pyplot as plt
import stock_data_gatherer as sdg
import stock_analysis
stock_prices = []
n = 180
ticker = "AAPL"
for i in range(-n,0,1):
    stock_prices.append(sdg.get_historical_data(ticker, "1d", "1m").iloc[i].to_dict()['Volume'])
plt.plot(list(range(n)), stock_prices, 'xb-')
# plt.ylim([130, 134])

print("Price Slope: ", sdg.get_volume_slope(ticker)/(0.2*sdg.get_current_stock_data(ticker)['Volume']))
plt.show()