コード例 #1
0
def svmr(stock_sym):
    predicted_y_high = analyzer.analyzeSymbol(stock_sym)
    long_svm_int = get_svm_prediction(stock_sym, predicted_y_high)
    if (long_svm_int == +1):
        long_svm = "strong"
    else:
        long_svm = "weak"
        # Get 50 day MACD and compare with ANN prediction
    long_macd = MACD.get_macd(stock_sym)
    if (long_macd < predicted_y_high):
        long_macd = "rising"
        print("BUY")
    else:
        long_macd = "falling"
        print("SELL")
    return predicted_y_high, long_macd, long_svm
コード例 #2
0
def training(variable):

    key1 = analyzeSymbol(variable)

    #key1 = dbtojsonfunction("abcd") # Use this to print graph in abcd.html inorder to print predict price and actual price
    #key1 = dbtojsonfunction("abcd") # Use this to print graph in bank.html
    #key1 = dbtojsonfunction("sanimabank") # Use this For stockanalysis.html
    #

    con = sql.connect("EBL.db")
    cur = con.cursor()

    cur.execute("SELECT * FROM {} ".format(variable, ))
    individualdata = cur.fetchall()
    #name = cur.fetchall()

    #return render_template(os.path.join(path+'.html'), key1=key1, key2 = key2)
    return render_template('training.html',
                           variable=variable,
                           individualdata=individualdata)
コード例 #3
0
def apiAnalyze(stockSymbol):
    return json.dumps(analyzeSymbol(stockSymbol))
コード例 #4
0
comp_ticker = {"google": "GOOG", "apple": "AAPL"}

while True:
	for mention in mentions:
		tw = mention.text
		_, cmd, comp = tw.split(' ')

		print tw
		print cmd, comp
		print mention.user.screen_name

		comp = comp.lower()
		ticker = comp_ticker.get(comp, None)

		price, coef = analyzer.analyzeSymbol(ticker)
		market_fear = finance_scrape.get_fear_score(ticker)

		print (price, coef, market_fear)

		api.update_status(
			"Hello @{}! I think that the {} stock will be at {:.2f} tomorrow - With a Confidence of {:.2f}% and a Bear ratio of {}".format(
				mention.user.screen_name, comp.title(), price, 100 * coef, market_fear))
		
		exit(0)



def getCompanymmand(phrase):
    temp = phrase.split(' ')
    command = temp[0].lower()
コード例 #5
0
def apiAnalyze(stockSymbol):
    return json.dumps(analyzeSymbol(stockSymbol))
