Metadata-Version: 2.4
Name: xpectral
Version: 1.0.3
Summary: Quant Research Library
Project-URL: Homepage, https://github.com/bayquant/xpectral
Author: BayQuant
License: MIT License
        
        Copyright (c) 2025 BayQuant
        
        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.
License-File: LICENSE
Keywords: bokeh,finance,polars,quant
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.12
Requires-Dist: bokeh==3.8.1
Requires-Dist: massive>=2.0.2
Requires-Dist: matplotlib>=3.10.7
Requires-Dist: pandas>=2.3.3
Requires-Dist: polars>=1.34.0
Requires-Dist: pyarrow>=21.0.0
Requires-Dist: python-dotenv>=1.2.1
Description-Content-Type: text/markdown

# Xpectral

![Spectral decomposition](assets/xpectral_banner.gif)

A quantitative research library that extends **Polars** and **Pandas** DataFrames with charting and quant analytics.

## Modules

- **`xpectral.charts`** — Fluent Bokeh visualization via `df.bokeh.line(...)`, `df.bokeh.scatter(...)`, etc.
- **`xpectral.quant`** — Financial metrics (returns, volatility, beta) via `pl.col(...).quant.returns()`
- **`xpectral.data`** — Market data from the Polygon/Massive API with caching and rate limiting

## `xpectral.charts`

### Usage

```python
import xpectral  # registers the accessors
from xpectral import PandasDataFrame
from xpectral import PolarsDataFrame

df: PolarsDataFrame = pl.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
fig = df.bokeh(title="Example", width=600, height=400)
fig.line(x="x", y="y")

pd_df: PandasDataFrame = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
pd_fig = pd_df.bokeh(title="Example", width=600, height=400)
pd_fig.line(x="x", y="y")
```

Annotate sample DataFrames with `PolarsDataFrame` or `PandasDataFrame` when you want the editor (pyright) to resolve the `df.bokeh(...)` parameters and chained accessor methods. Annotation is neccessary for type hinting as accessors are not discovered dinamically.

### Custom chart methods

Use `BokehAccessor.register` to add your own methods to the accessor. The decorated function receives `self` — the accessor instance — giving access to `self._df`, `self.source`, `self.plot`, and all built-in glyph methods.

```python
from xpectral.charts import BokehAccessor

@BokehAccessor.register
def price_band(self, mid, upper, lower, **kwargs):
    self.line(y=mid, **kwargs)
    self.varea(y1=lower, y2=upper, fill_alpha=0.2, **kwargs)

fig = df.bokeh(title="Bands", width=800, height=400)
fig.price_band(mid="close", upper="upper", lower="lower")
```

The method is available on both Polars and Pandas accessors immediately after registration.

## Install

```bash
pip install xpectral
```

```bash
uv add xpectral
```

For development:

```bash
uv sync
```
