Fit the LPPLS model to price data
masterTo use the lppls module, you must first prepare your data as an observations array. This array should contain two rows: the first row is the time (converted to ordinal format) and the second row is the log-transformed price.
- Convert dates to ordinals using
pd.Timestamp.toordinal. - Log-transform the price data.
- Create a NumPy array of shape
(2, N). - Instantiate
lppls.LPPLS(observations=observations). - Call
.fit(max_searches)to retrieve the model parameters.
from lppls import lppls
import numpy as np
import pandas as pd
from datetime import datetime as dt
# Prepare data
data = data_loader.nasdaq_dotcom()
time = [pd.Timestamp.toordinal(dt.strptime(t1, '%Y-%m-%d')) for t1 in data['Date']]
price = np.log(data['Adj Close'].values)
observations = np.array([time, price])
# Fit model
MAX_SEARCHES = 25
lppls_model = lppls.LPPLS(observations=observations)
tc, m, w, a, b, c, c1, c2, O, D = lppls_model.fit(MAX_SEARCHES)
# Visualize
lppls_model.plot_fit()