.\pandas-ta\docs\conf.py
# -*- coding: utf-8 -*- # # Configuration file for the Sphinx documentation builder. # # This file does only contain a selection of the most common options. For a # full list see the documentation: # http://www.sphinx-doc.org/en/master/config # -- Path setup -------------------------------------------------------------- # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # # import os # import sys # sys.path.insert(0, os.path.abspath('.')) # -- Project information ----------------------------------------------------- # 设置项目名称为 "pandas_ta" project = "pandas_ta" # 版权信息为 "2019, Kevin Johnson" copyright = "2019, Kevin Johnson" # 作者为 "Kevin Johnson" author = "Kevin Johnson" # The short X.Y version # 设置版本号为 "0.0.1" version = "0.0.1" # The full version, including alpha/beta/rc tags # 设置发布版本为 "alpha" release = "alpha" # -- General configuration --------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. # # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. # 添加 Sphinx 扩展模块的名称 extensions = [ "sphinx.ext.todo", "sphinx.ext.mathjax", "sphinx.ext.viewcode", ] # Add any paths that contain templates here, relative to this directory. # 添加包含模板的路径 templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] # 源文件的后缀名 source_suffix = ".rst" # The master toctree document. # 主目录文档 master_doc = "index" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. # 内容自动生成的语言 language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. # 忽略查找源文件时匹配的文件和目录的模式 exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # The name of the Pygments (syntax highlighting) style to use. # 使用的 Pygments(语法高亮)样式 pygments_style = None # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # # 设置 HTML 和 HTML 帮助页面使用的主题 html_theme = "alabaster" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # # html_theme_options = {} # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". # 添加包含自定义静态文件(如样式表)的路径 html_static_path = ["_static"] # Custom sidebar templates, must be a dictionary that maps document names # -- Options for HTML output ---------------------------------------------- # HTML 文档输出的选项 # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # # html_theme = "alabaster" # # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # # html_theme_options = {} # The name for this set of Sphinx documents. If None, it defaults to # "<project> v<release> documentation". # # html_title = None # A shorter title for the navigation bar. Default is the same as html_title. # # html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. # # html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # # html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". # # html_static_path = ["_static"] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. # # html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. # # html_last_updated_fmt = "%b %d, %Y" # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. # # html_use_smartypants = True # Custom sidebar templates, must be a dictionary that maps document names # to template names. # # The default sidebars (for documents that don't match any pattern) are # defined by theme itself. Builtin themes are using these templates by # default: ``['localtoc.html', 'relations.html', 'sourcelink.html', # 'searchbox.html']``. # # html_sidebars = {} # -- Options for HTMLHelp output --------------------------------------------- # Output file base name for HTML help builder. # # htmlhelp_basename = "pandas_tadoc" # -- Options for LaTeX output ------------------------------------------------ # LaTeX 文档输出的选项 latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. # # 'preamble': '', # Latex figure (float) alignment # # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). # # latex_documents = [ # ( # master_doc, # "pandas_ta.tex", # "pandas\\_ta Documentation", # "Kevin Johnson", # "manual", # ), # ] # -- Options for manual page output ------------------------------------------ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). # # man_pages = [(master_doc, "pandas_ta", "pandas_ta Documentation", [author], 1)] # -- Options for Texinfo output ---------------------------------------------- # Texinfo 文档输出的选项 # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) # # texinfo_documents = [ # ( # master_doc, # "pandas_ta", # "pandas_ta Documentation", # author, # "pandas_ta", # "One line description of project.", # "Miscellaneous", # ), # ] # -- Options for Epub output ------------------------------------------------- # ePub 文档输出的选项 # Bibliographic Dublin Core info. # # epub_title = project # The unique identifier of the text. This can be a ISBN number # or the project homepage. # # epub_identifier = '' # A unique identification for the text. # # epub_uid = '' # A list of files that should not be packed into the epub file. # # epub_exclude_files = ["search.html"] # -- Extension configuration ------------------------------------------------- # 扩展配置的选项 # -- Options for todo extension ---------------------------------------------- # If true, `todo` and `todoList` produce output, else they produce nothing. # # todo_include_todos = True
.\pandas-ta\examples\ni.py
# -*- coding: utf-8 -*- # 从pandas_ta.overlap导入simple moving average函数 from pandas_ta.overlap import sma # 从pandas_ta.utils导入获取偏移量的函数和验证序列的函数 from pandas_ta.utils import get_offset, verify_series # 标准定义你的自定义指标函数(包括文档) def ni(close, length=None, centered=False, offset=None, **kwargs): """ Example indicator ni """ # 验证参数 length = int(length) if length and length > 0 else 20 close = verify_series(close, length) offset = get_offset(offset) # 如果close为空,则返回空值 if close is None: return # 计算结果 t = int(0.5 * length) + 1 # 计算简单移动平均线 ma = sma(close, length) ni = close - ma.shift(t) # 如果设置了centered,则将ni进行居中调整 if centered: ni = (close.shift(t) - ma).shift(-t) # 偏移 if offset != 0: ni = ni.shift(offset) # 处理填充 if "fillna" in kwargs: ni.fillna(kwargs["fillna"], inplace=True) if "fill_method" in kwargs: ni.fillna(method=kwargs["fill_method"], inplace=True) # 给新的特征命名和分类 ni.name = f"ni_{length}" ni.category = "trend" return ni # 设置自定义指标函数的文档字符串 ni.__doc__ = \ """Example indicator (NI) Is an indicator provided solely as an example Sources: https://github.com/twopirllc/pandas-ta/issues/264 Calculation: Default Inputs: length=20, centered=False SMA = Simple Moving Average t = int(0.5 * length) + 1 ni = close.shift(t) - SMA(close, length) if centered: ni = ni.shift(-t) Args: close (pd.Series): Series of 'close's length (int): It's period. Default: 20 centered (bool): Shift the ni back by int(0.5 * length) + 1. Default: False offset (int): How many periods to offset the result. Default: 0 Kwargs: fillna (value, optional): pd.DataFrame.fillna(value) fill_method (value, optional): Type of fill method Returns: pd.Series: New feature generated. """ # 定义匹配类方法 def ni_method(self, length=None, offset=None, **kwargs): # 从self中获取'close'列 close = self._get_column(kwargs.pop("close", "close")) # 调用ni函数计算指标结果 result = ni(close=close, length=length, offset=offset, **kwargs) # 对结果进行后处理 return self._post_process(result, **kwargs)
PandasTA 源码解析(一)(2)https://developer.aliyun.com/article/1505518