CycleDuration#

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__()#

Methods

to_timedelta()

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

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.

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_4d

Run decide_trades() for every 4 days

cycle_7d

Run decide_trades() for every week

cycle_30d

Run decide_trades() for every month

cycle_unknown

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

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_4d = '4d'#

Run decide_trades() for every 4 days

cycle_7d = '7d'#

Run decide_trades() for every week

cycle_30d = '30d'#

Run decide_trades() for every month

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.

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]