【问题标题】:How to build aroon indicator with Python pandas如何使用 Python pandas 构建 aroon 指标
【发布时间】:2017-12-23 06:52:10
【问题描述】:

我正在尝试使用 pandas 在 python 中制作 aroon 指示器。但是我得到了错误的价值观......谁能帮忙指出我哪里出错了......

import pandas as pd
import Bitmex_OHLC
import numpy as np
import importlib

def aroon():
    importlib.reload(Bitmex_OHLC)
    df_aroon = Bitmex_OHLC.OHLC()
    df_aroon['14L_min'] = df_aroon['low'].rolling(window=14,min_periods=0).min()
    df_aroon['14H_max'] = df_aroon['high'].rolling(window=14,min_periods = 0).max()
    df_aroon['ind'] = range(0,len(df_aroon))
    # recent_high = df_aroon.iloc[-1]["25d High"]
    df_aroon['high_ind'] = df_aroon['ind'].where(df_aroon["14H_max"]==df_aroon['high']).fillna(method = 'ffill')
    df_aroon['low_ind'] = df_aroon['ind'].where(df_aroon["14L_min"] == df_aroon['low']).fillna(method = 'ffill')
    df_aroon['since_high'] = df_aroon['ind']-df_aroon['high_ind']
    df_aroon['since_low'] = df_aroon['ind'] - df_aroon['low_ind']
    df_aroon['up'] = (((14 - df_aroon['since_high'])/14) *100)
    df_aroon['down'] = (((14 - df_aroon['since_low']) / 14) * 100)
    return (df_aroon)

print(aroon().tail())

(down) 列的值应始终为正,(since_low) 列应小于 14。

任何帮助将不胜感激..谢谢

https://dpaste.de/kJJW Error code

【问题讨论】:

标签: python pandas finance quantitative-finance indicator


【解决方案1】:

我也在寻找相同的指标然后找到了我修改的这段代码

def aroon(data, lb=25):

    df = data.copy()
    df['up'] = 100 * df.High.rolling(lb + 1).apply(lambda x: x.argmax()) / lb
    df['dn'] = 100 * df.Low.rolling(lb + 1).apply(lambda x: x.argmin()) / lb

    return df['up'], df['dn'] 

这是我的图片 enter image description here

我希望它可以帮助别人。

【讨论】:

    【解决方案2】:

    您好,我是一个想要使用 quantopian 的新手 有兴趣使用 Aroon。在我的搜索中找到了这个。看起来比您的代码更简单,并相信它使用 ta-lib。 https://github.com/FreddieWitherden/ta/blob/master/ta.py

    【讨论】:

      猜你喜欢
      • 2020-08-22
      • 2022-10-30
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 2016-06-29
      • 2023-02-09
      • 1970-01-01
      • 2015-12-04
      相关资源
      最近更新 更多