Ejemplo n.º 1
0
def makeOutY(FinalM, xVals, startYear, yVals,
             currentData):  # Make a Y array with the fucntion x

    Current_Data = float(currentData[0]['LastTradePrice'])  # Gets current data
    y = len(yVals)  # length of yVals array

    x10 = float(FinalM.item(10, 0))  #Coeffcient 10
    x9 = float(FinalM.item(9, 0))  #Coeffcient 9
    x8 = float(FinalM.item(8, 0))  #Coeffcient 8
    x7 = float(FinalM.item(7, 0))  #Coeffcient 7
    x6 = float(FinalM.item(6, 0))  #Coeffcient 6
    x5 = float(FinalM.item(5, 0))  #Coeffcient 5
    x4 = float(FinalM.item(4, 0))  #Coeffcient 4
    x3 = float(FinalM.item(3, 0))  #Coeffcient 3
    x2 = float(FinalM.item(2, 0))  #Coeffcient 2
    x1 = float(FinalM.item(1, 0))  #Coeffcient 1
    xo = float(FinalM.item(0, 0))  #Coeffcient 0

    Generated_Data = np.array(yVals[y - xVals])

    for x in range(0, 30):
        Generated_Data = np.append(
            Generated_Data,
            (float(x10 * pow(x, 10) + x9 * pow(x, 9) + x8 * pow(x, 8) +
                   x7 * pow(x, 7) + x6 * pow(x, 6) + x5 * pow(x, 5) +
                   x4 * pow(x, 4) + x3 * pow(x, 3) + x2 * pow(x, 2) +
                   x1 * pow(x, 1) + xo * pow(x, 0))))
        pass

    return ArrayNCalc.Normalize(
        ArrayNCalc.differenceBetweenDataPoints(Generated_Data), yVals)
Ejemplo n.º 2
0
def totalTogether(stockSymbol, Webster, currentInfo, Predict, Pointy,
                  Rsi):  #plots all the graphs together
    old_stdout = sys.stdout
    sys.stdout = open(os.devnull, "w")
    # Does not work in linux!!!
    temp = Webster.index
    temp = temp.tz_localize("UTC")

    figure = obj.Scatter(y=Webster.High,
                         x=temp,
                         line=dict(color=('rgb(0,50,100)')),
                         name="Past Data for " + stockSymbol)  #Past Data Line

    currentFigure = obj.Trace(y=currentInfo[0]['LastTradePrice'],
                              x=currentInfo[0]['LastTradeDateTime'],
                              line=dict(color=('rgb(0,0,0)')),
                              name='Current Data for ' +
                              stockSymbol)  #Current Point

    Predicts = obj.Scatter(y=Predict,
                           x=ArrayNCalc.getWorkDates(len(Predict)),
                           line=dict(color=('rgb(255,165,0)')),
                           name="Prediction " + stockSymbol)  #Prediction Line

    point = obj.Trace(y=Pointy,
                      x=datetime.now(pytz.utc) + timedelta(days=1),
                      line=dict(color=pointColorMaker(Pointy, currentInfo)),
                      name="Prediction " + stockSymbol)  #point of prediciton

    RSI = obj.Scatter(y=Rsi,
                      x=ArrayNCalc.getWorkDates(len(Rsi)),
                      line=dict(color=('rgb(0,0,0)')),
                      name="RSI for " + stockSymbol)  #Prediction Line

    fig = tools.make_subplots(rows=2, cols=1)

    #data=Data([figure,currentFigure,Predicts, point]) #Data Array of Figures
    data = Data([Predicts, point, currentFigure, figure])
    fig.append_trace(data[0], 1, 1)
    fig.append_trace(data[1], 1, 1)
    fig.append_trace(data[2], 1, 1)
    fig.append_trace(data[3], 1, 1)

    fig.append_trace(RSI, 2, 1)

    fig['layout']['yaxis1'].update(title='Dollars ($)', domain=[0, 0.7])
    fig['layout']['yaxis2'].update(title='RSI percentage (%)',
                                   range=[0, 100],
                                   domain=[0.8, 1])
    sys.stdout.close()
    sys.stdout = old_stdout
    return py.plot(fig, filename=stockSymbol + '_Line',
                   auto_open=False)  #Plot The Function
