import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
date = np.linspace(1,15,15)
priceBegin = np.array([19.59,19.51,
                       20.98,18.67,18.52,19,
                       18.64,18.2,
                       18.73,18.84,18.42,
                       18.2,18.55,
                       19.02,18.78])
priceEnd = np.array([19.45,19.83,
                     20.6,20.56,
                     18.69,18.56,
                     19.18,18.68,
                     18.38,18.8,
                     18.94,18.39,
                     18.16,18.7,18.68])
priceHeight = np.array([20.23,19.
                        9,21.97,20.56,18.93,
                        19.09,19.32,18.78,
                        19.04,19,19.37,
                        18.4,18.59,
                        19.18,19.27])
priceLow = np.array([19.33,19,20.56,
                     18.5,18.42
                     ,18.51,18.54,
                     18.07,18.34,
                     18.6,18.4,18.18,
                     18.1,18.6,18.68])
#print(date)
dataOne = np.zeros([2])
dataPrice = np.zeros([2])
dataMaxmin = np.zeros([2])
#print(dataOne)
for i in range(0,15):
    dataOne[0] = date[i]
    dataOne[1] = date[i]
    dataPrice[0] = priceBegin[i]
    dataPrice[1] = priceEnd[i]
    dataMaxmin[0] = priceHeight[i]
    dataMaxmin[1] = priceLow[i]
    if dataPrice[0]>=dataPrice[1]:
        plt.plot(dataOne,dataPrice,lw=8,color='g')
        plt.plot(dataOne,dataMaxmin,lw=1,color='g')
    else:
        plt.plot(dataOne,dataPrice,lw=8,color='r')
        plt.plot(dataOne,dataMaxmin,lw=1,color='r')
dateNormal = np.zeros([15,1])
priceNormal = np.zeros([15,1])
for i in range(0,15):
    dateNormal[i,0] = i/14
    priceNormal[i,0] = priceEnd[i]/50
x = tf.placeholder(tf.float32,[None,1])
y = tf.placeholder(tf.float32,[None,1])

w1 = tf.Variable(tf.random_uniform([1,10],0,1))
b1 = tf.Variable(tf.zeros([15,10]))
wb1 = tf.matmul(x,w1)+b1
layer1 = tf.nn.relu(wb1

w2 = tf.Variable(tf.random_uniform([10,1],0,1))
b2 = tf.Variable(tf.random_uniform([15,1],0,1))
wb2 = tf.matmul(layer1,w2)+b2
layer2 = tf.nn.relu(wb2)
loss = tf.reduce_mean(tf.sqrt(tf.square(y-layer2)))
train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    for i in range(0,1000):
        sess.run(train_step,feed_dict={x:dateNormal,y:priceNormal})
    pred = sess.run(layer2,feed_dict={x:dateNormal})
    predPrice = np.zeros([15,1])
    for i in range(0,15):
        predPrice[i,0] = (pred*50)[i,0]
    plt.plot(date,predPrice,'black',lw=2)
plt.show()