# -*- coding: utf-8 -*-# 从 numpy 库中导入 exp 函数并重命名为 npExpfrom numpy import exp as npExp
# 从 numpy 库中导入 nan 常量并重命名为 npNaNfrom numpy import nan as npNaN
# 从 pandas 库中导入 Series 类from pandas import Series
# 从 pandas_ta.utils 模块中导入 get_offset 和 verify_series 函数from pandas_ta.utils import get_offset, verify_seriesdefalma(close, length=None, sigma=None, distribution_offset=None, offset=None,**kwargs):"""Indicator: Arnaud Legoux Moving Average (ALMA)"""# 验证参数# 将长度转换为整数,如果长度存在且大于 0;否则默认为 10length =int(length)if length and length >0else10# 将 sigma 转换为浮点数,如果 sigma 存在且大于 0;否则默认为 6.0sigma =float(sigma)if sigma and sigma >0else6.0# 将 distribution_offset 转换为浮点数,如果 distribution_offset 存在且大于 0;否则默认为 0.85distribution_offset =float(distribution_offset)if distribution_offset and distribution_offset >0else0.85# 验证 close 序列,长度为 lengthclose = verify_series(close, length)# 获取偏移量offset = get_offset(offset)# 如果 close 为空,返回空if close isNone:return# 预先计算m = distribution_offset *(length -1)s = length / sigmawtd =list(range(length))for i inrange(0, length):# 计算权重(窗口)wtd[i]= npExp(-1*((i - m)*(i - m))/(2* s * s))# 计算结果# 初始化结果为长度-1个 NaN 和 1 个 0 组成的列表result =[npNaN for _ inrange(0, length -1)]+[0]for i inrange(length, close.size):window_sum =0cum_sum =0for j inrange(0, length):# 计算窗口和window_sum = window_sum + wtd[j]* close.iloc[i - j]# 计算累积和cum_sum = cum_sum + wtd[j]# 计算 ALMAalmean = window_sum / cum_sum# 如果 i 等于长度,则将结果列表追加 NaN,否则追加 almeanresult.append(npNaN)if i == length else result.append(almean)# 创建 ALMA Series 对象alma = Series(result, index=close.index)# 处理偏移if offset !=0:alma = alma.shift(offset)# 处理填充if"fillna"in kwargs:alma.fillna(kwargs["fillna"], inplace=True)if"fill_method"in kwargs:alma.fillna(method=kwargs["fill_method"], inplace=True)# 名称和分类alma.name =f"ALMA_{length}_{sigma}_{distribution_offset}"alma.category ="overlap"return alma# 为 alma 函数添加文档字符串
alma.__doc__ = \
"""Arnaud Legoux Moving Average (ALMA)The ALMA moving average uses the curve of the Normal (Gauss) distribution, which
can be shifted from 0 to 1. This allows regulating the smoothness and high
sensitivity of the indicator. Sigma is another parameter that is responsible for
the shape of the curve coefficients. This moving average reduces lag of the data
in conjunction with smoothing to reduce noise.Implemented for Pandas TA by rengel8 based on the source provided below.Sources:https://www.prorealcode.com/prorealtime-indicators/alma-arnaud-legoux-moving-average/Calculation:refer to provided sourceArgs:close (pd.Series): Series of 'close'slength (int): It's period, window size. Default: 10sigma (float): Smoothing value. Default 6.0distribution_offset (float): Value to offset the distribution min 0(smoother), max 1 (more responsive). Default 0.85offset (int): How many periods to offset the result. Default: 0Kwargs:fillna (value, optional): pd.DataFrame.fillna(value)fill_method (value, optional): Type of fill methodReturns:"""# 创建一个 Pandas Series 对象,表示生成了一个新的特征# 这是一个空的字符串,通常用作多行注释的起始
.\pandas-ta\pandas_ta\overlap\dema.py
# -*- coding: utf-8 -*-# 导入 ema 函数from.ema import ema
# 导入 Imports 模块from pandas_ta import Imports
# 导入 get_offset 和 verify_series 函数from pandas_ta.utils import get_offset, verify_series# 定义 dema 函数,计算 Double Exponential Moving Average (DEMA)defdema(close, length=None, talib=None, offset=None,**kwargs):"""Indicator: Double Exponential Moving Average (DEMA)"""# 验证参数# 如果 length 存在且大于 0,则将其转换为整数,否则设为默认值 10length =int(length)if length and length >0else10# 验证 close 数据类型为 Series,并且长度符合要求close = verify_series(close, length)# 获取 offset 值offset = get_offset(offset)# 判断是否使用 talib 模式mode_tal =bool(talib)ifisinstance(talib,bool)elseTrue# 如果 close 为空,则返回空值if close isNone:return# 计算结果if Imports["talib"]and mode_tal:# 如果导入了 talib 并且使用 talib 模式,则调用 talib 中的 DEMA 函数from talib import DEMAdema = DEMA(close, length)else:# 否则,分别计算两个 EMA 值ema1 = ema(close=close, length=length)ema2 = ema(close=ema1, length=length)# 计算 DEMA 值dema =2* ema1 - ema2# 对结果进行偏移if offset !=0:dema = dema.shift(offset)# 处理填充值if"fillna"in kwargs:dema.fillna(kwargs["fillna"], inplace=True)if"fill_method"in kwargs:dema.fillna(method=kwargs["fill_method"], inplace=True)# 设置指标名称和类别dema.name =f"DEMA_{length}"dema.category ="overlap"return dema# 设置 dema 函数的文档字符串
dema.__doc__ = \
"""Double Exponential Moving Average (DEMA)The Double Exponential Moving Average attempts to a smoother average with less
lag than the normal Exponential Moving Average (EMA).Sources:https://www.tradingtechnologies.com/help/x-study/technical-indicator-definitions/double-exponential-moving-average-dema/Calculation:Default Inputs:length=10EMA = Exponential Moving Averageema1 = EMA(close, length)ema2 = EMA(ema1, length)DEMA = 2 * ema1 - ema2Args:close (pd.Series): Series of 'close'slength (int): It's period. Default: 10talib (bool): If TA Lib is installed and talib is True, Returns the TA Libversion. Default: Trueoffset (int): How many periods to offset the result. Default: 0Kwargs:fillna (value, optional): pd.DataFrame.fillna(value)fill_method (value, optional): Type of fill methodReturns:pd.Series: New feature generated.
"""
什么是上位机?
上位机(SCADA,Supervisory Control and Data Acquisition)是一种软件系统,用于监控和控制工业过程中的设备。它通常与传感器、执行器和其他自动化设备一起工作,以实时地监视过程状态、收集数…
1. 再谈构造函数
1.1 构造函数体赋值
在创建对象时,编译器通过调用构造函数,给对象中各个成员变量一个合适的初始值。
class Date
{
public:Date(int year, int month, int day){_year year;_month month;_day day;}
private:int _year;int _mont…