Ejemplo n.º 3
0
def getPointY(FinalM, date, prev, yahoorecent):

    i = ArrayNCalc.getWorkDates(45)
    i = len(i)

    prev = float(prev)
    Max = .25 * prev - prev  # Maximum
    Min = .25 * prev + prev  # Minimum

    x10 = float(FinalM.item(10, 0))  #Coeffcient 10
    x9 = float(FinalM.item(9, 0))  #Coeffcient 9
    x8 = float(FinalM.item(8, 0))  #Coeffcient 8
    x7 = float(FinalM.item(7, 0))  #Coeffcient 7
    x6 = float(FinalM.item(6, 0))  #Coeffcient 6
    x5 = float(FinalM.item(5, 0))  #Coeffcient 5
    x4 = float(FinalM.item(4, 0))  #Coeffcient 4
    x3 = float(FinalM.item(3, 0))  #Coeffcient 3
    x2 = float(FinalM.item(2, 0))  #Coeffcient 2
    x1 = float(FinalM.item(1, 0))  #Coeffcient 1
    xo = float(FinalM.item(0, 0))  #Coeffcient 0

    change = float(
        (x10 * pow(i, 10) + x9 * pow(i, 9) + x8 * pow(i, 8) + x7 * pow(i, 7) +
         x6 * pow(i, 6) + x5 * pow(i, 5) + x4 * pow(i, 4) + x3 * pow(i, 3) +
         x2 * pow(i, 2) + x1 * pow(i, 1) + xo * pow(i, 0)))
    if (yahoorecent < prev):
        change += yahoorecent + (Max - Min)  # Predicited Increase
    else:
        change = yahoorecent - change  # Predicted decrease
    return prev + (change / (Max - Min))
Ejemplo n.º 4
0
def getPointY(FinalM, date, prev, yahoorecent):

    i = ArrayNCalc.getWorkDates(45)
    i = len(i)
    prev = float(prev)
    Max = .25 * prev - prev
    Min = .25 * prev + prev
    x10 = float(FinalM.item(10, 0))
    x9 = float(FinalM.item(9, 0))
    x8 = float(FinalM.item(8, 0))
    x7 = float(FinalM.item(7, 0))
    x6 = float(FinalM.item(6, 0))
    x5 = float(FinalM.item(5, 0))
    x4 = float(FinalM.item(4, 0))
    x3 = float(FinalM.item(3, 0))
    x2 = float(FinalM.item(2, 0))
    x1 = float(FinalM.item(1, 0))
    xo = float(FinalM.item(0, 0))

    change = float(
        (x10 * pow(i, 10) + x9 * pow(i, 9) + x8 * pow(i, 8) + x7 * pow(i, 7) +
         x6 * pow(i, 6) + x5 * pow(i, 5) + x4 * pow(i, 4) + x3 * pow(i, 3) +
         x2 * pow(i, 2) + x1 * pow(i, 1) + xo * pow(i, 0)))
    if (yahoorecent < prev):
        change += yahoorecent + (Max - Min)
    else:
        change = yahoorecent - change
    return prev + (change / (Max - Min))
Ejemplo n.º 5
0
def makeXVals_Matrix(
    percision, startYear, DataSet
):  #Number of elements,percison what power of X do we want to go to. Returns One's Matrix

    i = len(ArrayNCalc.getWorkDates(45))
    matrixx = np.array(i - DataSet)

    matrixx = np.append(matrixx, 0)

    for q in range(2, percision + 1):

        matrixx = np.append(matrixx, pow(0, q))

        pass

    for x in range(int(i - DataSet + 1), int(i)):

        matrixx = np.append(matrixx, [1])

        for y in range(1, percision + 1):

            matrixx = np.append(matrixx, pow(x, y))

            pass

        pass

    return (np.reshape(matrixx, (DataSet, percision + 1)))
