mlgrid: mlgrid Numeric Representation

View source: R/mltools.R

mlgridR Documentation

mlgrid Numeric Representation


Create a grid of ichimoku indicator conditions and next period returns. The grid facilitates the comparison of strategy returns and provides a basis for use in machine learning applications. Translates the visual representation of the relationship between cloud chart elements into a numerical format for further analysis.


  y = c("logret", "ret", "none"),
  k = 1L,
  dir = c("long", "short"),
  type = c("boolean", "numeric", "z-score"),
  format = c("dataframe", "matrix"),
  unique = TRUE



an ichimoku object.


[default 'logret'] choose target variable 'logret' (log returns), 'ret' (discrete returns), or 'none'.


[default 1L] number of periods time horizon over which to calculate target variable 'y'.


[default 'long'] trade direction, either 'long' or 'short'.


[default 'boolean'] choose 'boolean', 'numeric' or 'z-score'. 'boolean' creates a grid of dummy variables for ichimoku indicator conditions of the form 1 if c1 > c2, 0 otherwise. 'numeric' creates a grid of the numeric difference c1 - c2. 'z-score' standardises the numeric grid by the mean and standard deviation of each feature.


[default 'dataframe'] select either 'dataframe' or 'matrix' for the format of returned object.


[default TRUE] to return only unique combinations of c1 and c2. Set to FALSE to return both c1 > c2 and c2 > c1.


The date-time index corresponds to when the indicator condition is met at the close for that period. The return is the k-period return achieved by transacting at the immediately following opening price until the next opening price.

Only valid combinations are included. This excludes any combination involving 'open' as it is in effect a lagged indicator and not contemporaneous. The following trivial or highly-collinear pairs are also excluded: (high, close), (low, close), (low, high), (cloudTop, Senkou A), (cloudBase, senkou A), (cloudTop, senkouB), (cloudBase, senkouB), (cloudBase, cloudTop).


A data.frame or matrix in a 'tidy' format with one observation per row and one feature per column with the target 'y' as the first column (unless set to 'none').

The 'y' and 'k' parameters, trade direction and grid type are set as attributes. To view these, use look on the returned object.

Further Details

Please refer to the strategies vignette by calling: vignette("strategies", package = "ichimoku")

See Also

autostrat which uses mlgrid() to enumerate all valid return combinations.

relative which uses mlgrid() to relate the latest observed numeric representation to historical values.


cloud <- ichimoku(sample_ohlc_data, ticker = "TKR")
grid <- mlgrid(cloud, y = "ret", k = 2, dir = "short", type = "z-score")

ichimoku documentation built on May 23, 2022, 9:05 a.m.