Time Series forecasting of natural gas prices with Python
A common task in finance is forecasting values. There are several methods for creating forecasts such as ARIMA, Bayesian Structural Time Series, and simulation. Monte Carlo is a simulation technique based on generating random walks over a period of time.
6 min readOct 26, 2023
In this tutorial, we will:
- fetch Natural Gas prices
- Simulate future price movements using Monte Carlo
- Plot the simulated future paths
- Calculate future values using ARIMA and Bayesian Timeseries
We start by importing the modules we will need. We are going to access the price of natural gas from Financial Modeling Prep, a web API. You need an API key from them to pull the data.
# getting historical data for US Natural Gas prices.
# This code calls the API and transforms the result into a DataFrame.
import numpy as np
np.random.seed(3363)
import pandas as pd
from scipy.stats import norm
import datetime
import matplotlib.pyplot as plt
%matplotlib inline
ticker = "NGUSD" #US natural gas
base = 'https://financialmodelingprep.com/api/v3/'
key = YOUR_KEY
target = "{}historical-price-full/{}?apikey={}".format(base, ticker, key)
df = pd.read_json(target)
df = pd.json_normalize(df['historical'])
df['date'] =…