Ejemplo n.º 6
0
def rsiPlot(stockSymbol, Webster, Predict,
            startYear):  #plots all the graphs together
    old_stdout = sys.stdout
    sys.stdout = open(os.devnull, "w")
    figure = obj.Scatter(y=Webster.High,
                         x=Webster.index,
                         line=dict(color=('rgb(0,50,100)')),
                         name="Past Data for " + stockSymbol)  #Past Data Line

    Predicts = obj.Scatter(y=Predict,
                           x=ArrayNCalc.getWorkDates(len(Predict)),
                           line=dict(color=('rgb(255,165,0)')),
                           name="RSI for " + stockSymbol)  #Prediction Line

    fig = tools.make_subplots(rows=2, cols=1)

    fig.append_trace(figure, 1, 1)  # subplot positions
    fig.append_trace(Predicts, 2, 1)

    fig['layout']['xaxis2'].update(
        range=[datetime(int(startYear), 1, 1),
               datetime.now()])

    fig['layout']['yaxis1'].update(title='Dollars ($)')  # format the axes
    fig['layout']['yaxis2'].update(title='RSI percentage (%)', range=[0, 100])
    sys.stdout.close()
    sys.stdout = old_stdout
    return py.plot(fig, filename=stockSymbol + '_Line')
def getRelativeAcc():
	stockName = request.args.get('s')
	var=stockName
	old_stdout = sys.stdout
	sys.stdout = open(os.devnull, "w")
	if var != 'null':					# ONLY PRECED IF WE HAVE A COMPANY
		timeBegin=2010
			
		totalDataCurrent=Fetching.fetchDataToday(var,timeBegin) # This gets all the data from the start year to 3 days ago (give or take a work day)
		
		googData=Fetching.fetchGoogData(var) # Fetch Todays data from google finance
			
		Prediction_Data=Fetching.fetchDataSpec(var,(datetime.now()+timedelta(days=-45))) # Get the data from just the past month for the prediciton part
			
		Prediction_Data_Length=len(Prediction_Data.High) # Lenght of the predictin Data to save the recalc of it
		
		
		Coefficients=LinearAlgebra.coeffcients_Generator(LinearAlgebra.makeXVals_Matrix(10,timeBegin,Prediction_Data_Length),LinearAlgebra.makeY_Matrix(Prediction_Data.Low)) #coeffcients for prediction fucntion a0-a10		
		
		Prediction_Model=LinearAlgebra.makeOutY(Coefficients,Prediction_Data_Length,timeBegin,totalDataCurrent.High,googData) # Gets Prediciton Model or scatter of predicted points these points are also normalized
		
		
		ret = str(ArrayNCalc.CalculateRelativeACC(Prediction_Model,Prediction_Data.High))
		sys.stdout.close()
		sys.stdout = old_stdout
		return "The relative accuracy is: " + ret + "%"
	else:
		sys.stdout.close()
		sys.stdout = old_stdout
		return ""
Ejemplo n.º 8
0
def getRelativeAcc():
	stockName = request.args.get('s')
	var=stockName
	old_stdout = sys.stdout
	sys.stdout = open(os.devnull, "w")
	if var != 'null':					# ONLY PRECED IF WE HAVE A COMPANY
		timeBegin=2010
		
		Coefficients = numpy.zeros(shape =(11,1))
			
		totalDataCurrent=Fetching.fetchDataToday(var,timeBegin) # This gets all the data from the start year to 3 days ago (give or take a work day)
		
		googData=Fetching.fetchGoogData(var) # Fetch Todays data from google finance
			
		Prediction_Data=Fetching.fetchDataSpec(var,(datetime.now()+timedelta(days=-45))) # Get the data from just the past month for the prediciton part
			
		Prediction_Data_Length=len(Prediction_Data.High) # Lenght of the predictin Data to save the recalc of it
		
		
		#if Cache2.Search(var) ==0:
			
		Coefficients=LinearAlgebra.coefficients_Generator(LinearAlgebra.makeXVals_Matrix(10,timeBegin,Prediction_Data_Length),LinearAlgebra.makeY_Matrix(Prediction_Data.Low)) #coeffcients for prediction fucntion a0-a10		
				
		#Cache2.Cache_Predictions(var,Coefficients)		# after calculating store the data in cache
				
		#else:
		#Coefficients = Cache2.Fetch_Cache(var)		# fetch from cache if the company data is stored and it's recent ( less than 3 days from prediction)
			
		Prediction_Model=LinearAlgebra.makeOutY(Coefficients,Prediction_Data_Length,timeBegin,totalDataCurrent.High,googData) # Gets Prediciton Model or scatter of predicted points these points are also normalized
		
		
		ret = str(ArrayNCalc.CalculateRelativeACC(Prediction_Model,Prediction_Data.High))
		sys.stdout.close()
		sys.stdout = old_stdout
		return "The relative error is: " + ret + "%"
	else:
		sys.stdout.close()
		sys.stdout = old_stdout
		return ""