1

I want to create a table in DolphinDB where each row is a dictionary storing the parameters for factor calculation.

The dictionary is of type (STRING, ANY), where the dictionary keys are parameter names and the dictionary values are the parameter values. Each dictionary value can be a scalar or a vector.

As the number of parameters might be different for each factor, and the parameter values may contain vectors of strings (so the data cannot be converted into array vectors), it is not feasible to store the data in table columns. Any good idea?

1 Answers1

1

DolphinDB currently does not support storing dictionary variables in a table, but you can use the function toStdJson to convert a dictionary into a STRING for storage. The strings can be converted back into dictionaries with parseExpr().eval().

config = dict(STRING, ANY)
config[`name] = `dmc
config[`desc] = "minute factor"
config[`upper] = [`oles, `macd]
config[`ParamKeys] = [`win,`high,`times,`range]
config[`ParamValues] = [3,10,20,[`abc,`adc]]
// convert a dictionary to string
config_string = toStdJson(config)
// convert a string to dictionary
config_dict = parseExpr(config_string).eval()

Note: In DolphinDB, the size limit for a single string is 64KB. If your parameter dictionary is large, you can split out the parameters with fixed data type and size to store them in separate columns.

For parameters whose values are string arrays, such as variable names containing only letters, numbers and underscores, consider concatenating the strings into a long string. Add a special character between the concatenated strings so you can split() them apart again later.

config[`ParamKeys]=[`win,`high,`times,`range]
// convert a string array to a long string
longString = concat(config[`ParamKeys], ",")
// split a string into an array of strings
stringArray = split(longString , ",")