如何使用Python pandas

时间:2017-12-23 06:52:10

标签: python pandas finance quantitative-finance indicator

我正在尝试使用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())

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

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

https://dpaste.de/kJJW Error enter image description here code enter image description here

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

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

我希望它可以帮助其他人。