Пример #1
0
def main():
    start = "2003-01-01"
    end = "2018-01-01"

    hist.get_stock_data("AAPL", start_date=start, end_date=end)
    process = DataProcessing("stock_prices.csv", 0.9)
    process.gen_test(10)
    process.gen_train(10)

    X_train = process.X_train / 200
    Y_train = process.Y_train / 200

    X_test = process.X_test / 200
    Y_test = process.Y_test / 200

    model = tf.keras.models.Sequential()
    model.add(tf.keras.layers.Dense(100, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dense(100, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dense(1, activation=tf.nn.relu))

    model.compile(optimizer="adam", loss="mean_squared_error")

    model.fit(X_train, Y_train, epochs=100)

    print(model.evaluate(X_test, Y_test))
Пример #2
0
import get_prices as hist
import tensorflow as tf
from preprocessing import DataProcessing
import pandas_datareader.data as pdr
import yfinance as fix
import matplotlib.pyplot as plt
import WXBizSendMsg

fix.pdr_override()

start = "2000-01-01"
end = "2019-08-22"

stock = "000001.SS"

hist.get_stock_data(stock, start_date=start, end_date=end)
process = DataProcessing("stock_prices.csv", 0.9)

process.gen_test(10)
process.gen_train(10)

X_train = process.X_train / np.array([process.value_max, process.volume_max
                                      ])  # 归一化, 包括Adj Close 和 Volume
Y_train = process.Y_train / process.value_max

X_test = process.X_test / np.array([process.value_max, process.volume_max])
Y_test = process.Y_test / process.value_max

model = tf.keras.Sequential()
model.add(tf.keras.layers.LSTM(20, input_shape=(10, 2), return_sequences=True))
model.add(tf.keras.layers.LSTM(20))
Пример #3
0
import get_prices as hist
import tensorflow as tf
from preprocessing import DataProcessing
# import pandas_datareader.data as pdr if using the single test below
import yfinance as fix
fix.pdr_override()

start = "2003-01-01"
end = "2018-01-01"

hist.get_stock_data("AAPL", start_date=start, end_date=end)
process = DataProcessing("stock_prices.csv", 0.9)
process.gen_test(10)
process.gen_train(10)

X_train = process.X_train / 200
Y_train = process.Y_train / 200

X_test = process.X_test / 200
Y_test = process.Y_test / 200

model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Dense(100, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(100, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(1, activation=tf.nn.relu))

model.compile(optimizer="adam", loss="mean_squared_error")

model.fit(X_train, Y_train, epochs=100)

print(model.evaluate(X_test, Y_test))