Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py 3.12 #4

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
FMP_API_KEY: ${{ secrets.FMP_API_KEY }}
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dist
.venv
.mypy_cache
.pytest_cache
.python-version

# Jupyter
*.ipynb
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023 Quantmind
Copyright (c) 2024 Quantmind

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Expand Down
11 changes: 8 additions & 3 deletions dev/lint
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ if [ "$1" = "fix" ] ; then
RUFF_ARG="--fix"
fi

black quantflow tests ${BLACK_ARG}
ruff quantflow tests ${RUFF_ARG}
mypy quantflow tests
echo black
black quantflow quantflow_tests ${BLACK_ARG}
echo ruff
ruff quantflow quantflow_tests ${RUFF_ARG}
echo mypy
mypy quantflow
echo mypy tests
mypy quantflow_tests --explicit-package-bases
3,184 changes: 1,645 additions & 1,539 deletions poetry.lock

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ Repository = "https://github.com/quantmind/quantflow"
Documentation = "https://quantmind.github.io/quantflow/"

[tool.poetry.dependencies]
python = ">=3.10,<3.12"
python = ">=3.10,<3.13"
numpy = "^1.22.3"
scipy = "^1.10.1"
pandas = "^2.0.1"
aiohttp = {version = "^3.8.1", optional = true}
pydantic = "^2.0.2"
pyarrow = "^15.0.0"

[tool.poetry.group.dev.dependencies]
black = "^23.3.0"
black = "^24.1.1"
pytest-cov = "^4.0.0"
mypy = "^1.4.0"
ghp-import = "^2.0.2"
ruff = "^0.0.285"
pytest-asyncio = "^0.21.1"
ruff = "^0.1.14"
pytest-asyncio = "^0.23.3"


[tool.poetry.extras]
Expand Down Expand Up @@ -53,7 +54,10 @@ formats = "ipynb,myst"
[tool.pytest.ini_options]
asyncio_mode = "auto"
testpaths = [
"tests"
"quantflow_tests"
]
filterwarnings = [
"ignore::DeprecationWarning:dateutil.*:"
]

[tool.isort]
Expand All @@ -74,7 +78,7 @@ disallow_untyped_defs = true
warn_no_return = true

[[tool.mypy.overrides]]
module = "tests.*"
module = "quantflow_tests.*"
disallow_untyped_defs = false

[[tool.mypy.overrides]]
Expand Down
3 changes: 2 additions & 1 deletion quantflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"""Quantitative analysis and pricing"""
__version__ = "0.2.4"

__version__ = "0.2.5"
3 changes: 1 addition & 2 deletions quantflow/options/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@


class VolSurfaceSecurity(Protocol):
def vol_surface_type(self) -> VolSecurityType:
...
def vol_surface_type(self) -> VolSecurityType: ...


S = TypeVar("S", bound=VolSurfaceSecurity)
Expand Down
1 change: 1 addition & 0 deletions quantflow/sp/cir.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CIR(IntensityProcess):
:param sigma: Volatility parameter :math:`\sigma`
:param theta: Long term mean rate :math:`\theta`
"""

sigma: float = Field(default=1.0, gt=0, description="Volatility")
theta: float = Field(default=1.0, gt=0, description="Mean rate")
sample_algo: SamplingAlgorithm = Field(
Expand Down
1 change: 1 addition & 0 deletions quantflow/sp/copula.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class FrankCopula(Copula):
u\right)-1\right)\left(\exp\left(-\kappa
v\right)-1\right)}{\exp\left(-\kappa\right)-1}\right]
"""

kappa: Decimal = Field(default=ZERO, description="Frank copula parameter")

def __call__(self, u: FloatArrayLike, v: FloatArrayLike) -> FloatArrayLike:
Expand Down
1 change: 1 addition & 0 deletions quantflow/sp/dsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DSP(PoissonBase):

:param intensity: the stochastic intensity of the Poisson
"""

intensity: IntensityProcess = Field( # type ignore
default_factory=CIR, description="intensity process"
)
Expand Down
1 change: 1 addition & 0 deletions quantflow/sp/heston.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Heston(StochasticProcess1D):
d v_t = (a - \kappa v_t) dt + \nu \sqrt{v_t} dw^2_t
\rho dt = \E[dw^1 dw^2]
"""

