首页 > 编程语言 >PandasTA 源码解析(二十一)

PandasTA 源码解析(二十一)

时间:2024-04-15 13:55:44浏览次数:19  
标签:PandasTA Series self 二十一 源码 result close pandas ta

.\pandas-ta\tests\test_indicator_performance.py

# 导入所需的模块和函数
from .config import sample_data
from .context import pandas_ta
# 从 unittest 模块中导入 TestCase 类
from unittest import TestCase
# 从 pandas 模块中导入 Series 类
from pandas import Series

# 定义测试类 TestPerformace,继承自 TestCase 类
class TestPerformace(TestCase):
    # 在所有测试方法执行之前执行的设置方法
    @classmethod
    def setUpClass(cls):
        # 从配置文件中获取示例数据
        cls.data = sample_data
        # 获取示例数据中的 close 列作为测试数据
        cls.close = cls.data["close"]
        # 判断 close 列是否大于其简单移动平均值的 Series 对象,并转换为整数类型
        cls.islong = (cls.close > pandas_ta.sma(cls.close, length=8)).astype(int)
        # 计算 close 列的非累积百分比收益率的 Series 对象
        cls.pctret = pandas_ta.percent_return(cls.close, cumulative=False)
        # 计算 close 列的非累积对数收益率的 Series 对象
        cls.logret = pandas_ta.percent_return(cls.close, cumulative=False)

    # 在所有测试方法执行之后执行的清理方法
    @classmethod
    def tearDownClass(cls):
        # 清理示例数据、close 列、islong 列、pctret 列和 logret 列
        del cls.data
        del cls.close
        del cls.islong
        del cls.pctret
        del cls.logret

    # 设置测试方法前的准备工作,此处不需要执行任何操作,因此留空
    def setUp(self): pass

    # 设置测试方法后的清理工作,此处不需要执行任何操作,因此留空
    def tearDown(self): pass

    # 测试对数收益率计算的方法
    def test_log_return(self):
        # 调用对数收益率计算函数,获取结果
        result = pandas_ta.log_return(self.close)
        # 断言结果类型为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "LOGRET_1"
        self.assertEqual(result.name, "LOGRET_1")

    # 测试累积对数收益率计算的方法
    def test_cum_log_return(self):
        # 调用累积对数收益率计算函数,获取结果
        result = pandas_ta.log_return(self.close, cumulative=True)
        # 断言结果类型为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "CUMLOGRET_1"
        self.assertEqual(result.name, "CUMLOGRET_1")

    # 测试百分比收益率计算的方法
    def test_percent_return(self):
        # 调用百分比收益率计算函数,获取结果
        result = pandas_ta.percent_return(self.close, cumulative=False)
        # 断言结果类型为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "PCTRET_1"
        self.assertEqual(result.name, "PCTRET_1")

    # 测试累积百分比收益率计算的方法
    def test_cum_percent_return(self):
        # 调用累积百分比收益率计算函数,获取结果
        result = pandas_ta.percent_return(self.close, cumulative=True)
        # 断言结果的名称为 "CUMPCTRET_1"
        self.assertEqual(result.name, "CUMPCTRET_1")

.\pandas-ta\tests\test_indicator_statistics.py

# 从.config模块中导入error_analysis,sample_data,CORRELATION,CORRELATION_THRESHOLD,VERBOSE变量
# 从.context模块中导入pandas_ta模块
from .config import error_analysis, sample_data, CORRELATION, CORRELATION_THRESHOLD, VERBOSE
from .context import pandas_ta

# 从unittest模块中导入skip,TestCase类
from unittest import skip, TestCase
# 导入pandas的测试模块
import pandas.testing as pdt
# 从pandas模块中导入DataFrame,Series类
from pandas import DataFrame, Series
# 导入talib库,并重命名为tal
import talib as tal

