يعد التحليل الفني لـ Pandas ( Pandas TA ) مكتبة سهلة الاستخدام تستفيد من حزمة Pandas مع أكثر من 130 مؤشرًا ووظائف المنفعة وأكثر من 60 TA LIB Candlestick. يتم تضمين العديد من المؤشرات شائعة الاستخدام ، مثل: نمط الشمعة ( CDL_Pattern ) ، متوسط متوسط الحركة المتوسط المتحرك ( SMA ) المتوسط المتوسط ( MACD ) ، المتوسط المتحرك الأسي للبدن ( HMA ) ، نطاقات Bollinger ( BBANDS ) ، حجم الموازن ( OBV (OBV) ) ، آرون آند آرون مذبذب ( أرون ) ، الضغط ( الضغط ) وغيرها الكثير .
ملاحظة: يجب تثبيت TA LIB لاستخدام جميع أنماط الشموع. pip install TA-Lib
. إذا لم يتم تثبيت TA LIB ، فستتوفر أنماط الشموع المدمجة فقط.
talib=False
.ta.stdev(df["close"], length=30, talib=False)
.import_dir
تحت /pandas_ta/custom.py
.ta.tsignals
.lookahead=False
لتعطيل.يتحقق Pandas TA إذا كان لدى المستخدم بعض حزم التداول الشائعة المثبتة بما في ذلك على سبيل المثال لا الحصر: TA LIB ، Vector BT ، yfinance ... الكثير منها تجريبي ومن المحتمل أن ينكسر حتى يستقر أكثر.
help(ta.ticker)
help(ta.yf)
والأمثلة أدناه. إصدار pip
هو آخر إصدار مستقر. الإصدار: 0.3.14b
$ pip install pandas_ta
أفضل خيار! الإصدار: 0.3.14b
$ pip install -U git+https://github.com/twopirllc/pandas-ta
هذا هو نسخة التطوير التي يمكن أن تحتوي على الأخطاء وغيرها من الآثار الجانبية غير المرغوب فيها. استخدام في خطر خاص!
$ pip install -U git+https://github.com/twopirllc/pandas-ta.git@development
import pandas as pd
import pandas_ta as ta
df = pd . DataFrame () # Empty DataFrame
# Load data
df = pd . read_csv ( "path/to/symbol.csv" , sep = "," )
# OR if you have yfinance installed
df = df . ta . ticker ( "aapl" )
# VWAP requires the DataFrame index to be a DatetimeIndex.
# Replace "datetime" with the appropriate column from your DataFrame
df . set_index ( pd . DatetimeIndex ( df [ "datetime" ]), inplace = True )
# Calculate Returns and append to the df DataFrame
df . ta . log_return ( cumulative = True , append = True )
df . ta . percent_return ( cumulative = True , append = True )
# New Columns with results
df . columns
# Take a peek
df . tail ()
# vv Continue Post Processing vv
تم إعادة ترتيب بعض حجج المؤشر للاتساق. استخدم help(ta.indicator_name)
لمزيد من المعلومات أو تقديم طلب سحب لتحسين الوثائق.
import pandas as pd
import pandas_ta as ta
# Create a DataFrame so 'ta' can be used.
df = pd . DataFrame ()
# Help about this, 'ta', extension
help ( df . ta )
# List of all indicators
df . ta . indicators ()
# Help about an indicator such as bbands
help ( ta . bbands )
شكرا لاستخدام Pandas TA !
$ pip install -U git+https://github.com/twopirllc/pandas-ta
شكرا لك على مساهماتك!
لدى Pandas TA ثلاثة "أنماط" أساسية لمعالجة المؤشرات الفنية لحالة الاستخدام و/أو المتطلبات. هم: قياسي ، امتداد DataFrame ، واستراتيجية Pandas TA . كل مع زيادة مستويات التجريد لسهولة الاستخدام. عندما تصبح أكثر دراية بـ Pandas TA ، قد تصبح بساطة وسرعة استخدام استراتيجية Pandas TA أكثر وضوحًا. علاوة على ذلك ، يمكنك إنشاء مؤشراتك الخاصة من خلال التسلسل أو التكوين. أخيرًا ، يقوم كل مؤشر إما بإرجاع سلسلة أو ملف بيانات بتنسيق Underscore Underscore بغض النظر عن الأناقة.
يمكنك تحديد أعمدة الإدخال صراحة وتعتني بالإخراج.
sma10 = ta.sma(df["Close"], length=10)
SMA_10
donchiandf = ta.donchian(df["HIGH"], df["low"], lower_length=10, upper_length=15)
DC_10_15
وأسماء الأعمدة: DCL_10_15, DCM_10_15, DCU_10_15
ema10_ohlc4 = ta.ema(ta.ohlc4(df["Open"], df["High"], df["Low"], df["Close"]), length=10)
EMA_10
. إذا لزم الأمر ، فقد تحتاج إلى تسمية ذلك بشكل فريد. سيقوم استدعاء df.ta
تلقائيًا بتخفيف OHLCVA إلى OHLCVA : مفتوح ، عالي ، منخفض ، إغلاق ، حجم ، adj_close . بشكل افتراضي ، ستستخدم df.ta
OHLCVA لوسائط المؤشر التي تزيل الحاجة إلى تحديد أعمدة الإدخال مباشرة.
sma10 = df.ta.sma(length=10)
SMA_10
ema10_ohlc4 = df.ta.ema(close=df.ta.ohlc4(), length=10, suffix="OHLC4")
EMA_10_OHLC4
close=df.ta.ohlc4()
.donchiandf = df.ta.donchian(lower_length=10, upper_length=15)
DC_10_15
وأسماء الأعمدة: DCL_10_15, DCM_10_15, DCU_10_15
مثل الأمثلة الثلاثة الأخيرة ، ولكن إلحاق النتائج مباشرة إلى DataFrame df
.
df.ta.sma(length=10, append=True)
df
: SMA_10
.df.ta.ema(close=df.ta.ohlc4(append=True), length=10, suffix="OHLC4", append=True)
close=df.ta.ohlc4()
.df.ta.donchian(lower_length=10, upper_length=15, append=True)
df
بأسماء الأعمدة: DCL_10_15, DCM_10_15, DCU_10_15
. استراتيجية Pandas TA هي مجموعة محددة من المؤشرات التي تديرها طريقة الاستراتيجية . تستخدم جميع الاستراتيجيات MuleTprocessing إلا عند استخدام معلمة col_names
(انظر أدناه). هناك أنواع مختلفة من الاستراتيجيات المدرجة في القسم التالي.
# (1) Create the Strategy
MyStrategy = ta . Strategy (
name = "DCSMA10" ,
ta = [
{ "kind" : "ohlc4" },
{ "kind" : "sma" , "length" : 10 },
{ "kind" : "donchian" , "lower_length" : 10 , "upper_length" : 15 },
{ "kind" : "ema" , "close" : "OHLC4" , "length" : 10 , "suffix" : "OHLC4" },
]
)
# (2) Run the Strategy
df . ta . strategy ( MyStrategy , ** kwargs )
تعد فئة الإستراتيجية طريقة بسيطة لتسمية مؤشرات TA المفضلة لديك وتجميعها باستخدام فئة بيانات . يأتي Pandas TA مع استراتيجيتين أساسيتين تم تصميمه مسبقًا لمساعدتك في البدء: Allstrategy و Commonstrate . يمكن أن تكون الإستراتيجية بسيطة مثل Commonstrategy أو معقدة حسب الحاجة باستخدام التكوين/التسلسل.
df
.راجع أمثلة استراتيجية Pandas TA لأمثلة بما في ذلك تكوين المؤشر/التسلسل .
{"kind": "indicator name"}
. تذكر أن تتحقق من الإملاء. # Running the Builtin CommonStrategy as mentioned above
df . ta . strategy ( ta . CommonStrategy )
# The Default Strategy is the ta.AllStrategy. The following are equivalent:
df . ta . strategy ()
df . ta . strategy ( "All" )
df . ta . strategy ( ta . AllStrategy )
# List of indicator categories
df . ta . categories
# Running a Categorical Strategy only requires the Category name
df . ta . strategy ( "Momentum" ) # Default values for all Momentum indicators
df . ta . strategy ( "overlap" , length = 42 ) # Override all Overlap 'length' attributes
# Create your own Custom Strategy
CustomStrategy = ta . Strategy (
name = "Momo and Volatility" ,
description = "SMA 50,200, BBANDS, RSI, MACD and Volume SMA 20" ,
ta = [
{ "kind" : "sma" , "length" : 50 },
{ "kind" : "sma" , "length" : 200 },
{ "kind" : "bbands" , "length" : 20 },
{ "kind" : "rsi" },
{ "kind" : "macd" , "fast" : 8 , "slow" : 21 },
{ "kind" : "sma" , "close" : "volume" , "length" : 20 , "prefix" : "VOLUME" },
]
)
# To run your "Custom Strategy"
df . ta . strategy ( CustomStrategy )
تستخدم طريقة استراتيجية Pandas TA المعالجة المتعددة لمعالجة المؤشرات بالجملة لجميع أنواع الاستراتيجية باستثناء واحد! عند استخدام معلمة col_names
لإعادة تسمية الأعمدة (العمود) الناتجة ، سيتم تشغيل المؤشرات في ta
بالترتيب.
# VWAP requires the DataFrame index to be a DatetimeIndex.
# * Replace "datetime" with the appropriate column from your DataFrame
df . set_index ( pd . DatetimeIndex ( df [ "datetime" ]), inplace = True )
# Runs and appends all indicators to the current DataFrame by default
# The resultant DataFrame will be large.
df . ta . strategy ()
# Or the string "all"
df . ta . strategy ( "all" )
# Or the ta.AllStrategy
df . ta . strategy ( ta . AllStrategy )
# Use verbose if you want to make sure it is running.
df . ta . strategy ( verbose = True )
# Use timed if you want to see how long it takes to run.
df . ta . strategy ( timed = True )
# Choose the number of cores to use. Default is all available cores.
# For no multiprocessing, set this value to 0.
df . ta . cores = 4
# Maybe you do not want certain indicators.
# Just exclude (a list of) them.
df . ta . strategy ( exclude = [ "bop" , "mom" , "percent_return" , "wcp" , "pvi" ], verbose = True )
# Perhaps you want to use different values for indicators.
# This will run ALL indicators that have fast or slow as parameters.
# Check your results and exclude as necessary.
df . ta . strategy ( fast = 10 , slow = 50 , verbose = True )
# Sanity check. Make sure all the columns are there
df . columns
تذكر أن هذه لن تستخدم المعالجة المتعددة
NonMPStrategy = ta . Strategy (
name = "EMAs, BBs, and MACD" ,
description = "Non Multiprocessing Strategy by rename Columns" ,
ta = [
{ "kind" : "ema" , "length" : 8 },
{ "kind" : "ema" , "length" : 21 },
{ "kind" : "bbands" , "length" : 20 , "col_names" : ( "BBL" , "BBM" , "BBU" )},
{ "kind" : "macd" , "fast" : 8 , "slow" : 21 , "col_names" : ( "MACD" , "MACD_H" , "MACD_S" )}
]
)
# Run it
df . ta . strategy ( NonMPStrategy )
# Set ta to default to an adjusted column, 'adj_close', overriding default 'close'.
df . ta . adjusted = "adj_close"
df . ta . sma ( length = 10 , append = True )
# To reset back to 'close', set adjusted back to None.
df . ta . adjusted = None
# List of Pandas TA categories.
df . ta . categories
# Set the number of cores to use for strategy multiprocessing
# Defaults to the number of cpus you have.
df . ta . cores = 4
# Set the number of cores to 0 for no multiprocessing.
df . ta . cores = 0
# Returns the number of cores you set or your default number of cpus.
df . ta . cores
# The 'datetime_ordered' property returns True if the DataFrame
# index is of Pandas datetime64 and df.index[0] < df.index[-1].
# Otherwise it returns False.
df . ta . datetime_ordered
# Sets the Exchange to use when calculating the last_run property. Default: "NYSE"
df . ta . exchange
# Set the Exchange to use.
# Available Exchanges: "ASX", "BMF", "DIFX", "FWB", "HKE", "JSE", "LSE", "NSE", "NYSE", "NZSX", "RTS", "SGX", "SSE", "TSE", "TSX"
df . ta . exchange = "LSE"
# Returns the time Pandas TA was last run as a string.
df . ta . last_run
# The 'reverse' is a helper property that returns the DataFrame
# in reverse order.
df . ta . reverse
# Applying a prefix to the name of an indicator.
prehl2 = df . ta . hl2 ( prefix = "pre" )
print ( prehl2 . name ) # "pre_HL2"
# Applying a suffix to the name of an indicator.
endhl2 = df . ta . hl2 ( suffix = "post" )
print ( endhl2 . name ) # "HL2_post"
# Applying a prefix and suffix to the name of an indicator.
bothhl2 = df . ta . hl2 ( prefix = "pre" , suffix = "post" )
print ( bothhl2 . name ) # "pre_HL2_post"
# Returns the time range of the DataFrame as a float.
# By default, it returns the time in "years"
df . ta . time_range
# Available time_ranges include: "years", "months", "weeks", "days", "hours", "minutes". "seconds"
df . ta . time_range = "days"
df . ta . time_range # prints DataFrame time in "days" as float
# Sets the DataFrame index to UTC format.
df . ta . to_utc
import numpy as np
# Add constant '1' to the DataFrame
df . ta . constants ( True , [ 1 ])
# Remove constant '1' to the DataFrame
df . ta . constants ( False , [ 1 ])
# Adding constants for charting
import numpy as np
chart_lines = np . append ( np . arange ( - 4 , 5 , 1 ), np . arange ( - 100 , 110 , 10 ))
df . ta . constants ( True , chart_lines )
# Removing some constants from the DataFrame
df . ta . constants ( False , np . array ([ - 60 , - 40 , 40 , 60 ]))
# Prints the indicators and utility functions
df . ta . indicators ()
# Returns a list of indicators and utility functions
ind_list = df . ta . indicators ( as_list = True )
# Prints the indicators and utility functions that are not in the excluded list
df . ta . indicators ( exclude = [ "cg" , "pgo" , "ui" ])
# Returns a list of the indicators and utility functions that are not in the excluded list
smaller_list = df . ta . indicators ( exclude = [ "cg" , "pgo" , "ui" ], as_list = True )
# Download Chart history using yfinance. (pip install yfinance) https://github.com/ranaroussi/yfinance
# It uses the same keyword arguments as yfinance (excluding start and end)
df = df . ta . ticker ( "aapl" ) # Default ticker is "SPY"
# Period is used instead of start/end
# Valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max
# Default: "max"
df = df . ta . ticker ( "aapl" , period = "1y" ) # Gets this past year
# History by Interval by interval (including intraday if period < 60 days)
# Valid intervals: 1m,2m,5m,15m,30m,60m,90m,1h,1d,5d,1wk,1mo,3mo
# Default: "1d"
df = df . ta . ticker ( "aapl" , period = "1y" , interval = "1wk" ) # Gets this past year in weeks
df = df . ta . ticker ( "aapl" , period = "1mo" , interval = "1h" ) # Gets this past month in hours
# BUT WAIT!! THERE'S MORE!!
help ( ta . yf )
الأنماط غير الجريئة ، تتطلب تثبيت ta-lib: pip install TA-Lib
# Get all candle patterns (This is the default behaviour)
df = df . ta . cdl_pattern ( name = "all" )
# Get only one pattern
df = df . ta . cdl_pattern ( name = "doji" )
# Get some patterns
df = df . ta . cdl_pattern ( name = [ "doji" , "inside" ])
ta.linreg(series, r=True)
lazybear=True
df.ta.strategy()
.تباعد التقارب المتوسط المتحرك (MACD) |
---|
help(ta.ichimoku)
.lookahead=False
يسقط عمود CHIKOU SPAN لمنع تسرب البيانات المحتمل.متوسطات الحركة البسيطة (SMA) و Bollinger Bands (Bbands) |
---|
استخدم المعلمة: تراكمية = صواب للنتائج التراكمية.
عائد في المئة (تراكمي) مع متوسط متحرك بسيط (SMA) |
---|
Z النتيجة |
---|
lookahead=False
لتعطيل التركيز وإزالة تسرب البيانات المحتمل.متوسط مؤشر حركة الاتجاه (ADX) |
---|
متوسط النطاق الحقيقي (ATR) |
---|
حجم الموازن (obv) |
---|
مقاييس الأداء هي إضافة جديدة إلى الحزمة ، وبالتالي فمن المحتمل أن تكون غير موثوقة. استخدم على مسؤوليتك الخاصة. هذه المقاييس تُرجع تعويمًا وليست جزءًا من امتداد DataFrame . يطلق عليهم الطريق القياسي. على سبيل المثال:
import pandas_ta as ta
result = ta . cagr ( df . close )
من أجل التكامل الأسهل مع محفظة VectorBT من طريقة from_signals
، تم استبدال طريقة ta.trend_return
بطريقة ta.tsignals
لتبسيط توليد إشارات التداول. للحصول على مثال شامل ، راجع مثال Jupyter Notebook VectorBT Backtest مع Pandas TA في دليل الأمثلة.
import pandas as pd
import pandas_ta as ta
import vectorbt as vbt
df = pd . DataFrame (). ta . ticker ( "AAPL" ) # requires 'yfinance' installed
# Create the "Golden Cross"
df [ "GC" ] = df . ta . sma ( 50 , append = True ) > df . ta . sma ( 200 , append = True )
# Create boolean Signals(TS_Entries, TS_Exits) for vectorbt
golden = df . ta . tsignals ( df . GC , asbool = True , append = True )
# Sanity Check (Ensure data exists)
print ( df )
# Create the Signals Portfolio
pf = vbt . Portfolio . from_signals ( df . close , entries = golden . TS_Entries , exits = golden . TS_Exits , freq = "D" , init_cash = 100_000 , fees = 0.0025 , slippage = 0.0025 )
# Print Portfolio Stats and Return Stats
print ( pf . stats ())
print ( pf . returns_stats ())
mamode
KWARG مع المزيد من الخيارات المتوسطة المتحركة مع وظيفة الأداة المساعدة المتوسطة المتحركة ta.ma()
. من أجل البساطة ، جميع الخيارات هي متوسطات نقل مصدر واحد. هذا هو في المقام الأول فائدة داخلية تستخدمها المؤشرات التي لها mamode
kwarg . ويشمل ذلك المؤشرات: Accbands ، AMAT ، AOBV ، ATR ، BBANDS ، BIAS ، EFI ، HILO ، KC ، NATR ، QQE ، RVI ، و THERMO ؛ لم تتغير معلمات mamode
الافتراضية. ومع ذلك ، يمكن استخدام ta.ma()
من قبل المستخدم أيضًا إذا لزم الأمر. لمزيد من المعلومات: help(ta.ma)
to_utc
، لتحويل فهرس DataFrame إلى UTC. انظر: help(ta.to_utc)
الآن كخاصية PANDAS TA DATAFRAME لتحويل فهرس DataFrame بسهولة إلى UTC. close > sma(close, 50)
فإنها تُرجع الاتجاه ، وإدخالات التجارة والمخارج التجارية لهذا الاتجاه لجعلها متوافقة مع VectorBT عن طريق تعيين asbool=True
للحصول على إدخالات التجارة المنطقية والخروج. انظر help(ta.tsignals)
help(ta.alma)
حساب التداول ، أو الصندوق. انظر help(ta.drawdown)
help(ta.cdl_pattern)
help(ta.cdl_z)
help(ta.cti)
help(ta.xsignals)
help(ta.dm)
help(ta.ebsw)
help(ta.jma)
help(ta.kvo)
help(ta.stc)
help(ta.squeeze_pro)
df.ta.strategy()
لأسباب الأداء. انظر help(ta.td_seq)
help(ta.tos_stdevall)
help(ta.vhf)
mamode
المعاد تسميتها إلى mode
. انظر help(ta.accbands)
.mamode
مع " RMA " الافتراضية ونفس خيارات mamode
مثل TradingView. حجة جديدة lensig
بحيث تتصرف مثل مؤشر ADX المدمج في TradingView. انظر help(ta.adx)
.drift
المضافة وأسماء الأعمدة الوصفية.mamode
الافتراضي الآن " RMA " ومع نفس خيارات mamode
مثل TradingView. انظر help(ta.atr)
.ddoff
للسيطرة على درجات الحرية. وشملت أيضا BB في المئة (BBP) كعمود نهائي. الافتراضي هو 0. انظر help(ta.bbands)
.ln
لاستخدام اللوغاريتم الطبيعي (صواب) بدلاً من اللوغاريتم القياسي (خطأ). الافتراضي كاذب. انظر help(ta.chop)
.tvmode
مع True
الافتراضي. عندما يكون tvmode=False
، ينفذ CKSP "المتداول الفني الجديد" مع القيم الافتراضية. انظر help(ta.cksp)
.talib
إصدار TA Lib وإذا تم تثبيت TA LIB. الافتراضي صحيح. انظر help(ta.cmo)
.strict
إذا كانت السلسلة تتناقص باستمرار على length
الفترة مع حساب أسرع. الافتراضي: False
. كما تمت إضافة حجة percent
مع الافتراضي لا شيء. انظر help(ta.decreasing)
.strict
إذا كانت السلسلة تزداد باستمرار على length
الفترة مع حساب أسرع. الافتراضي: False
. كما تمت إضافة حجة percent
مع الافتراضي لا شيء. انظر help(ta.increasing)
.help(ta.kvo)
.as_strided
أو طريقة sliding_window_view
الأحدث. يجب أن يحل هذا المشكلات مع Google Colab وتأخر تحديثات التبعية وكذلك تبعيات TensorFlow كما تمت مناقشته في القضايا رقم 285 و #329.asmode
كإصدار من MACD. الافتراضي كاذب. انظر help(ta.macd)
.sar
TradingView. حجة جديدة af0
لتهيئة عامل التسارع. انظر help(ta.psar)
.mamode
كخيار. الافتراضي هو SMA لمطابقة TA LIB. انظر help(ta.ppo)
.signal
مضافة مع الافتراضي 13
و MA mamode
MAMODE مع EMA الافتراضي كوسائط. انظر help(ta.tsi)
.help(ta.vp)
.help(ta.vwma)
.anchor
. الافتراضي: "D" لـ "Daily". انظر مرورات الأوقات المعارضة الأسماء المستعارة لخيارات إضافية. يتطلب فهرس DataFrame ليكون dateTimeIndex. انظر help(ta.vwap)
.help(ta.vwma)
.Z_length
إلى ZS_length
. انظر help(ta.zscore)
.الأصلي ta-lib | TradingView | سييرا تشارت | MQL5 | FM Labs | برو كود حقيقي | المستخدم 42
هل تشعر بالسخاء ، مثل الحزمة أو تريد رؤيتها تصبح أكثر حزمة ناضجة؟