コード例 #6
0
def myprofile():
    if request.cookies.get('login'):
        username = str(request.cookies.get('login').split('_')[0])
    else:
        return redirect('http://127.0.0.1:5000/client/login')
    cursor.execute("SELECT favorite_stock FROM login_info WHERE user_name = '{username}'".format(username=username))
    focused_stock = str(cursor.fetchone()[0]).encode("utf-8")
    cnx.commit()
    try:
        data_types = [
            'High',
            'Low',
            'Close',
            'Volume',
            'Adj Close',
        ]
        stockname = focused_stock
        # stockname = request.args.get('chart_title')
        window = 50
        window2 = 150

        recent_trend_query = """
         SELECT Date, `{__value_name__}`
         FROM seproject.historicaldata
         where sym = '{__stockname__}'
         order by Date ASC;
         """
        move_avg_query = """
         SELECT seproject.historicaldata.Date, seproject.historicaldata.`{__value_name__}`, avg(historicaldata_past.`{__value_name__}`) as `{__value_name__}_window`
         FROM seproject.historicaldata
         JOIN (
             SELECT
             seproject.historicaldata.Date, seproject.historicaldata.`{__value_name__}`
             FROM seproject.historicaldata
             WHERE seproject.historicaldata.sym = '{__stockname__}'
         ) AS historicaldata_past 
           ON seproject.historicaldata.Date BETWEEN  historicaldata_past.Date and date_add(historicaldata_past.Date, interval + {__window__} day)
         WHERE seproject.historicaldata.sym = '{__stockname__}'
         GROUP BY 1, 2
         order by seproject.historicaldata.Date ASC;
         """
        rt_price = """
         SELECT price 
         FROM seproject.realtimedata
         WHERE sym = '{__stockname__}'
         """
        stock_symb = [
            'AAPL',
            'GOOGL',
            'NVDA',
            'YHOO',
            'AMZN',
            'MSFT',
            'BAC',
            'NKE',
            'NFLX',
            'FB',
        ]

        pred_price = round(analyzeSymbol(stockname, 5), 2)
        pred_price1 = round(analyzeSymbol(stockname, 50), 2)
        RSI = tuple(getRSI(stockname))

        q_results = db.engine.execute(rt_price.format(__stockname__=stockname))
        # d = json.dumps(q_results)
        for res in q_results:
            chart_data = res[0]

        rt_price1 = chart_data
        rec_BS_A = ['BUY', 'SELL', 'HOLD']
        if float(rt_price1) * (0.99) > pred_price:
            rec_BS = rec_BS_A[1]
        elif float(rt_price1) * (1.01) < pred_price:
            rec_BS = rec_BS_A[0]
        else:
            rec_BS = rec_BS_A[2]

        if float(rt_price1) * (0.99) > pred_price1:
            rec_BS1 = rec_BS_A[1]
        elif float(rt_price1) * (1.01) < pred_price1:
            rec_BS1 = rec_BS_A[0]
        else:
            rec_BS1 = rec_BS_A[2]

        rss_url = "//rss.bloople.net/?url=https%3A%2F%2Fwww.google.com%2Ffinance%2Fcompany_news%3Fq%3DNASDAQ%3A" + stockname + "%26ei%3DXt77WInNHZLteNzahsAC%26output%3Drss&detail=-1&showtitle=false&type=js"
        chart_data_all = {}
        chart_data_all_sec = {}
        chart_data_all_th = {}
        chart_data_all_fth = {}

        for data_type in data_types:
            q_results = db.engine.execute(recent_trend_query.format(__stockname__=stockname, __value_name__=data_type))
            chart_values = []
            for result in q_results:
                unixtime = time.mktime(result[0].timetuple()) * 1000
                chart_values.append([unixtime, result[1]])
            chart_data_all[data_type] = chart_values

            q_results = db.engine.execute(
                move_avg_query.format(__stockname__=stockname, __value_name__=data_type, __window__=window))
            chart_values = []
            for result in q_results:
                unixtime = time.mktime(result[0].timetuple()) * 1000
                chart_values.append([unixtime, result[2]])
            chart_data_all_sec[data_type] = chart_values

            q_results = db.engine.execute(
                move_avg_query.format(__stockname__=stockname, __value_name__=data_type, __window__=window2))
            chart_values = []
            chart_values1 = []
            i = 0;
            for result in q_results:
                unixtime = time.mktime(result[0].timetuple()) * 1000
                chart_values.append([unixtime, result[2]])
                chart_values1.append([unixtime, RSI[i]])
                i = i + 1
            chart_data_all_th[data_type] = chart_values
            chart_data_all_fth[data_type] = chart_values1

        return render_template("myprofile.html",stock=focused_stock, chart_title=stockname,
                                   chart_data_all=chart_data_all, chart_data_all_sec=chart_data_all_sec,
                                   chart_data_all_th=chart_data_all_th, data_types=data_types,
                                   window=window, window2=window2, rt_price=rt_price1,
                                   pred_price=pred_price, rec_BS=rec_BS, pred_price1=pred_price1, rec_BS1=rec_BS1,
                                   stock_symb=stock_symb, rss_url=rss_url, chart_data_all_fth=chart_data_all_fth)
    except IndexError:
    	return render_template("myprofile.html")