# 定义测试Statistics类,继承自TestCase类
class TestStatistics(TestCase):
    # 类方法,用于设置测试类的初始状态
    @classmethod
    def setUpClass(cls):
        # 将sample_data赋值给类属性data
        cls.data = sample_data
        # 将data的列名转换为小写
        cls.data.columns = cls.data.columns.str.lower()
        # 分别将open、high、low、close列赋值给对应的类属性
        cls.open = cls.data["open"]
        cls.high = cls.data["high"]
        cls.low = cls.data["low"]
        cls.close = cls.data["close"]
        # 如果data的列中包含volume列,则将volume列赋值给类属性volume
        if "volume" in cls.data.columns:
            cls.volume = cls.data["volume"]

    # 类方法,用于清理测试类的状态
    @classmethod
    def tearDownClass(cls):
        # 删除类属性open、high、low、close
        del cls.open
        del cls.high
        del cls.low
        del cls.close
        # 如果类中有volume属性,则删除volume属性
        if hasattr(cls, "volume"):
            del cls.volume
        # 删除类属性data
        del cls.data

    # 空的setUp方法
    def setUp(self): pass

    # 空的tearDown方法
    def tearDown(self): pass

    # 测试entropy方法
    def test_entropy(self):
        # 调用pandas_ta模块中的entropy方法,计算close列的熵
        result = pandas_ta.entropy(self.close)
        # 断言result的类型为Series
        self.assertIsInstance(result, Series)
        # 断言result的名称为"ENTP_10"
        self.assertEqual(result.name, "ENTP_10")

    # 测试kurtosis方法
    def test_kurtosis(self):
        # 调用pandas_ta模块中的kurtosis方法,计算close列的峰度
        result = pandas_ta.kurtosis(self.close)
        # 断言result的类型为Series
        self.assertIsInstance(result, Series)
        # 断言result的名称为"KURT_30"
        self.assertEqual(result.name, "KURT_30")

    # 测试mad方法
    def test_mad(self):
        # 调用pandas_ta模块中的mad方法,计算close列的绝对平均偏差
        result = pandas_ta.mad(self.close)
        # 断言result的类型为Series
        self.assertIsInstance(result, Series)
        # 断言result的名称为"MAD_30"
        self.assertEqual(result.name, "MAD_30")

    # 测试median方法
    def test_median(self):
        # 调用pandas_ta模块中的median方法,计算close列的中位数
        result = pandas_ta.median(self.close)
        # 断言result的类型为Series
        self.assertIsInstance(result, Series)
        # 断言result的名称为"MEDIAN_30"
        self.assertEqual(result.name, "MEDIAN_30")

    # 测试quantile方法
    def test_quantile(self):
        # 调用pandas_ta模块中的quantile方法,计算close列的分位数
        result = pandas_ta.quantile(self.close)
        # 断言result的类型为Series
        self.assertIsInstance(result, Series)
        # 断言result的名称为"QTL_30_0.5"
        self.assertEqual(result.name, "QTL_30_0.5")

    # 测试skew方法
    def test_skew(self):
        # 调用pandas_ta模块中的skew方法,计算close列的偏度
        result = pandas_ta.skew(self.close)
        # 断言result的类型为Series
        self.assertIsInstance(result, Series)
        # 断言result的名称为"SKEW_30"
        self.assertEqual(result.name, "SKEW_30")

    # 测试stdev方法
    def test_stdev(self):
        # 调用pandas_ta模块中的stdev方法,计算close列的标准差(talib=False)
        result = pandas_ta.stdev(self.close, talib=False)
        # 断言result的类型为Series
        self.assertIsInstance(result, Series)
        # 断言result的名称为"STDEV_30"
        self.assertEqual(result.name, "STDEV_30")

        # 尝试使用tal.STDDEV方法计算close列的标准差
        try:
            # 期望的结果使用tal.STDDEV方法计算
            expected = tal.STDDEV(self.close, 30)
            # 断言result与expected相等,忽略名称检查
            pdt.assert_series_equal(result, expected, check_names=False)
        except AssertionError:
            try:
                # 如果断言失败,计算result与expected之间的相关性
                corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
                # 断言相关性大于阈值CORRELATION_THRESHOLD
                self.assertGreater(corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 如果出现异常,则调用error_analysis函数,并传递result,CORRELATION,异常信息ex
                error_analysis(result, CORRELATION, ex)

        # 重新调用pandas_ta模块中的stdev方法,计算close列的标准差
        result = pandas_ta.stdev(self.close)
        # 断言result的类型为Series
        self.assertIsInstance(result, Series)
        # 断言result的名称为"STDEV_30"
        self.assertEqual(result.name, "STDEV_30")
    # 测试 TOS_STDEVALL 函数
    def test_tos_sdtevall(self):
        # 调用 TOS_STDEVALL 函数,计算标准差
        result = pandas_ta.tos_stdevall(self.close)
        # 断言结果为 DataFrame 类型
        self.assertIsInstance(result, DataFrame)
        # 断言结果列名为 "TOS_STDEVALL"
        self.assertEqual(result.name, "TOS_STDEVALL")
        # 断言结果列数为 7
        self.assertEqual(len(result.columns), 7)

        # 调用 TOS_STDEVALL 函数,计算长度为 30 的标准差
        result = pandas_ta.tos_stdevall(self.close, length=30)
        # 断言结果为 DataFrame 类型
        self.assertIsInstance(result, DataFrame)
        # 断言结果列名为 "TOS_STDEVALL_30"
        self.assertEqual(result.name, "TOS_STDEVALL_30")
        # 断言结果列数为 7
        self.assertEqual(len(result.columns), 7)

        # 调用 TOS_STDEVALL 函数,计算长度为 30,标准差为 1 和 2 的标准差
        result = pandas_ta.tos_stdevall(self.close, length=30, stds=[1, 2])
        # 断言结果为 DataFrame 类型
        self.assertIsInstance(result, DataFrame)
        # 断言结果列名为 "TOS_STDEVALL_30"
        self.assertEqual(result.name, "TOS_STDEVALL_30")
        # 断言结果列数为 5
        self.assertEqual(len(result.columns), 5)

    # 测试 Variance 函数
    def test_variance(self):
        # 调用 Variance 函数,计算方差
        result = pandas_ta.variance(self.close, talib=False)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果列名为 "VAR_30"
        self.assertEqual(result.name, "VAR_30")

        try:
            # 使用 Talib 计算期望结果
            expected = tal.VAR(self.close, 30)
            # 断言结果与期望结果相等
            pdt.assert_series_equal(result, expected, check_names=False)
        except AssertionError:
            try:
                # 计算结果与期望结果的相关性
                corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
                # 断言相关性大于阈值
                self.assertGreater(corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 分析错误
                error_analysis(result, CORRELATION, ex)

        # 调用 Variance 函数,默认使用 Talib 计算,计算方差
        result = pandas_ta.variance(self.close)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果列名为 "VAR_30"
        self.assertEqual(result.name, "VAR_30")

    # 测试 Z-Score 函数
    def test_zscore(self):
        # 调用 Z-Score 函数,计算 Z 分数
        result = pandas_ta.zscore(self.close)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果列名为 "ZS_30"
        self.assertEqual(result.name, "ZS_30")

.\pandas-ta\tests\test_indicator_trend.py

# 从相对路径的config模块中导入error_analysis、sample_data、CORRELATION、CORRELATION_THRESHOLD和VERBOSE变量
from .config import error_analysis, sample_data, CORRELATION, CORRELATION_THRESHOLD, VERBOSE
# 从context模块中导入pandas_ta对象
from .context import pandas_ta

# 导入TestCase类和skip函数从unittest模块中
from unittest import TestCase, skip
# 导入pandas测试模块,并用pdt别名引用
import pandas.testing as pdt
# 从pandas模块中导入DataFrame和Series类
from pandas import DataFrame, Series

# 导入talib模块,并用tal别名引用
import talib as tal

# 定义TestTrend类,继承自TestCase类
class TestTrend(TestCase):
    # 在类方法setUpClass中设置测试所需的数据
    @classmethod
    def setUpClass(cls):
        # 将sample_data赋值给cls.data,然后将列名转换为小写
        cls.data = sample_data
        cls.data.columns = cls.data.columns.str.lower()
        # 将open列、high列、low列、close列分别赋值给cls.open、cls.high、cls.low、cls.close
        cls.open = cls.data["open"]
        cls.high = cls.data["high"]
        cls.low = cls.data["low"]
        cls.close = cls.data["close"]
        # 如果数据中存在volume列,则将其赋值给cls.volume
        if "volume" in cls.data.columns:
            cls.volume = cls.data["volume"]

    # 在类方法tearDownClass中清理测试所需的数据
    @classmethod
    def tearDownClass(cls):
        # 删除cls.open、cls.high、cls.low、cls.close四个变量的引用
        del cls.open
        del cls.high
        del cls.low
        del cls.close
        # 如果cls中存在volume属性,则删除该属性
        if hasattr(cls, "volume"):
            del cls.volume
        # 删除cls.data变量的引用
        del cls.data

    # 在setUp方法中初始化测试环境
    def setUp(self): pass
    # 在tearDown方法中清理测试环境
    def tearDown(self): pass

    # 定义测试ADX指标的方法
    def test_adx(self):
        # 调用pandas_ta.adx函数计算ADX指标,指定talib参数为False
        result = pandas_ta.adx(self.high, self.low, self.close, talib=False)
        # 断言result对象为DataFrame类型
        self.assertIsInstance(result, DataFrame)
        # 断言result对象的name属性为"ADX_14"
        self.assertEqual(result.name, "ADX_14")

        # 尝试使用tal.ADX函数计算预期结果,并断言result的第一列与预期结果相等
        try:
            expected = tal.ADX(self.high, self.low, self.close)
            pdt.assert_series_equal(result.iloc[:, 0], expected)
        # 如果断言失败,则进行异常处理
        except AssertionError:
            # 尝试计算result与预期结果的相关性,并与CORRELATION_THRESHOLD进行比较
            try:
                corr = pandas_ta.utils.df_error_analysis(result.iloc[:, 0], expected, col=CORRELATION)
                self.assertGreater(corr, CORRELATION_THRESHOLD)
            # 如果相关性计算出现异常,则调用error_analysis函数记录异常信息
            except Exception as ex:
                error_analysis(result, CORRELATION, ex)

        # 再次调用pandas_ta.adx函数计算ADX指标
        result = pandas_ta.adx(self.high, self.low, self.close)
        # 断言result对象为DataFrame类型
        self.assertIsInstance(result, DataFrame)
        # 断言result对象的name属性为"ADX_14"
        self.assertEqual(result.name, "ADX_14")

    # 定义测试AMAT指标的方法
    def test_amat(self):
        # 调用pandas_ta.amat函数计算AMAT指标
        result = pandas_ta.amat(self.close)
        # 断言result对象为DataFrame类型
        self.assertIsInstance(result, DataFrame)
        # 断言result对象的name属性为"AMATe_8_21_2"
        self.assertEqual(result.name, "AMATe_8_21_2")
    # 测试 Aroon 指标计算函数
    def test_aroon(self):
        # 调用 pandas_ta 库中的 aroon 函数计算 Aroon 指标
        result = pandas_ta.aroon(self.high, self.low, talib=False)
        # 断言返回结果为 DataFrame 类型
        self.assertIsInstance(result, DataFrame)
        # 断言返回结果的名称为 "AROON_14"

        # 尝试使用 talib 库计算 Aroon 指标
        try:
            expected = tal.AROON(self.high, self.low)
            expecteddf = DataFrame({"AROOND_14": expected[0], "AROONU_14": expected[1]})
            # 比较计算结果与预期结果是否一致
            pdt.assert_frame_equal(result, expecteddf)
        except AssertionError:
            # 如果计算结果与预期结果不一致,进行错误分析
            try:
                aroond_corr = pandas_ta.utils.df_error_analysis(result.iloc[:, 0], expecteddf.iloc[:, 0], col=CORRELATION)
                self.assertGreater(aroond_corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 如果出现异常,进行错误分析
                error_analysis(result.iloc[:, 0], CORRELATION, ex)

            try:
                aroonu_corr = pandas_ta.utils.df_error_analysis(result.iloc[:, 1], expecteddf.iloc[:, 1], col=CORRELATION)
                self.assertGreater(aroonu_corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 如果出现异常,进行错误分析
                error_analysis(result.iloc[:, 1], CORRELATION, ex, newline=False)

        # 重新计算 Aroon 指标
        result = pandas_ta.aroon(self.high, self.low)
        # 断言返回结果为 DataFrame 类型
        self.assertIsInstance(result, DataFrame)
        # 断言返回结果的名称为 "AROON_14"

    # 测试 Aroon Oscillator 指标计算函数
    def test_aroon_osc(self):
        # 计算 Aroon Oscillator 指标
        result = pandas_ta.aroon(self.high, self.low)
        # 断言返回结果为 DataFrame 类型
        self.assertIsInstance(result, DataFrame)
        # 断言返回结果的名称为 "AROON_14"

        try:
            expected = tal.AROONOSC(self.high, self.low)
            # 比较计算结果与预期结果是否一致
            pdt.assert_series_equal(result.iloc[:, 2], expected)
        except AssertionError:
            try:
                aroond_corr = pandas_ta.utils.df_error_analysis(result.iloc[:,2], expected,col=CORRELATION)
                self.assertGreater(aroond_corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 如果出现异常,进行错误分析
                error_analysis(result.iloc[:, 0], CORRELATION, ex)

    # 测试 Chande Kroll Stop 指标计算函数
    def test_chop(self):
        # 计算 Chande Kroll Stop 指标
        result = pandas_ta.chop(self.high, self.low, self.close, ln=False)
        # 断言返回结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言返回结果的名称为 "CHOP_14_1_100"

        result = pandas_ta.chop(self.high, self.low, self.close, ln=True)
        # 断言返回结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言返回结果的名称为 "CHOPln_14_1_100"

    # 测试 Chande Kroll Stop Points 指标计算函数
    def test_cksp(self):
        # 计算 Chande Kroll Stop Points 指标
        result = pandas_ta.cksp(self.high, self.low, self.close, tvmode=False)
        # 断言返回结果为 DataFrame 类型
        self.assertIsInstance(result, DataFrame)
        # 断言返回结果的名称为 "CKSP_10_3_20"

    # 测试 Chande Kroll Stop Points 指标计算函数(带 True Volume 模式)
    def test_cksp_tv(self):
        # 计算 Chande Kroll Stop Points 指标(带 True Volume 模式)
        result = pandas_ta.cksp(self.high, self.low, self.close, tvmode=True)
        # 断言返回结果为 DataFrame 类型
        self.assertIsInstance(result, DataFrame)
        # 断言返回结果的名称为 "CKSP_10_1_9"
    # 测试指数加权衰减移动平均函数
    def test_decay(self):
        # 使用默认参数计算指数加权衰减移动平均
        result = pandas_ta.decay(self.close)
        # 断言返回结果是一个 Series 对象
        self.assertIsInstance(result, Series)
        # 断言结果 Series 的名称为 "LDECAY_5"
        self.assertEqual(result.name, "LDECAY_5")

        # 使用指数加权衰减移动平均模式参数计算指数加权衰减移动平均
        result = pandas_ta.decay(self.close, mode="exp")
        # 断言返回结果是一个 Series 对象
        self.assertIsInstance(result, Series)
        # 断言结果 Series 的名称为 "EXPDECAY_5"
        self.assertEqual(result.name, "EXPDECAY_5")

    # 测试判断价格是否递减函数
    def test_decreasing(self):
        # 使用默认参数判断价格是否递减
        result = pandas_ta.decreasing(self.close)
        # 断言返回结果是一个 Series 对象
        self.assertIsInstance(result, Series)
        # 断言结果 Series 的名称为 "DEC_1"
        self.assertEqual(result.name, "DEC_1")

        # 使用指定长度和严格模式参数判断价格是否递减
        result = pandas_ta.decreasing(self.close, length=3, strict=True)
        # 断言返回结果是一个 Series 对象
        self.assertIsInstance(result, Series)
        # 断言结果 Series 的名称为 "SDEC_3"
        self.assertEqual(result.name, "SDEC_3")

    # 测试双重指数移动平均离差指标(DPO)函数
    def test_dpo(self):
        # 计算双重指数移动平均离差指标(DPO)
        result = pandas_ta.dpo(self.close)
        # 断言返回结果是一个 Series 对象
        self.assertIsInstance(result, Series)
        # 断言结果 Series 的名称为 "DPO_20"
        self.assertEqual(result.name, "DPO_20")

    # 测试判断价格是否递增函数
    def test_increasing(self):
        # 使用默认参数判断价格是否递增
        result = pandas_ta.increasing(self.close)
        # 断言返回结果是一个 Series 对象
        self.assertIsInstance(result, Series)
        # 断言结果 Series 的名称为 "INC_1"
        self.assertEqual(result.name, "INC_1")

        # 使用指定长度和严格模式参数判断价格是否递增
        result = pandas_ta.increasing(self.close, length=3, strict=True)
        # 断言返回结果是一个 Series 对象
        self.assertIsInstance(result, Series)
        # 断言结果 Series 的名称为 "SINC_3"
        self.assertEqual(result.name, "SINC_3")

    # 测试长期趋势函数
    def test_long_run(self):
        # 计算长期趋势
        result = pandas_ta.long_run(self.close, self.open)
        # 断言返回结果是一个 Series 对象
        self.assertIsInstance(result, Series)
        # 断言结果 Series 的名称为 "LR_2"
        self.assertEqual(result.name, "LR_2")

    # 测试抛物线 SAR 函数
    def test_psar(self):
        # 计算抛物线 SAR
        result = pandas_ta.psar(self.high, self.low)
        # 断言返回结果是一个 DataFrame 对象
        self.assertIsInstance(result, DataFrame)
        # 断言结果 DataFrame 的名称为 "PSAR_0.02_0.2"
        self.assertEqual(result.name, "PSAR_0.02_0.2")

        # 合并长期和短期 SAR 值为一个 SAR 值
        psar = result[result.columns[:2]].fillna(0)
        psar = psar[psar.columns[0]] + psar[psar.columns[1]]
        psar.name = result.name

        try:
            # 尝试与 talib 提供的 SAR 值进行比较
            expected = tal.SAR(self.high, self.low)
            # 断言两个 Series 对象相等
            pdt.assert_series_equal(psar, expected)
        except AssertionError:
            try:
                # 尝试进行相关性分析
                psar_corr = pandas_ta.utils.df_error_analysis(psar, expected, col=CORRELATION)
                # 断言相关性大于阈值
                self.assertGreater(psar_corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 发生异常时输出错误分析
                error_analysis(psar, CORRELATION, ex)

    # 测试 QStick 函数
    def test_qstick(self):
        # 计算 QStick 值
        result = pandas_ta.qstick(self.open, self.close)
        # 断言返回结果是一个 Series 对象
        self.assertIsInstance(result, Series)
        # 断言结果 Series 的名称为 "QS_10"
        self.assertEqual(result.name, "QS_10")

    # 测试短期趋势函数
    def test_short_run(self):
        # 计算短期趋势
        result = pandas_ta.short_run(self.close, self.open)
        # 断言返回结果是一个 Series 对象
        self.assertIsInstance(result, Series)
        # 断言结果 Series 的名称为 "SR_2"
        self.assertEqual(result.name, "SR_2")

    # 测试 TTM 趋势函数
    def test_ttm_trend(self):
        # 计算 TTM 趋势
        result = pandas_ta.ttm_trend(self.high, self.low, self.close)
        # 断言返回结果是一个 DataFrame 对象
        self.assertIsInstance(result, DataFrame)
        # 断言结果 DataFrame 的名称为 "TTMTREND_6"
        self.assertEqual(result.name, "TTMTREND_6")

    # 测试垂直水平通道函数
    def test_vhf(self):
        # 计算垂直水平通道值
        result = pandas_ta.vhf(self.close)
        # 断言返回结果是一个 Series 对象
        self.assertIsInstance(result, Series)
        # 断言结果 Series 的名称为 "VHF_28"
        self.assertEqual(result.name, "VHF_28")
    # 测试 Vortex 指标函数
    def test_vortex(self):
        # 调用 Vortex 指标函数,传入高、低、收盘价数据,获得结果
        result = pandas_ta.vortex(self.high, self.low, self.close)
        # 断言结果是 DataFrame 类型
        self.assertIsInstance(result, DataFrame)
        # 断言结果的名称为 "VTX_14"
        self.assertEqual(result.name, "VTX_14")

.\pandas-ta\tests\test_indicator_volatility.py

# 从.config模块中导入error_analysis,sample_data,CORRELATION,CORRELATION_THRESHOLD和VERBOSE变量
# 从.context模块中导入pandas_ta
from .config import error_analysis, sample_data, CORRELATION, CORRELATION_THRESHOLD, VERBOSE
from .context import pandas_ta

# 从unittest模块中导入TestCase和skip类
from unittest import TestCase, skip
# 导入pandas测试工具模块,重命名为pdt
import pandas.testing as pdt
# 从pandas模块中导入DataFrame和Series类
from pandas import DataFrame, Series
# 导入talib库,重命名为tal
import talib as tal

# 定义TestVolatility类,继承自TestCase类
class TestVolatility(TestCase):

    # 类方法,设置测试类的初始状态
    @classmethod
    def setUpClass(cls):
        # 将sample_data赋值给类属性data
        cls.data = sample_data
        # 将data的列名转换为小写
        cls.data.columns = cls.data.columns.str.lower()
        # 将data的"open"列赋值给类属性open
        cls.open = cls.data["open"]
        # 将data的"high"列赋值给类属性high
        cls.high = cls.data["high"]
        # 将data的"low"列赋值给类属性low
        cls.low = cls.data["low"]
        # 将data的"close"列赋值给类属性close
        cls.close = cls.data["close"]
        # 如果data的列中包含"volume"列
        if "volume" in cls.data.columns:
            # 将data的"volume"列赋值给类属性volume
            cls.volume = cls.data["volume"]

    # 类方法,清理测试类的状态
    @classmethod
    def tearDownClass(cls):
        # 删除类属性open
        del cls.open
        # 删除类属性high
        del cls.high
        # 删除类属性low
        del cls.low
        # 删除类属性close
        del cls.close
        # 如果类中存在volume属性
        if hasattr(cls, "volume"):
            # 删除类属性volume
            del cls.volume
        # 删除类属性data
        del cls.data

    # 实例方法,设置每个测试用例的初始状态
    def setUp(self): pass

    # 实例方法,清理每个测试用例的状态
    def tearDown(self): pass

    # 测试aberration函数
    def test_aberration(self):
        # 调用pandas_ta.aberration函数,传入self.high、self.low和self.close作为参数,返回结果赋值给result
        result = pandas_ta.aberration(self.high, self.low, self.close)
        # 断言result的类型为DataFrame
        self.assertIsInstance(result, DataFrame)
        # 断言result的name属性等于"ABER_5_15"
        self.assertEqual(result.name, "ABER_5_15")

    # 测试accbands函数
    def test_accbands(self):
        # 调用pandas_ta.accbands函数,传入self.high、self.low和self.close作为参数,返回结果赋值给result
        result = pandas_ta.accbands(self.high, self.low, self.close)
        # 断言result的类型为DataFrame
        self.assertIsInstance(result, DataFrame)
        # 断言result的name属性等于"ACCBANDS_20"
        self.assertEqual(result.name, "ACCBANDS_20")

    # 测试atr函数
    def test_atr(self):
        # 调用pandas_ta.atr函数,传入self.high、self.low、self.close和talib=False作为参数,返回结果赋值给result
        result = pandas_ta.atr(self.high, self.low, self.close, talib=False)
        # 断言result的类型为Series
        self.assertIsInstance(result, Series)
        # 断言result的name属性等于"ATRr_14"
        self.assertEqual(result.name, "ATRr_14")

        try:
            # 使用talib库计算ATR,期望结果赋值给expected
            expected = tal.ATR(self.high, self.low, self.close)
            # 断言result与expected相等,不检查名称
            pdt.assert_series_equal(result, expected, check_names=False)
        except AssertionError:
            try:
                # 计算result与expected之间的相关性
                corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
                # 断言相关性大于CORRELATION_THRESHOLD
                self.assertGreater(corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 调用error_analysis函数,传入result、CORRELATION和异常对象ex作为参数
                error_analysis(result, CORRELATION, ex)

        # 调用pandas_ta.atr函数,传入self.high、self.low和self.close作为参数,返回结果赋值给result
        result = pandas_ta.atr(self.high, self.low, self.close)
        # 断言result的类型为Series
        self.assertIsInstance(result, Series)
        # 断言result的name属性等于"ATRr_14"
        self.assertEqual(result.name, "ATRr_14")
    # 测试布林带指标函数
    def test_bbands(self):
        # 调用布林带指标函数,计算布林带指标
        result = pandas_ta.bbands(self.close, talib=False)
        # 断言结果为 DataFrame 类型
        self.assertIsInstance(result, DataFrame)
        # 断言结果的名称为 "BBANDS_5_2.0"
        self.assertEqual(result.name, "BBANDS_5_2.0")

        try:
            # 使用 TA-Lib 计算布林带指标的期望值
            expected = tal.BBANDS(self.close)
            # 将期望值转换为 DataFrame
            expecteddf = DataFrame({"BBU_5_2.0": expected[0], "BBM_5_2.0": expected[1], "BBL_5_2.0": expected[2]})
            # 使用 Pandas 的 assert_frame_equal 函数比较结果和期望值
            pdt.assert_frame_equal(result, expecteddf)
        except AssertionError:
            try:
                # 计算结果与期望值的相关性
                bbl_corr = pandas_ta.utils.df_error_analysis(result.iloc[:, 0], expecteddf.iloc[:,0], col=CORRELATION)
                # 断言相关性大于阈值
                self.assertGreater(bbl_corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 执行错误分析函数
                error_analysis(result.iloc[:, 0], CORRELATION, ex)

            try:
                bbm_corr = pandas_ta.utils.df_error_analysis(result.iloc[:, 1], expecteddf.iloc[:,1], col=CORRELATION)
                self.assertGreater(bbm_corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                error_analysis(result.iloc[:, 1], CORRELATION, ex, newline=False)

            try:
                bbu_corr = pandas_ta.utils.df_error_analysis(result.iloc[:, 2], expecteddf.iloc[:,2], col=CORRELATION)
                self.assertGreater(bbu_corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                error_analysis(result.iloc[:, 2], CORRELATION, ex, newline=False)

        # 调用布林带指标函数,设置自由度调整参数为 0
        result = pandas_ta.bbands(self.close, ddof=0)
        self.assertIsInstance(result, DataFrame)
        self.assertEqual(result.name, "BBANDS_5_2.0")

        # 调用布林带指标函数,设置自由度调整参数为 1
        result = pandas_ta.bbands(self.close, ddof=1)
        self.assertIsInstance(result, DataFrame)
        self.assertEqual(result.name, "BBANDS_5_2.0")

    # 测试唐奇安通道函数
    def test_donchian(self):
        # 调用唐奇安通道函数,计算唐奇安通道
        result = pandas_ta.donchian(self.high, self.low)
        self.assertIsInstance(result, DataFrame)
        self.assertEqual(result.name, "DC_20_20")

        # 调用唐奇安通道函数,设置下界长度为 20,上界长度为 5,计算唐奇安通道
        result = pandas_ta.donchian(self.high, self.low, lower_length=20, upper_length=5)
        self.assertIsInstance(result, DataFrame)
        self.assertEqual(result.name, "DC_20_5")

    # 测试 Keltner 通道函数
    def test_kc(self):
        # 调用 Keltner 通道函数,计算 Keltner 通道
        result = pandas_ta.kc(self.high, self.low, self.close)
        self.assertIsInstance(result, DataFrame)
        self.assertEqual(result.name, "KCe_20_2")

        # 调用 Keltner 通道函数,设置移动平均模式为 "sma",计算 Keltner 通道
        result = pandas_ta.kc(self.high, self.low, self.close, mamode="sma")
        self.assertIsInstance(result, DataFrame)
        self.assertEqual(result.name, "KCs_20_2")

    # 测试梅斯线指标函数
    def test_massi(self):
        # 调用梅斯线指标函数,计算梅斯线指标
        result = pandas_ta.massi(self.high, self.low)
        self.assertIsInstance(result, Series)
        self.assertEqual(result.name, "MASSI_9_25")
    # 测试 NATR 指标函数
    def test_natr(self):
        # 调用 pandas_ta 库中的 natr 函数计算 NATR 指标
        result = pandas_ta.natr(self.high, self.low, self.close, talib=False)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "NATR_14"
        self.assertEqual(result.name, "NATR_14")

        try:
            # 使用 TA-Lib 计算 NATR 指标的预期结果
            expected = tal.NATR(self.high, self.low, self.close)
            # 断言结果与预期结果一致,不检查名称
            pdt.assert_series_equal(result, expected, check_names=False)
        except AssertionError:
            try:
                # 计算结果与预期结果之间的相关性
                corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
                # 断言相关性大于阈值
                self.assertGreater(corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 执行错误分析
                error_analysis(result, CORRELATION, ex)

        # 重新调用 pandas_ta 库中的 natr 函数,不指定 TA-Lib
        result = pandas_ta.natr(self.high, self.low, self.close)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "NATR_14"
        self.assertEqual(result.name, "NATR_14")

    # 测试 PDIST 指标函数
    def test_pdist(self):
        # 调用 pandas_ta 库中的 pdist 函数计算 PDIST 指标
        result = pandas_ta.pdist(self.open, self.high, self.low, self.close)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "PDIST"
        self.assertEqual(result.name, "PDIST")

    # 测试 RVI 指标函数
    def test_rvi(self):
        # 调用 pandas_ta 库中的 rvi 函数计算 RVI 指标
        result = pandas_ta.rvi(self.close)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "RVI_14"

        # 调用 pandas_ta 库中的 rvi 函数计算 RVI 指标,使用高低价
        result = pandas_ta.rvi(self.close, self.high, self.low, refined=True)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "RVIr_14"

        # 调用 pandas_ta 库中的 rvi 函数计算 RVI 指标,使用三分法
        result = pandas_ta.rvi(self.close, self.high, self.low, thirds=True)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "RVIt_14"

    # 测试 THERMO 指标函数
    def test_thermo(self):
        # 调用 pandas_ta 库中的 thermo 函数计算 THERMO 指标
        result = pandas_ta.thermo(self.high, self.low)
        # 断言结果为 DataFrame 类型
        self.assertIsInstance(result, DataFrame)
        # 断言结果的名称为 "THERMO_20_2_0.5"

    # 测试 TRUE_RANGE 指标函数
    def test_true_range(self):
        # 调用 pandas_ta 库中的 true_range 函数计算 TRUE_RANGE 指标
        result = pandas_ta.true_range(self.high, self.low, self.close, talib=False)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "TRUERANGE_1"

        try:
            # 使用 TA-Lib 计算 TRUE_RANGE 指标的预期结果
            expected = tal.TRANGE(self.high, self.low, self.close)
            # 断言结果与预期结果一致,不检查名称
            pdt.assert_series_equal(result, expected, check_names=False)
        except AssertionError:
            try:
                # 计算结果与预期结果之间的相关性
                corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
                # 断言相关性大于阈值
                self.assertGreater(corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 执行错误分析
                error_analysis(result, CORRELATION, ex)

        # 重新调用 pandas_ta 库中的 true_range 函数,不指定 TA-Lib
        result = pandas_ta.true_range(self.high, self.low, self.close)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "TRUERANGE_1"

    # 测试 UI 指标函数
    def test_ui(self):
        # 调用 pandas_ta 库中的 ui 函数计算 UI 指标
        result = pandas_ta.ui(self.close)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "UI_14"

        # 调用 pandas_ta 库中的 ui 函数计算 UI 指标,包含 everget 参数
        result = pandas_ta.ui(self.close, everget=True)
        # 断言结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "UIe_14"

.\pandas-ta\tests\test_indicator_volume.py

# 从.config中导入错误分析、示例数据、相关性、相关性阈值、详细模式
from .config import error_analysis, sample_data, CORRELATION, CORRELATION_THRESHOLD, VERBOSE
# 从.context中导入pandas_ta
from .context import pandas_ta

# 导入TestCase和skip
from unittest import TestCase, skip
# 导入pandas测试工具
import pandas.testing as pdt
# 导入DataFrame和Series
from pandas import DataFrame, Series

# 导入talib库,并重命名为tal
import talib as tal

# 定义测试Volume的测试类
class TestVolume(TestCase):

    # 设置测试类的一些初始属性
    @classmethod
    def setUpClass(cls):
        cls.data = sample_data
        # 将列名转换为小写
        cls.data.columns = cls.data.columns.str.lower()
        # 设置测试数据的open、high、low、close列
        cls.open = cls.data["open"]
        cls.high = cls.data["high"]
        cls.low = cls.data["low"]
        cls.close = cls.data["close"]
        # 如果数据中包含volume列,则设置volume_
        if "volume" in cls.data.columns:
            cls.volume_ = cls.data["volume"]

    # 清理测试类的一些属性
    @classmethod
    def tearDownClass(cls):
        del cls.open
        del cls.high
        del cls.low
        del cls.close
        # 如果存在volume属性,则删除
        if hasattr(cls, "volume"):
            del cls.volume_
        del cls.data

    # 设置测试方法的setUp方法
    def setUp(self): pass

    # 设置测试方法的tearDown方法
    def tearDown(self): pass

    # 测试ad方法
    def test_ad(self):
        # 调用pandas_ta中的ad方法,不使用talib
        result = pandas_ta.ad(self.high, self.low, self.close, self.volume_, talib=False)
        # 检查返回结果是否为Series类型
        self.assertIsInstance(result, Series)
        # 检查返回结果的名称是否为"AD"
        self.assertEqual(result.name, "AD")

        # 尝试使用talib计算AD指标并检查结果是否一致,不检查名称
        try:
            expected = tal.AD(self.high, self.low, self.close, self.volume_)
            pdt.assert_series_equal(result, expected, check_names=False)
        except AssertionError:
            # 如果结果不一致,则进行错误分析
            try:
                corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
                # 检查相关性是否大于相关性阈值
                self.assertGreater(corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 如果出现异常,则进行错误分析
                error_analysis(result, CORRELATION, ex)

        # 再次调用pandas_ta中的ad方法,不使用talib
        result = pandas_ta.ad(self.high, self.low, self.close, self.volume_)
        # 检查返回结果是否为Series类型
        self.assertIsInstance(result, Series)
        # 检查返回结果的名称是否为"AD"

    # 测试ad_open方法
    def test_ad_open(self):
        # 调用pandas_ta中的ad方法,不使用talib
        result = pandas_ta.ad(self.high, self.low, self.close, self.volume_, self.open)
        # 检查返回结果是否为Series类型
        self.assertIsInstance(result, Series)
        # 检查返回结果的名称是否为"ADo"

    # 测试adosc方法
    def test_adosc(self):
        # 调用pandas_ta中的adosc方法,不使用talib
        result = pandas_ta.adosc(self.high, self.low, self.close, self.volume_, talib=False)
        # 检查返回结果是否为Series类型
        self.assertIsInstance(result, Series)
        # 检查返回结果的名称是否为"ADOSC_3_10"

        # 尝试使用talib计算ADOSC指标并检查结果是否一致,不检查名称
        try:
            expected = tal.ADOSC(self.high, self.low, self.close, self.volume_)
            pdt.assert_series_equal(result, expected, check_names=False)
        except AssertionError:
            # 如果结果不一致,则进行错误分析
            try:
                corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
                # 检查相关性是否大于相关性阈值
                self.assertGreater(corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 如果出现异常,则进行错误分析
                error_analysis(result, CORRELATION, ex)

        # 再次调用pandas_ta中的adosc方法,不使用talib
        result = pandas_ta.adosc(self.high, self.low, self.close, self.volume_)
        # 检查返回结果是否为Series类型
        self.assertIsInstance(result, Series)
        # 检查返回结果的名称是否为"ADOSC_3_10"

    # 测试aobv方法
    def test_aobv(self):
        # 调用pandas_ta中的aobv方法
        result = pandas_ta.aobv(self.close, self.volume_)
        # 检查返回结果是否为DataFrame类型
        self.assertIsInstance(result, DataFrame)
        # 检查返回结果的名称是否为"AOBVe_4_12_2_2_2"
    # 测试 CMF 指标计算函数
    def test_cmf(self):
        # 调用 pandas_ta 库的 CMF 函数计算结果
        result = pandas_ta.cmf(self.high, self.low, self.close, self.volume_)
        # 断言结果类型为 Series
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "CMF_20"
        self.assertEqual(result.name, "CMF_20")

    # 测试 EFI 指标计算函数
    def test_efi(self):
        # 调用 pandas_ta 库的 EFI 函数计算结果
        result = pandas_ta.efi(self.close, self.volume_)
        # 断言结果类型为 Series
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "EFI_13"
        self.assertEqual(result.name, "EFI_13")

    # 测试 EOM 指标计算函数
    def test_eom(self):
        # 调用 pandas_ta 库的 EOM 函数计算结果
        result = pandas_ta.eom(self.high, self.low, self.close, self.volume_)
        # 断言结果类型为 Series
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "EOM_14_100000000"
        self.assertEqual(result.name, "EOM_14_100000000")

    # 测试 KVO 指标计算函数
    def test_kvo(self):
        # 调用 pandas_ta 库的 KVO 函数计算结果
        result = pandas_ta.kvo(self.high, self.low, self.close, self.volume_)
        # 断言结果类型为 DataFrame
        self.assertIsInstance(result, DataFrame)
        # 断言结果的名称为 "KVO_34_55_13"
        self.assertEqual(result.name, "KVO_34_55_13")

    # 测试 MFI 指标计算函数
    def test_mfi(self):
        # 调用 pandas_ta 库的 MFI 函数计算结果,指定不使用 talib
        result = pandas_ta.mfi(self.high, self.low, self.close, self.volume_, talib=False)
        # 断言结果类型为 Series
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "MFI_14"
        self.assertEqual(result.name, "MFI_14")

        try:
            # 尝试使用 talib 计算 MFI,并与 pandas_ta 计算结果进行比较
            expected = tal.MFI(self.high, self.low, self.close, self.volume_)
            # 检查两个 Series 是否相等
            pdt.assert_series_equal(result, expected, check_names=False)
        except AssertionError:
            try:
                # 如果计算结果不相等,则进行错误分析并检查相关性
                corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
                self.assertGreater(corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 如果出现异常,则进行错误分析
                error_analysis(result, CORRELATION, ex)

        # 重新使用 pandas_ta 计算 MFI 指标
        result = pandas_ta.mfi(self.high, self.low, self.close, self.volume_)
        # 断言结果类型为 Series
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "MFI_14"
        self.assertEqual(result.name, "MFI_14")

    # 测试 NVI 指标计算函数
    def test_nvi(self):
        # 调用 pandas_ta 库的 NVI 函数计算结果
        result = pandas_ta.nvi(self.close, self.volume_)
        # 断言结果类型为 Series
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "NVI_1"
        self.assertEqual(result.name, "NVI_1")

    # 测试 OBV 指标计算函数
    def test_obv(self):
        # 调用 pandas_ta 库的 OBV 函数计算结果,指定不使用 talib
        result = pandas_ta.obv(self.close, self.volume_, talib=False)
        # 断言结果类型为 Series
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "OBV"
        self.assertEqual(result.name, "OBV")

        try:
            # 尝试使用 talib 计算 OBV,并与 pandas_ta 计算结果进行比较
            expected = tal.OBV(self.close, self.volume_)
            # 检查两个 Series 是否相等
            pdt.assert_series_equal(result, expected, check_names=False)
        except AssertionError:
            try:
                # 如果计算结果不相等,则进行错误分析并检查相关性
                corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
                self.assertGreater(corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                # 如果出现异常,则进行错误分析
                error_analysis(result, CORRELATION, ex)

        # 重新使用 pandas_ta 计算 OBV 指标
        result = pandas_ta.obv(self.close, self.volume_)
        # 断言结果类型为 Series
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "OBV"
        self.assertEqual(result.name, "OBV")

    # 测试 PVI 指标计算函数
    def test_pvi(self):
        # 调用 pandas_ta 库的 PVI 函数计算结果
        result = pandas_ta.pvi(self.close, self.volume_)
        # 断言结果类型为 Series
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "PVI_1"
        self.assertEqual(result.name, "PVI_1")

    # 测试 PVOL 指标计算函数
    def test_pvol(self):
        # 调用 pandas_ta 库的 PVOL 函数计算结果
        result = pandas_ta.pvol(self.close, self.volume_)
        # 断言结果类型为 Series
        self.assertIsInstance(result, Series)
        # 断言结果的名称为 "PVOL"
        self.assertEqual(result.name, "PVOL")
    # 测试 Price Volume Ratio (PVR) 指标函数
    def test_pvr(self):
        # 计算 PVR 指标
        result = pandas_ta.pvr(self.close, self.volume_)
        # 确保返回结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 确保返回结果的名称为 "PVR"
        self.assertEqual(result.name, "PVR")
        # 样本指标值来自于 SPY
        self.assertEqual(result[0], 1)
        self.assertEqual(result[1], 3)
        self.assertEqual(result[4], 2)
        self.assertEqual(result[6], 4)

    # 测试 Price Volume Trend (PVT) 指标函数
    def test_pvt(self):
        # 计算 PVT 指标
        result = pandas_ta.pvt(self.close, self.volume_)
        # 确保返回结果为 Series 类型
        self.assertIsInstance(result, Series)
        # 确保返回结果的名称为 "PVT"
        self.assertEqual(result.name, "PVT")

    # 测试 Volume Price (VP) 指标函数
    def test_vp(self):
        # 计算 VP 指标
        result = pandas_ta.vp(self.close, self.volume_)
        # 确保返回结果为 DataFrame 类型
        self.assertIsInstance(result, DataFrame)
        # 确保返回结果的名称为 "VP_10"
        self.assertEqual(result.name, "VP_10")

标签:PandasTA,Series,self,二十一,源码,result,close,pandas,ta
From: https://www.cnblogs.com/apachecn/p/18135803

相关文章

  • PandasTA 源码解析(一)
    .\pandas-ta\docs\conf.py#-*-coding:utf-8-*-##ConfigurationfilefortheSphinxdocumentationbuilder.##Thisfiledoesonlycontainaselectionofthemostcommonoptions.Fora#fulllistseethedocumentation:#http://www.sphinx-doc.org/e......
  • PandasTA 源码解析(二)
    .\pandas-ta\pandas_ta\candles\cdl_inside.py#-*-coding:utf-8-*-#从pandas_ta.utils中导入candle_color和get_offset函数frompandas_ta.utilsimportcandle_color,get_offset#从pandas_ta.utils中导入verify_series函数frompandas_ta.utilsimportve......
  • PandasTA 源码解析(四)
    .\pandas-ta\pandas_ta\momentum\cg.py#-*-coding:utf-8-*-#从pandas_ta.utils中导入get_offset,verify_series,weights函数frompandas_ta.utilsimportget_offset,verify_series,weights#定义CenterofGravity(CG)指标函数defcg(close,length=None,......
  • PandasTA 源码解析(三)
    .\pandas-ta\pandas_ta\custom.py#设置文件编码为UTF-8#-*-coding:utf-8-*-#导入必要的模块importimportlib#动态导入模块的工具importos#提供与操作系统交互的功能importsys#提供与Python解释器交互的功能importtypes#提供对Python类型和类的......
  • PandasTA 源码解析(六)
    .\pandas-ta\pandas_ta\momentum\rsi.py#-*-coding:utf-8-*-#导入所需模块和函数frompandasimportDataFrame,concatfrompandas_taimportImportsfrompandas_ta.overlapimportrmafrompandas_ta.utilsimportget_drift,get_offset,verify_series,signals......
  • PandasTA 源码解析(五)
    .\pandas-ta\pandas_ta\momentum\kst.py#-*-coding:utf-8-*-#导入DataFrame类frompandasimportDataFrame#导入roc函数from.rocimportroc#导入验证序列函数、获取漂移和偏移的函数frompandas_ta.utilsimportget_drift,get_offset,verify_series#定义......
  • PandasTA 源码解析(八)
    .\pandas-ta\pandas_ta\momentum\__init__.py#设置文件编码为UTF-8#导入ao指标from.aoimportao#导入apo指标from.apoimportapo#导入bias指标from.biasimportbias#导入bop指标from.bopimportbop#导入brar指标from.brarimportbrar#导......
  • PandasTA 源码解析(七)
    .\pandas-ta\pandas_ta\momentum\stc.py#-*-coding:utf-8-*-从pandas库中导入DataFrame和Series类从pandas_ta.overlap模块中导入ema函数从pandas_ta.utils模块中导入get_offset、non_zero_range和verify_series函数#定义函数:SchaffTrendCycle(STC......
  • 案例二十一备份30天之前的日志并压缩到指定目录下
    #!/bin/bash#备份目录info_backdir=/backup/log/info/`date-d"30dayago"+%F|awk-F"-"'{print$1"-"$2}'`error_backdir=/backup/log/error/`date-d"30dayago"+%F|awk-F"-"'{print$1"......
  • BackTrader 中文文档(二十一)
    原文:www.backtrader.com/目标订单原文:www.backtrader.com/blog/posts/2016-09-02-target-orders/target-orders/直到版本1.8.10.96,通过Strategy方法:买入和卖出,在backtrader上实现了智能的投注。一切都是关于向方程中添加一个Sizer,它负责赌注的大小。Sizer无法决定操作是......