trcs.195 / therollercoasterstrategy_195.py
antitheft159's picture
Upload therollercoasterstrategy_195.py
d1dac94 verified
raw
history blame
1.31 kB
# -*- coding: utf-8 -*-
"""therollercoasterstrategy.195
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1Pn8vxMsTuQGWNoH9Bqo7XTJ1stXjNDHx
"""
!pip install neuralprophet
from neuralprophet import NeuralProphet
import yfinance as yf
import pandas as pd
import matplotlib.pyplot as plt
stock_symbol = 'DAL'
start_date = '2020-11-01'
end_date = '2024-12-01'
stock_data = yf.download(stock_symbol, start = start_date, end=end_date)
print(stock_data.head())
stock_data.to_csv('stock_data.csv')
stocks = pd.read_csv('stock_data.csv')
stocks['Date'] = pd.to_datetime(stocks['Date'])
stocks = stocks[['Date', 'Close']]
stocks.columns = ['ds', 'y']
plt.plot(stocks['ds'], stocks['y'], label = 'actual', c = 'g')
plt.show()
model = NeuralProphet()
model.fit(stocks)
future = model.make_future_dataframe(stocks, periods = 300)
forecast = model.predict(future)
actual_prediction = model.predict(stocks)
plt.title(".159 Est. 1367")
plt.plot(actual_prediction['ds'], actual_prediction['yhat1'], label = "prediction_Actual", c = 'r')
plt.plot(forecast['ds'], forecast['yhat1'], label = 'future_predictions', c = 'b')
plt.plot(stocks['ds'], stocks['y'], label = 'actual', c = 'g')
plt.legend()
plt.show()
"""S&P 500"""
model.plot_components(forecast)