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.

mlgrid(
  x,
  y = c("logret", "ret", "none"),
  dir = c("long", "short"),
  type = c("boolean", "numeric"),
  unique = TRUE
)

Arguments

x

an ichimoku object.

y

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

dir

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

type

[default 'boolean'] either 'boolean' or 'numeric'. '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.

unique

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

Value

A data.frame 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' parameter and trade direction are set as atrributes. To view these, use look on the returned object.

Details

The date-time index corresponds to when the indicator condition is met at the close for that period. The return is the single-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).

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.

Examples

cloud <- ichimoku(sample_ohlc_data, ticker = "TKR") grid <- mlgrid(cloud, y = "ret", dir = "short", type = "numeric") str(grid)
#> 'data.frame': 153 obs. of 38 variables: #> $ y : num -0.007246 0.000806 0.001614 -0.004819 0.002415 ... #> $ chikou_close : num -5.2 -3.4 -3.4 -3.8 -3.2 ... #> $ chikou_high : num -5.2 -4.5 -4 -3.9 -3.7 ... #> $ chikou_low : num -4.3 -3.1 -3 -3.3 -2.9 ... #> $ chikou_tenkan : num -3.2 -2.5 -3 -4.2 -3.8 ... #> $ chikou_kijun : num -1.55 -0.85 -0.75 -0.95 -0.35 ... #> $ chikou_senkouA : num 1.3 2 2.1 1.85 2.33 ... #> $ chikou_senkouB : num 0.4 1.1 1.2 1 1.6 ... #> $ chikou_cloudT : num 0.4 1.1 1.2 1 1.6 ... #> $ chikou_cloudB : num 1.3 2 2.1 1.85 2.33 ... #> $ close_tenkan : num 1.9 2.45 2.35 1.65 1.6 ... #> $ close_kijun : num -0.5 0.2 0.45 0.25 0.85 ... #> $ close_senkouA : num -2.38 -1.67 -1.88 -2.57 -2.08 ... #> $ close_senkouB : num -1.55 -0.85 -0.75 -0.95 -0.35 ... #> $ close_cloudT : num -2.38 -1.67 -1.88 -2.57 -2.08 ... #> $ close_cloudB : num -1.55 -0.85 -0.75 -0.95 -0.35 ... #> $ high_tenkan : num 2.3 2.45 2.55 1.85 1.8 ... #> $ high_kijun : num -0.1 0.2 0.65 0.45 1.05 ... #> $ high_senkouA : num -1.97 -1.67 -1.67 -2.38 -1.88 ... #> $ high_senkouB : num -1.15 -0.85 -0.55 -0.75 -0.15 ... #> $ high_cloudT : num -1.97 -1.67 -1.67 -2.38 -1.88 ... #> $ high_cloudB : num -1.15 -0.85 -0.55 -0.75 -0.15 ... #> $ low_tenkan : num 0.3 1.45 2.25 1.15 0.8 ... #> $ low_kijun : num -2.1 -0.8 0.35 -0.25 0.05 ... #> $ low_senkouA : num -3.97 -2.67 -1.97 -3.07 -2.88 ... #> $ low_senkouB : num -3.15 -1.85 -0.85 -1.45 -1.15 ... #> $ low_cloudT : num -3.97 -2.67 -1.97 -3.07 -2.88 ... #> $ low_cloudB : num -3.15 -1.85 -0.85 -1.45 -1.15 ... #> $ tenkan_kijun : num -2.4 -2.25 -1.9 -1.4 -0.75 ... #> $ tenkan_senkouA : num -4.27 -4.12 -4.22 -4.22 -3.67 ... #> $ tenkan_senkouB : num -3.45 -3.3 -3.1 -2.6 -1.95 ... #> $ tenkan_cloudT : num -4.27 -4.12 -4.22 -4.22 -3.67 ... #> $ tenkan_cloudB : num -3.45 -3.3 -3.1 -2.6 -1.95 ... #> $ kijun_senkouA : num -1.88 -1.88 -2.33 -2.83 -2.93 ... #> $ kijun_senkouB : num -1.05 -1.05 -1.2 -1.2 -1.2 ... #> $ kijun_cloudT : num -1.88 -1.88 -2.33 -2.83 -2.93 ... #> $ kijun_cloudB : num -1.05 -1.05 -1.2 -1.2 -1.2 ... #> $ senkouA_senkouB: num 0.825 0.825 1.125 1.625 1.725 ... #> - attr(*, "y")= chr "ret" #> - attr(*, "direction")= chr "short" #> - attr(*, "ticker")= chr "TKR"