Skip to main content

A Python module for fitting the LPPLS model to data.

Project description

PyPI 📦   PyTests HitCount

Log Periodic Power Law Singularity (LPPLS) Model

lppls is a Python module for fitting the LPPLS model to data.

Overview

The LPPLS model provides a flexible framework to detect bubbles and predict regime changes of a financial asset. A bubble is defined as a faster-than-exponential increase in asset price, that reflects positive feedback loop of higher return anticipations competing with negative feedback spirals of crash expectations. It models a bubble price as a power law with a finite-time singularity decorated by oscillations with a frequency increasing with time.

Here is the model:

LPPLS Model

where:

  • Expected Log Price Colon Equals expected log price at the date of the termination of the bubble
  • Critical Time Colon Equals critical time (date of termination of the bubble and transition in a new regime)
  • A Colon Equals expected log price at the peak when the end of the bubble is reached at Critical Time
  • B Colon Equals amplitude of the power law acceleration
  • C Colon Equals amplitude of the log-periodic oscillations
  • m Colon Equals degree of the super exponential growth
  • omega Colon Equals scaling ratio of the temporal hierarchy of oscillations
  • phi Colon Equals time scale of the oscillations

The model has three components representing a bubble. The first, LPPLS Term 1, handles the hyperbolic power law. For m < 1 when the price growth becomes unsustainable, and at Critical Time the growth rate becomes infinite. The second term, LPPLS Term 2, controls the amplitude of the oscillations. It drops to zero at the critical time Critical Time. The third term, LPPLS Term 3, models the frequency of the osciallations. They become infinite at Critical Time.

Important links

Installation

Dependencies

lppls requires:

  • Matplotlib (>= 3.1.1)
  • NumPy (>= 1.17.0)
  • Pandas (>= 0.25.0)
  • Python (>= 3.6)
  • SciPy (>= 1.3.0)

User installation

pip install -U lppls

Example Use

from lppls import lppls, data_loader
import numpy as np
import pandas as pd
%matplotlib inline

# read example dataset into df 
data = data_loader.sp500()

# convert index col to evenly spaced numbers over a specified interval
time = np.linspace(0, len(data)-1, len(data))

# create list of observation data, in this case, 
# daily adjusted close prices of the S&P 500
# use log price
price = np.log(data['Adj Close'].values)

# create Mx2 matrix (expected format for LPPLS observations)
observations = np.array([time, price])

# set the max number for searches to perform before giving-up
# the literature suggests 25
MAX_SEARCHES = 25

# instantiate a new LPPLS model with the S&P 500 dataset
lppls_model = lppls.LPPLS(observations=observations)

# fit the model to the data and get back the params
tc, m, w, a, b, c = lppls_model.fit(observations, MAX_SEARCHES, minimizer='Nelder-Mead')

# visualize the fit
lppls_model.plot_fit(observations, tc, m, w)

# should give a plot like the following...

LPPLS Fit to the S&P500 Dataset

References

  • Filimonov, V. and Sornette, D. A Stable and Robust Calibration Scheme of the Log-Periodic Power Law Model. Physica A: Statistical Mechanics and its Applications. 2013
  • Sornette, D. Why Stock Markets Crash: Critical Events in Complex Financial Systems. Princeton University Press. 2002.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lppls-0.3.2.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lppls-0.3.2-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

Details for the file lppls-0.3.2.tar.gz.

File metadata

  • Download URL: lppls-0.3.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for lppls-0.3.2.tar.gz
Algorithm Hash digest
SHA256 ba00ece15c811b13e60f6028bb312439d4db32fccdf63e1b3ae92348a5cfd465
MD5 2279b3ffcc4e331f8fd0729de8a14306
BLAKE2b-256 31ebf943d6723d79712ecf83a7ad4bb59a391f260a6eecee65d928db150a2cd6

See more details on using hashes here.

File details

Details for the file lppls-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: lppls-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 34.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for lppls-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a5138e0edd56fa46f7b8856dae28c2359e506017209b1a12277d6a98f02fad89
MD5 aa646b0cdb676249c3a2c40734d3d3ee
BLAKE2b-256 3e89abd929d0c6825f8096c716bc649e6e5cf563c9c11b515fac03816f487795

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page