quant.utils¶
quant.utils¶
Utils that may be used outside the quantlib package
-
class
quant.utils.
Localizer
(path)[源代码]¶ 把DataFrame缓存到本地hdf5文件中。通过设置key和const_key参数,可以设定需要跟踪哪些参数。
Examples
无参数
localilzer = Localizer('./.cache') @localizer.wrap('foo', const_key="foo") def foo(): return pd.DataFrame([[1,2,3], [3,4,5]])
由于hdf5文件需要key来定位数据,因此,对于没有参数的函数,需要给装饰器提供const_key参数方便保存
跟踪参数
localilzer = Localizer('./.cache') @localizer.wrap('zeros', keys=["length"]) def zeros(length): return pd.DataFrame(np.random.zeros(length, length))
通过设置keys=[“length”],缓存器可以根据传入的参数不同区分缓存内容。
Methods
wrap
(filename[, keys, const_key, format])装饰器,用来装饰要缓存结果的函数
-
class
quant.utils.
ConfigManager
(path='config.cfg')[源代码]¶ 配置项管理,解析配置文件,并允许配置项被命令行参数重写
Methods
add_argument
(*args, **kwargs)除了配置文件已有的参数外,新增命令行参数,与`argparse.ArgumentParser.add_argument`相同 items
()遍历键值对 keys
()列出所有可用的参数名 set_default
(key, value)Set the default of a setting item. set_value
(key, value)Set the value of a setting item. update
()从命令行参数中更新所有配置 get -
set_default
(key, value)[源代码]¶ Set the default of a setting item. This will overwrite the config file, but not the commandline arguments.
-
-
class
quant.utils.
HTML
(enable_highcharts=False, enable_bootstrap=True, enable_mathjax=False)[源代码]¶ Attributes: main
The current main element
Methods
append
(node)Append an element generate_table
(data[, caption, …])Generate a table highcharts
(name, data[, plot_type, options])Insert highcharts. series2json
(series)把pd.Series时间序列转换为json格式 col container html inline render row tab text use -
generate_table
(data, caption=None, show_headers=True, show_index=True, hover=True, bordered=True, striped=False, condensed=False, format='{:.2f}', **kwargs)[源代码]¶ Generate a table
Parameters: - data: pd.DataFrame
data to be converted to a table
- caption: str
caption to show, optional
- show_headers: bool, optional
whether to show the column names as first row
- show_index: bool, optional
whether to show the index as first column
- hover: bool, optional
table-hover class
- bordered: bool, optional
table-bordered class
- striped: bool, optional
table-striped class
- condensed: bool, optional
table-condensed class
- format: str, optional
the format to show the values
- kwargs
other attributes to be added to table
参见
pd.DataFrame.style
- Another way to generate beautiful html table from pd.DataFrame