Skip to contents

Event Helpers: fg_signal_to_events

Usage

fg_signal_to_events(signal_df, colormap)

Arguments

signal_df

A two-column data.frame with first being a date and second being any (factor-like) signal parameter.

colormap

A two column data.frame with the first being the possible signal (see Example) and the second a color. description

Value

data.table suitable for passing into fgts_dygraph() via the event_ds parameter

Details

This helper applies run-length encoding to match the signal in signal_df to the color in colormap

Examples

# A simple moving average strategy with threshold
require(data.table)
ma_signal<-eqtypx[,.(date,sig=cut(frollmean(EEM,5)-frollmean(EEM,20),
                    c(-10,-0.5,0.5,10),labels=c("long","flat","short")),EEM)]
colormap<-data.frame(sig=c("long","flat","short"),color=c("#f56462","white","#6161ff"))
fgts_dygraph(eqtypx[,.(date,EEM)],event_ds=fg_signal_to_events(ma_signal,colormap),
    dtstartfrac=0.8,roller=1,title="5/20 MA positions")