コード例 #7
0
def stock():
    data_types = [
        'High',
        'Low',
        'Close',
        'Volume',
        'Adj Close',
    ]
    stockname = request.args.get('stock_name')
    #stockname = request.args.get('chart_title')
    window = 50
    window2 = 150
 



    recent_trend_query = """
    SELECT Date, `{__value_name__}`
    FROM seproject.historicaldata
    where sym = '{__stockname__}'
    order by Date ASC;
    """
    move_avg_query = """
    SELECT seproject.historicaldata.Date, seproject.historicaldata.`{__value_name__}`, avg(historicaldata_past.`{__value_name__}`) as `{__value_name__}_window`
    FROM seproject.historicaldata
    JOIN (
        SELECT
        seproject.historicaldata.Date, seproject.historicaldata.`{__value_name__}`
        FROM seproject.historicaldata
        WHERE seproject.historicaldata.sym = '{__stockname__}'
    ) AS historicaldata_past 
      ON seproject.historicaldata.Date BETWEEN  historicaldata_past.Date and date_add(historicaldata_past.Date, interval + {__window__} day)
    WHERE seproject.historicaldata.sym = '{__stockname__}'
    GROUP BY 1, 2
    order by seproject.historicaldata.Date ASC;
    """
    rt_price = """
    SELECT price 
    FROM seproject.realtimedata
    WHERE sym = '{__stockname__}'
    """
    stock_symb = [
     'AAPL',
     'GOOGL',
     'NVDA',
     'YHOO',
     'AMZN',
     'MSFT',
     'BAC',
     'NKE',
     'NFLX',
     'SNAP',
    ]
    
    pred_price = round(analyzeSymbol(stockname, 5),2)
    pred_price1 = round(analyzeSymbol(stockname, 50),2)

    # get Bayesian Prediction
    filename = stockname + '_histdata.csv'
    returnBayesianPrice = getBayesianCurveFit('./', filename, '3', '0')

    # get SVM prediction
    returnSVM = SVMpredict(stockname)  # get Bayesian Prediction

    RSI = tuple(getRSI(stockname))

    q_results = db.engine.execute(rt_price.format(__stockname__=stockname))
    #d = json.dumps(q_results)
    for res in q_results:
        chart_data = res[0]
        
    rt_price1 = chart_data
    rec_BS_A = ['BUY','SELL','HOLD']
    if float(rt_price1)*(0.99) > pred_price:
        rec_BS = rec_BS_A[1]
    elif float(rt_price1)*(1.01) < pred_price:
        rec_BS = rec_BS_A[0]
    else:
        rec_BS = rec_BS_A[2] 

    if float(rt_price1)*(0.99) > pred_price1:
        rec_BS1 = rec_BS_A[1]
    elif float(rt_price1)*(1.01) < pred_price1:
        rec_BS1 = rec_BS_A[0]
    else:
        rec_BS1 = rec_BS_A[2] 

    rss_url = "//rss.bloople.net/?url=https%3A%2F%2Fwww.google.com%2Ffinance%2Fcompany_news%3Fq%3DNASDAQ%3A"+stockname+"%26ei%3DXt77WInNHZLteNzahsAC%26output%3Drss&detail=-1&showtitle=false&type=js"
    chart_data_all = {}
    chart_data_all_sec = {}
    chart_data_all_th = {}
    chart_data_all_fth = {}


    for data_type in data_types:
        q_results = db.engine.execute(recent_trend_query.format(__stockname__=stockname, __value_name__=data_type))
        chart_values = []
        for result in q_results:
            unixtime = time.mktime(result[0].timetuple()) * 1000
            chart_values.append([unixtime, result[1]])
        chart_data_all[data_type] = chart_values

        q_results = db.engine.execute(move_avg_query.format(__stockname__=stockname, __value_name__=data_type, __window__=window))
        chart_values = []
        for result in q_results:
            unixtime = time.mktime(result[0].timetuple()) * 1000
            chart_values.append([unixtime, result[2]])
        chart_data_all_sec[data_type] = chart_values

        q_results = db.engine.execute(move_avg_query.format(__stockname__=stockname, __value_name__=data_type, __window__=window2))
        chart_values = []
        chart_values1 = []
        i = 0;
        for result in q_results:
            unixtime = time.mktime(result[0].timetuple()) * 1000
            chart_values.append([unixtime, result[2]])
            chart_values1.append([unixtime, RSI[i]])
            i = i + 1
        chart_data_all_th[data_type] = chart_values
        chart_data_all_fth[data_type] = chart_values1
    

    if request.cookies.get('login'):
        return render_template("stockselect.html", display='true',chart_title=stockname, 
            chart_data_all=chart_data_all, chart_data_all_sec=chart_data_all_sec,
            chart_data_all_th=chart_data_all_th, data_types=data_types, 
            window=window, window2= window2,  rt_price= rt_price1, 
            pred_price = pred_price, rec_BS = rec_BS, pred_price1 = pred_price1, rec_BS1 = rec_BS1, stock_symb = stock_symb,rss_url=rss_url, chart_data_all_fth = chart_data_all_fth, stock=stockname, pred_Bayesian=returnBayesianPrice,pred_SVM=returnSVM )
    else:
        return render_template("stockselect.html", display='false',chart_title=stockname, 
            chart_data_all=chart_data_all, chart_data_all_sec=chart_data_all_sec,
            chart_data_all_th=chart_data_all_th, data_types=data_types, 
            window=window, window2= window2,  rt_price= rt_price1, 
            pred_price = pred_price, rec_BS = rec_BS, pred_price1 = pred_price1, rec_BS1 = rec_BS1, stock_symb = stock_symb,rss_url=rss_url, chart_data_all_fth = chart_data_all_fth, stock=stockname, pred_Bayesian=returnBayesianPrice,pred_SVM=returnSVM )