variance_process: CIR = Field(default_factory=CIR, description="Variance process")
rho: float = Field(default=0, ge=-1, le=1, description="Correlation")

Expand Down
1 change: 1 addition & 0 deletions quantflow/sp/jump_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class JumpDiffusion(StochasticProcess1D, Generic[D]):
where N_t is a compound poisson process with intensity \lambda
and jump distribution D
"""

diffusion: WeinerProcess = Field(
default_factory=WeinerProcess, description="diffusion"
)
Expand Down
2 changes: 1 addition & 1 deletion quantflow/sp/poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def cdf_from_characteristic(
)
f[0] = c[0].real # type: ignore[index]
if simpson_rule:
result.append(a * simpson(f, frequency))
result.append(a * simpson(f, x=frequency))
else:
result.append(a * np.trapz(f, frequency))
pdf = np.maximum(np.diff(result, prepend=0), 0)
Expand Down
2 changes: 1 addition & 1 deletion quantflow/utils/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def utcnow() -> datetime:
return datetime.utcnow().replace(tzinfo=timezone.utc)
return datetime.now(timezone.utc)


def isoformat(date: str | date) -> str:
Expand Down
5 changes: 3 additions & 2 deletions quantflow/utils/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd
from numpy.random import normal
from pydantic import BaseModel, Field
from scipy.integrate import cumtrapz
from scipy.integrate import cumulative_trapezoid

from . import plot
from .bins import pdf as bins_pdf
Expand Down Expand Up @@ -68,7 +68,8 @@ def var(self) -> FloatArray:
def integrate(self) -> Paths:
"""Integrate paths"""
return self.__class__(
t=self.t, data=cumtrapz(self.data, dx=self.dt, axis=0, initial=0)
t=self.t,
data=cumulative_trapezoid(self.data, dx=self.dt, axis=0, initial=0),
)

def cross_section(self, t: float | None = None) -> FloatArray:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_heston.py → quantflow_tests/test_heston.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from quantflow.sp.heston import Heston, HestonJ
from tests.utils import characteristic_tests
from quantflow_tests.utils import characteristic_tests


@pytest.fixture
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/test_options.py → quantflow_tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
surface_from_inputs,
)
from quantflow.sp.heston import Heston
from tests.utils import has_plotly
from quantflow_tests.utils import has_plotly

a = np.asarray
CROSS_SECTIONS = 8
Expand All @@ -27,7 +27,7 @@ def heston() -> OptionPricer[Heston]:

@pytest.fixture
def vol_surface() -> VolSurface:
with open("tests/volsurface.json") as fp:
with open("quantflow_tests/volsurface.json") as fp:
return surface_from_inputs(VolSurfaceInputs(**json.load(fp)))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from quantflow.options.pricer import OptionPricer
from quantflow.sp.heston import HestonJ
from tests.utils import has_plotly
from quantflow_tests.utils import has_plotly


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ou.py → quantflow_tests/test_ou.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from quantflow.sp.bns import BNS
from quantflow.sp.ou import GammaOU, Vasicek
from tests.utils import characteristic_tests, analytical_tests
from quantflow_tests.utils import characteristic_tests, analytical_tests


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/test_poisson.py → quantflow_tests/test_poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from quantflow.sp.dsp import DSP
from quantflow.sp.poisson import CompoundPoissonProcess, PoissonProcess
from quantflow.utils.distributions import Exponential
from tests.utils import analytical_tests, characteristic_tests
from quantflow_tests.utils import analytical_tests, characteristic_tests


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/test_weiner.py → quantflow_tests/test_weiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from quantflow.sp.weiner import WeinerProcess
from quantflow.utils.paths import Paths
from tests.utils import characteristic_tests
from quantflow_tests.utils import characteristic_tests


@pytest.fixture
Expand Down
File renamed without changes.
File renamed without changes.
Empty file removed tests/__init__.py
Empty file.
Loading