Metadata-Version: 2.4
Name: IntrinsicTime
Version: 0.1.4
Summary: Utilities for intrinsic time decomposition and fractal event analysis
Author-email: Tom Houweling <thomas.houweling@gmail.com>
License: MIT License
        
        Copyright (c) 2025 [Your Name]
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        THE SOFTWARE.
        
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: scipy
Requires-Dist: plotly
Dynamic: license-file

# IntrinsicTime

Utilities for decomposing **intrinsic time** events and analyzing **fractal scaling** behavior in price or signal data.

This package provides:
- [dcos_core](dcos_core.md): A **Directional Change and Overshoot (DcOS)** event detector.
- [dcos_fractal](dcos_fractal.md): Tools for **fractal scaling** and **multi-threshold analysis**.
- [dcos_plot](dcos_plot.md): **Plotly** visualization for interactive fractal plots.

---

## Installation

### From PyPi
```
pip install IntrinsicTime
```

### From GitHub
```
pip install git+https://github.com/THouwe/IntrinsicTime.git
```

### Local Install
```
git clone https://github.com/THouwe/IntrinsicTime.git
cd IntrinsicTime
pip install -e .
```

### Dependencies
See `requirements.txt`.

---

## Overview

## DcOS events are first‑passage moves of size δ in log space
Robust power‑law behaviour can be observed for many phenomena.
For instance, Intrinsic Time event density of BTCUSDT price ticks scale linearly with DcOS δ threshold in log space (cit), consistently with first‑passage theory (cit) plus market microstructure.
However, this is the case only within a given range of δ thresholds, as the power law may brake at 'extremely low' or 'extremely high' δs.

For small δs, issues relate to **microstructure noise** (tick size, latency, and irregular sampling inject high‑frequency mean reversion. This raises event frequency toward a ceiling and flattens the log–log curve) and **discretization limits** (time and sample - e.g., *price* - granularity cap how many distinct first‑passage events you can observe).

For large δs, issues relate to **data scarcity**: too few events reduce fit quality and increase variance.

## Fractal brakepoint formalization
Compute local slopes (b(\delta)) with a sliding window (w) on ((\log \delta,\log f)).
Mark the smallest δ where either (R^2 < R^2_{\min}) or (|\Delta b|) exceeds one standard error from adjacent windows.
Your windowed method will return something close to δ ≈ 6e‑4 for this dataset if your visual read is correct.

### Example Usage
```
import numpy as np
import pandas as pd
from IntrinsicTime.dcos_core import DcOS, Price, Sample
from IntrinsicTime.dcos_fractal import DcOS_fractal, DcOS_tests
from IntrinsicTime.dcos_plot import DcOS_plotter

# Example input DataFrame
df = pd.DataFrame(
    {
        "Timestamp": np.arange(1_000),
        "Price": 100 + np.cumsum(np.random.randn(1_000)),
    }
)

# Initialize and run the full fractal analysis
analyzer = DcOS_fractal(debugMode=True)
results, fit_region = analyzer.run(df)

# Display basic statistics
print(results[["threshold", "nDCtot", "nOStot", "nEVtot"]].head())
print("Fit region (δ_min_fit, δ_max_fit):", fit_region)

# Optional: analyze results
summary = DcOS_tests.analyze_dcos_results(
    results,
    event_sequences=results.attrs.get("event_sequences"),
    os_segments=results.attrs.get("os_segments"),
)

# Optional: interactive Plotly visualization
plotter = DcOS_plotter()
fig = plotter.fractal_plot(
    results,
    pt_constant=61.21,
    pt_tolerance=2.5,
    savePlots=False,
    save_png=False,
)
fig.show()
```