コード例 #8
0
ファイル: app.py プロジェクト: DavidShield/SEProject-1
def stock():
    data_types = [
        'High',
        'Low',
        'Close',
        'Volume',
        'Adj Close',
    ]
    stockname = request.args.get('stock_name')

    window = 50
    window2 = 150

    recent_trend_query = """
    SELECT Date, `{__value_name__}`
    FROM seproject.historicaldata
    where sym = '{__stockname__}'
    order by Date ASC;
    """
    move_avg_query = """
    SELECT seproject.historicaldata.Date, seproject.historicaldata.`{__value_name__}`, avg(historicaldata_past.`{__value_name__}`) as `{__value_name__}_window`
    FROM seproject.historicaldata
    JOIN (
        SELECT
        seproject.historicaldata.Date, seproject.historicaldata.`{__value_name__}`
        FROM seproject.historicaldata
        WHERE seproject.historicaldata.sym = '{__stockname__}'
    ) AS historicaldata_past 
      ON seproject.historicaldata.Date BETWEEN  historicaldata_past.Date and date_add(historicaldata_past.Date, interval + {__window__} day)
    WHERE seproject.historicaldata.sym = '{__stockname__}'
    GROUP BY 1, 2
    order by seproject.historicaldata.Date ASC;

    """
    rt_price = """
    SELECT price 
    FROM seproject.realtimedata
    WHERE sym = '{__stockname__}'
    """
    #rt_price1 = {}

    pred_price = round(analyzeSymbol(stockname), 2)

    q_results = db.engine.execute(rt_price.format(__stockname__=stockname))
    #d = json.dumps(q_results)
    for res in q_results:
        chart_data = res[0]
    rt_price1 = chart_data
    print(type(pred_price))

    print(type(rt_price1))
    rec_BS_A = ['BUY', 'SELL']

    if float(rt_price1) < pred_price:
        rec_BS = rec_BS_A[0]
    else:
        rec_BS = rec_BS_A[1]

    chart_data_all = {}
    chart_data_all_sec = {}
    chart_data_all_th = {}

    for data_type in data_types:
        q_results = db.engine.execute(
            recent_trend_query.format(__stockname__=stockname,
                                      __value_name__=data_type))
        chart_values = []
        for result in q_results:
            unixtime = time.mktime(result[0].timetuple()) * 1000
            chart_values.append([unixtime, result[1]])
        chart_data_all[data_type] = chart_values

        q_results = db.engine.execute(
            move_avg_query.format(__stockname__=stockname,
                                  __value_name__=data_type,
                                  __window__=window))
        chart_values = []
        for result in q_results:
            unixtime = time.mktime(result[0].timetuple()) * 1000
            chart_values.append([unixtime, result[2]])
        chart_data_all_sec[data_type] = chart_values
        q_results = db.engine.execute(
            move_avg_query.format(__stockname__=stockname,
                                  __value_name__=data_type,
                                  __window__=window2))
        chart_values = []
        for result in q_results:
            unixtime = time.mktime(result[0].timetuple()) * 1000
            chart_values.append([unixtime, result[2]])
        chart_data_all_th[data_type] = chart_values

    return render_template("stockselect.html",
                           chart_title=stockname,
                           chart_data_all=chart_data_all,
                           chart_data_all_sec=chart_data_all_sec,
                           chart_data_all_th=chart_data_all_th,
                           data_types=data_types,
                           window=window,
                           window2=window2,
                           rt_price=rt_price1,
                           pred_price=pred_price,
                           rec_BS=rec_BS,
                           stock=stockname)