0% found this document useful (0 votes)
10 views

Gas Price Analyzer

Uploaded by

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

Gas Price Analyzer

Uploaded by

gh.22srimanta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Analyzing_Natural_Gas_Prices

April 17, 2024

[1]: import pandas as pd


import numpy as np
import matplotlib.pyplot as plt
from statsmodels.tsa.holtwinters import ExponentialSmoothing

# Load the dataset


data = pd.read_csv(r"C:\Users\gh22s\Downloads\Nat_Gas.csv")

# Load the dataset with explicit date format


data['Dates'] = pd.to_datetime(data['Dates'], format='%m/%d/%y')

# Set 'Date' column as index


data.set_index('Dates', inplace=True)

# Generate a new date range with frequency 'MS'


data.index = pd.date_range(start=data.index[0], periods=len(data), freq='MS')

# Fit the Exponential Smoothing model


model = ExponentialSmoothing(data['Prices'], seasonal='additive',␣
,→seasonal_periods=12)

results = model.fit()

# Forecast future prices


forecast = results.forecast(steps=12)

#print(forecast)
d = pd.DataFrame(forecast)

# Reset the index, moving it to a column


d.reset_index(inplace=True)
d.columns = ['Dates','Prices']
d

[1]: Dates Prices


0 2024-11-01 11.847585
1 2024-12-01 12.384329
2 2025-01-01 12.721168
3 2025-02-01 12.758006

1
4 2025-03-01 12.644867
5 2025-04-01 12.681651
6 2025-05-01 12.043331
7 2025-06-01 11.615156
8 2025-07-01 11.491899
9 2025-08-01 11.653760
10 2025-09-01 11.540510
11 2025-10-01 11.752298

[2]: # Assuming 'results' contains the fitted Exponential Smoothing model


date_input = pd.to_datetime('2025-05-01') # Change the date as needed

# Extract the forecasted price for the specific date


forecasted_price = results.forecast(steps=12)[date_input]

print(f"Estimated gas price for {date_input.date()}: ${forecasted_price:.2f}")

Estimated gas price for 2025-05-01: $12.04

[3]: import matplotlib.pyplot as plt

# Visualize the data and forecast side by side


fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(16, 6))

# Plot historical prices


axes[0].plot(data.index, data['Prices'], marker='o', linestyle='-',␣
,→color='skyblue')

axes[0].set_title('Historical Natural Gas Prices', fontsize=14)


axes[0].set_xlabel('Dates', fontsize=12)
axes[0].set_ylabel('Prices', fontsize=12)
axes[0].tick_params(axis='x', rotation=45)
axes[0].grid(True)

# Plot forecasted prices


axes[1].plot(data.index, data['Prices'], label='Historical Prices', marker='o',␣
,→linestyle='-', color='skyblue')

axes[1].plot(forecast.index, forecast, label='Forecasted Prices',␣


,→color='salmon', marker='o', linestyle='--')

axes[1].set_title('Forecasted Natural Gas Prices (Exponential Smoothing)',␣


,→fontsize=14)

axes[1].set_xlabel('Dates', fontsize=12)
axes[1].set_ylabel('Prices', fontsize=12)
axes[1].tick_params(axis='x', rotation=45)
axes[1].legend(fontsize=12)
axes[1].grid(True)

# Add annotation for projected trend

2
axes[1].annotate('Projected Trend', xy=(data.index[-1], forecast.iloc[-1]),␣
,→xytext=(-100, 50),

textcoords='offset points', arrowprops=dict(arrowstyle='->',␣


,→connectionstyle="arc3,rad=.2"), fontsize=12)

plt.tight_layout()
plt.show()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy