CycleDuration#

API documentation for tradeexecutor.strategy.cycle.CycleDuration Python class in Trading Strategy framework.

class CycleDuration[source]#

Bases: Enum

Strategy cycle duration options.

This enum defines what strategy cycle durations backtesting and live testing engine supports.

It is also the value you can enter as trading_strategy_cycle option for your strategies.

All cycles are aligned to the wall clock time. E.g. 24h cycle is always run at 00:00.

See Strategy cycle for more information.

__init__(*args, **kwds)#

Methods

to_timedelta()

Get the duration of the strategy cycle as Python timedelta object.

to_pandas_timedelta()

to_timebucket()

Convert to trading-strategy client format.

get_yearly_periods()

How many decision cycle periods a year has.

from_timebucket(bucket)

Convert from OHLCV time frame.

get_timing_offset()

What's the base offset for this cycle.

Attributes

cycle_1s

Run decide_trades() one second

cycle_1m

Run decide_trades() every minute

cycle_5m

Run decide_trades() every 5 minutes

cycle_15m

Run decide_trades() every 15 minutes

cycle_30m

Run decide_trades() every 30 minutes

cycle_1h

Run decide_trades() every hour

cycle_2h

Run decide_trades() every 2 hours

cycle_4h

Run decide_trades() every 4 hours

cycle_6h

Run decide_trades() every 6 hours

cycle_8h

Run decide_trades() for every 8 hours

cycle_10h

Run decide_trades() for every 10 hours

cycle_12h

Run decide_trades() for every 12 hours

cycle_16h

Run decide_trades() for every 16 hours

cycle_1d

Run decide_trades() for every 24h hours

cycle_2d

Run decide_trades() for every 2 days

cycle_3d

Run decide_trades() for every 2 days

cycle_4d

Run decide_trades() for every 4 days

cycle_7d

Run decide_trades() for every week

cycle_10d

Run decide_trades() for 2 weeks cycl

cycle_14d

Run decide_trades() for 2 weeks cycl

cycle_30d

Run decide_trades() for every month

cycle_97h

Random cycle that's prime number in hours

cycle_unknown

Don't really know or care about the trade cycle duration.

s1

Alias to match TimeBucket

m1

Alias to match TimeBucket

m15

Alias to match TimeBucket

h1

Alias to match TimeBucket

h4

Alias to match TimeBucket

d1

Alias to match TimeBucket

d7

Alias to match TimeBucket

unknown

Alias

cycle_1s = '1s'#

Run decide_trades() one second

Only used in unit testing. See strategies/test_only_/enzymy_end_to_end.py.

cycle_1m = '1m'#

Run decide_trades() every minute

cycle_5m = '5m'#

Run decide_trades() every 5 minutes

cycle_15m = '15m'#

Run decide_trades() every 15 minutes

cycle_30m = '30m'#

Run decide_trades() every 30 minutes

cycle_1h = '1h'#

Run decide_trades() every hour

cycle_2h = '2h'#

Run decide_trades() every 2 hours

cycle_4h = '4h'#

Run decide_trades() every 4 hours

cycle_6h = '6h'#

Run decide_trades() every 6 hours

cycle_8h = '8h'#

Run decide_trades() for every 8 hours

cycle_10h = '10h'#

Run decide_trades() for every 10 hours

cycle_12h = '12h'#

Run decide_trades() for every 12 hours

cycle_16h = '16h'#

Run decide_trades() for every 16 hours

cycle_1d = '1d'#

Run decide_trades() for every 24h hours

cycle_2d = '2d'#

Run decide_trades() for every 2 days

cycle_3d = '3d'#

Run decide_trades() for every 2 days

cycle_4d = '4d'#

Run decide_trades() for every 4 days

cycle_7d = '7d'#

Run decide_trades() for every week

cycle_10d = '10d'#

Run decide_trades() for 2 weeks cycl

cycle_14d = '14d'#

Run decide_trades() for 2 weeks cycl

cycle_30d = '30d'#

Run decide_trades() for every month

cycle_97h = '97h'#

Random cycle that’s prime number in hours

cycle_unknown = 'unknown'#

Don’t really know or care about the trade cycle duration.

Used when doing a simulated execution loop with set_up_simulated_execution_loop and where the time is ticked through manually by producing new blocks with EthereumTester chain.

s1 = '1s'#

Alias to match TimeBucket

m1 = '1m'#

Alias to match TimeBucket

m15 = '15m'#

Alias to match TimeBucket

h1 = '1h'#

Alias to match TimeBucket

h4 = '4h'#

Alias to match TimeBucket

d1 = '1d'#

Alias to match TimeBucket

d7 = '7d'#

Alias to match TimeBucket

unknown = 'unknown'#

Alias

to_timedelta()[source]#

Get the duration of the strategy cycle as Python timedelta object.

Return type:

timedelta

to_timebucket()[source]#

Convert to trading-strategy client format.

TODO: Try to avoid tightly coupling and leaking trading-strategy client here.

Unlike TimeBucket, CycleDuration may have “unknown” value that is presented by None

Return type:

Optional[TimeBucket]

get_yearly_periods()[source]#

How many decision cycle periods a year has.

This metric is used to calculate Sharpe, other metrics.

See tradeexecutor.analysis.advanced_metrics.calculate_advanced_metrics() for more information.

Return type:

float

static from_timebucket(bucket)[source]#

Convert from OHLCV time frame.

Parameters:

bucket (TimeBucket) –

Return type:

Optional[CycleDuration]

get_timing_offset()[source]#

What’s the base offset for this cycle.

Return type:

str | pandas._libs.tslibs.offsets.DateOffset