0% found this document useful (0 votes)
12 views1 page

Facebook Prophet Code

The document outlines a Python script that uses the Prophet library to forecast stock prices for ASIANPAINT.NS based on historical data. It loads the dataset, prepares it for modeling, fits the Prophet model, and predicts stock prices for the next three months, specifically highlighting the forecast for the third month. The script also includes visualizations of the forecast and its components.

Uploaded by

Nani Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Facebook Prophet Code

The document outlines a Python script that uses the Prophet library to forecast stock prices for ASIANPAINT.NS based on historical data. It loads the dataset, prepares it for modeling, fits the Prophet model, and predicts stock prices for the next three months, specifically highlighting the forecast for the third month. The script also includes visualizations of the forecast and its components.

Uploaded by

Nani Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import pandas as pd

from prophet import Prophet


import [Link] as plt

# Load the dataset


file_path = '/content/ASIANPAINT.NS_stock_data_inr.csv' # Adjust the path if
necessary
df = pd.read_csv(file_path)

# Rename columns to fit Prophet's requirements


[Link](columns={'Date': 'ds', 'Close': 'y'}, inplace=True)

# Convert 'ds' to datetime format


df['ds'] = pd.to_datetime(df['ds'])

# Initialize and fit the Prophet model


model = Prophet()
[Link](df)

# Create a dataframe to predict the next 3 months (approximately 90 days)


future = model.make_future_dataframe(periods=90)

# Make predictions
forecast = [Link](future)

# Get the last actual value from the original data


last_actual_value = df['y'].iloc[-1]

# Calculate percentage change for predictions


forecast['percent_change'] = ((forecast['yhat'] - last_actual_value) /
last_actual_value) * 100

# Filter the forecast to show predictions for the third month only
third_month_start = future['ds'].iloc[-90] + [Link](days=60)
third_month_end = future['ds'].iloc[-90] + [Link](days=90)
third_month_forecast = forecast[(forecast['ds'] >= third_month_start) &
(forecast['ds'] <= third_month_end)]

# Display relevant columns with percentage change for the third month
forecast_with_percentage = third_month_forecast[['ds', 'yhat', 'yhat_lower',
'yhat_upper', 'percent_change']]
print(forecast_with_percentage)

# Plot the forecast for all data


fig1 = [Link](forecast)
[Link]('Stock Price Forecast')
[Link]('Date')
[Link]('Close Price')
[Link]()

# Plot forecast components


fig2 = model.plot_components(forecast)
[Link]()

You might also like