ZenQuant.Helpers.Funding (zen_quant v0.2.0)

Copy Markdown View Source

Funding rate timing helpers for perpetual futures.

Pure functions for calculating time until next funding payment. Most perpetual futures exchanges use 8-hour funding cycles at 00:00, 08:00, and 16:00 UTC.

Example

ZenQuant.Helpers.Funding.next_funding()
# => 2.5 (hours until next funding)

ZenQuant.Helpers.Funding.next_funding_at()
# => ~U[2025-01-15 16:00:00Z]

Summary

Functions

Returns hours until the next funding time.

Returns the DateTime of the next funding time.

Returns the DateTime of the next funding time from a given DateTime.

Returns hours until the next funding time from a given DateTime.

Functions

next_funding()

@spec next_funding() :: float()

Returns hours until the next funding time.

Standard funding cycles are at 00:00, 08:00, and 16:00 UTC.

Example

ZenQuant.Helpers.Funding.next_funding()
# => 2.5 (hours until next funding)

next_funding_at()

@spec next_funding_at() :: DateTime.t()

Returns the DateTime of the next funding time.

Standard funding cycles are at 00:00, 08:00, and 16:00 UTC.

Example

ZenQuant.Helpers.Funding.next_funding_at()
# => ~U[2025-01-15 16:00:00Z]

next_funding_at_from(from)

@spec next_funding_at_from(DateTime.t()) :: DateTime.t()

Returns the DateTime of the next funding time from a given DateTime.

Example

past_time = ~U[2025-01-15 07:30:00Z]
ZenQuant.Helpers.Funding.next_funding_at_from(past_time)
# => ~U[2025-01-15 08:00:00Z]

next_funding_from(from)

@spec next_funding_from(DateTime.t()) :: float()

Returns hours until the next funding time from a given DateTime.

Useful for backtesting or working with historical data.

Example

past_time = ~U[2025-01-15 07:30:00Z]
ZenQuant.Helpers.Funding.next_funding_from(past_time)
# => 0.5 (30 minutes until 08:00)