Skip to main content

A Python module for fitting the LPPLS model to data.

Project description

PyPI 📦

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:

where:

  • expected log price at the date of the termination of the bubble
  • critical time (date of termination of the bubble and transition in a new regime)
  • expected log price at the peak when the end of the bubble is reached at
  • amplitude of the power law acceleration
  • amplitude of the log-periodic oscillations
  • degree of the super exponential growth
  • scaling ratio of the temporal hierarchy of oscillations
  • time scale of the oscillations

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

Important links

Installation

Dependencies

lppls requires:

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

User installation If you already have a working installation of numpy and scipy, the easiest way to install scikit-learn is using pip

pip install -U lppls

Example Use

from datetime import datetime
from lppls import lppls
import numpy as np
import pandas as pd

SECONDS_IN_A_MONTH = 2.628e+6

data = pd.read_csv('data/sp500.csv', index_col='Date')

timestamp = [datetime.timestamp(dt) for dt in data.index]
price = [p for p in data['Adj Close']]
last_ts = timestamp[-1]

observations = np.array([timestamp, price])

# set limits for non-linear params
search_bounds = [
    (last_ts, last_ts + SECONDS_IN_A_MONTH),    # Critical Time 
    (0.1, 0.9),                                 # m : 0.1 ≤ m ≤ 0.9
    (6, 13),                                    # ω : 6 ≤ ω ≤ 13
]

MAX_SEARCHES = 25

lppls_model = lppls.LPPLS(use_ln=True, observations=observations)

tc, m, w, a, b, c1, c2 = lppls_model.fit(observations, MAX_SEARCHES, search_bounds, minimizer='Nelder-Mead')

lppls_model.plot_fit(tc, m, w, observations)

# 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.1.10.tar.gz (7.2 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.1.10-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lppls-0.1.10.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for lppls-0.1.10.tar.gz
Algorithm Hash digest
SHA256 9c59002bcb3c9ea362068251ea08dba749d408341f63aed40af0900d91777a25
MD5 58b8ffbfa1ee65d5c4fca5e0c84f17a1
BLAKE2b-256 d7e4b828ddf5f85592e835d2fdc485e67f8f4c2bd8e2d4ec6fdeb1ac6eb4dbe2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lppls-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for lppls-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 74e6ab43551c00ee6a5cdf29ff0c60d7afef7ff9c3fa37a990af17837e8bb7de
MD5 0faec3dda91cf56d18b119eca21185e5
BLAKE2b-256 ace15df9ddc96fb99408e26d669e896e62468f72402a155d16b1eb3e584711db

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