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]) 装饰器,用来装饰要缓存结果的函数
wrap(filename, keys=None, const_key=None, format='fixed')[源代码]

装饰器,用来装饰要缓存结果的函数

Parameters:
filename: str

缓存到的文件名(无需后缀名)

keys: List[str]

需要跟踪的参数名

const_key: str

基础键名

format: {‘fixed’, ‘table’}

详见pd.DataFrame.to_hdf

::

See pd.DataFrame.to_hdf()

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  
add_argument(*args, **kwargs)[源代码]

除了配置文件已有的参数外,新增命令行参数,与`argparse.ArgumentParser.add_argument`相同

items()[源代码]

遍历键值对

keys()[源代码]

列出所有可用的参数名

set_default(key, value)[源代码]

Set the default of a setting item. This will overwrite the config file, but not the commandline arguments.

set_value(key, value)[源代码]

Set the value of a setting item. This will overwrite the config file and commandline arguments.

update()[源代码]

从命令行参数中更新所有配置

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
highcharts(name, data, plot_type=None, options=None, **kwargs)[源代码]

Insert highcharts.

Parameters:
name: str

Name of the chart.

data: pd.DataFrame

data to be converted to chart

plot_type: dict

type to be plotted

options: dict

other options to pass to highcharts

static series2json(series)[源代码]

把pd.Series时间序列转换为json格式

quant.utils.calendar

class quant.utils.calendar.TradingCalendar[源代码]

中国金融市场交易日历

Attributes:
TradingDay

根据获取的节假日信息生成pd.tseries.offsets.CustomBusinessDay对象

holidays

中国A股市场休市日期

Methods

get_holidays  
TradingDay

根据获取的节假日信息生成pd.tseries.offsets.CustomBusinessDay对象

holidays

中国A股市场休市日期

type: List[str]