{"id":20923454,"url":"https://github.com/mpquant/python-financial-technical-indicators-pandas","last_synced_at":"2025-05-13T16:30:39.109Z","repository":{"id":50460775,"uuid":"403040229","full_name":"mpquant/Python-Financial-Technical-Indicators-Pandas","owner":"mpquant","description":"Technical Indicators implemented in Python only using Numpy-Pandas as Magic  - Very Very Fast! Very tiny!  Stock Market Financial Technical Analysis Python library .  Quant Trading automation or cryptocoin exchange ","archived":false,"fork":false,"pushed_at":"2021-10-30T03:53:49.000Z","size":144,"stargazers_count":70,"open_issues_count":1,"forks_count":21,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T04:47:13.361Z","etag":null,"topics":["atr","bbi","bool","cci","dma","dmi","ema","emv","expma","kdj","macd","python","rsi","sma","trix"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mpquant.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-04T11:35:23.000Z","updated_at":"2025-02-28T05:15:54.000Z","dependencies_parsed_at":"2022-08-19T18:20:11.792Z","dependency_job_id":null,"html_url":"https://github.com/mpquant/Python-Financial-Technical-Indicators-Pandas","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpquant%2FPython-Financial-Technical-Indicators-Pandas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpquant%2FPython-Financial-Technical-Indicators-Pandas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpquant%2FPython-Financial-Technical-Indicators-Pandas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpquant%2FPython-Financial-Technical-Indicators-Pandas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mpquant","download_url":"https://codeload.github.com/mpquant/Python-Financial-Technical-Indicators-Pandas/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253981654,"owners_count":21994313,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["atr","bbi","bool","cci","dma","dmi","ema","emv","expma","kdj","macd","python","rsi","sma","trix"],"created_at":"2024-11-18T20:15:57.567Z","updated_at":"2025-05-13T16:30:38.806Z","avatar_url":"https://github.com/mpquant.png","language":"Python","readme":"# MyTT\nTechnical Indicators implemented in Python only using Numpy-Pandas as Magic - Very Very Fast! to Stock Market Financial Technical Analysis Python library\n [MyTT.py](https://github.com/mpquant/Python-Financial-Technical-Indicators-Pandas/blob/main/MyTT.py)\n\n# Features\n\n* Innovative application of core tools function,so to writing indicator becomes easy and interesting!\n* Calculate technical indicators (Most of the indicators supported)\n* Produce graphs for any technical indicator\n* MyTT is very very fast! pure numpy and pandas implemented, not need install Ta-lib (talib)\n* MyTT is very simple,only use numpy and pandas even not \"for in \" in the code\n* Trading automation Quant Trade, Stock Market, Futures market or cryptocoin exchange like BTC\n* Chinese version MyTT Url: https://github.com/mpquant/MyTT\n\n```python\n\n#  ----- 0 level：core tools function ---------\n\n def MA(S,N):                          \n    return pd.Series(S).rolling(N).mean().values   \n\n def DIFF(S, N=1):         \n    return pd.Series(S).diff(N)  \n    \n def STD(S,N):              \n    return  pd.Series(S).rolling(N).std(ddof=0).values\n\n def EMA(S,N):               # alpha=2/(span+1)    \n    return pd.Series(S).ewm(span=N, adjust=False).mean().values  \n\n def SMA(S, N, M=1):        #   alpha=1/(1+com)\n    return pd.Series(S).ewm(com=N-M, adjust=True).mean().values     \n\n def AVEDEV(S,N):          \n    return pd.Series(S).rolling(N).apply(lambda x: (np.abs(x - x.mean())).mean()).values \n\n def IF(S_BOOL,S_TRUE,S_FALSE):  \n    return np.where(S_BOOL, S_TRUE, S_FALSE)\n\n def SUM(S, N):                   \n    return pd.Series(S).rolling(N).sum().values if N\u003e0 else pd.Series(S).cumsum()  \n\n def HHV(S,N):                   \n    return pd.Series(S).rolling(N).max().values     \n\n def LLV(S,N):            \n    return pd.Series(S).rolling(N).min().values    \n```    \n\n```python\n\n#-----   1 level： Logic and Statistical function  (only use 0 level function to implemented） -----\n\ndef COUNT(S_BOOL, N):                  # COUNT(CLOSE\u003eO, N): \n    return SUM(S_BOOL,N)    \n\ndef EVERY(S_BOOL, N):                  # EVERY(CLOSE\u003eO, 5)  \n    R=SUM(S_BOOL, N)\n    return  IF(R==N, True, False)\n  \ndef LAST(S_BOOL, A, B):                   \n    if A\u003cB: A=B                        #LAST(CLOSE\u003eOPEN,5,3)  \n    return S_BOOL[-A:-B].sum()==(A-B)    \n\ndef EXIST(S_BOOL, N=5):                # EXIST(CLOSE\u003e3010, N=5) \n    R=SUM(S_BOOL,N)    \n    return IF(R\u003e0, True ,False)\n\ndef BARSLAST(S_BOOL):                  \n    M=np.argwhere(S_BOOL);             # BARSLAST(CLOSE/REF(CLOSE)\u003e=1.1) \n    return len(S_BOOL)-int(M[-1])-1  if M.size\u003e0 else -1\n\ndef FORCAST(S,N):                      \n    K,Y=SLOPE(S,N,RS=True)\n    return Y[-1]+K\n  \ndef CROSS(S1,S2):                      # GoldCross CROSS(MA(C,5),MA(C,10))  \n    CROSS_BOOL=IF(S1\u003eS2, True ,False)  # DieCross CROSS(MA(C,10),MA(C,5))\n    return (COUNT(CROSS_BOOL\u003e0,2)==1)*CROSS_BOOL\n\n```\n\n```python\n\n# ------ Technical Indicators  ( 2 level only use 0,1 level functions to implemented) --------------\n\ndef MACD(CLOSE,SHORT=12,LONG=26,M=9):             \n    DIF = EMA(CLOSE,SHORT)-EMA(CLOSE,LONG);  \n    DEA = EMA(DIF,M);      MACD=(DIF-DEA)*2\n    return DIF,DEA,MACD\n\ndef KDJ(CLOSE,HIGH,LOW, N=9,M1=3,M2=3):          \n    RSV = (CLOSE - LLV(LOW, N)) / (HHV(HIGH, N) - LLV(LOW, N)) * 100\n    K = EMA(RSV, (M1*2-1));    D = EMA(K,(M2*2-1));        J=K*3-D*2\n    return K, D, J\n\ndef RSI(CLOSE, N=24):                          \n    DIF = CLOSE-REF(CLOSE,1) \n    return (SMA(MAX(DIF,0), N) / SMA(ABS(DIF), N) * 100)  \n\ndef WR(CLOSE, HIGH, LOW, N=10, N1=6):           \n    WR = (HHV(HIGH, N) - CLOSE) / (HHV(HIGH, N) - LLV(LOW, N)) * 100\n    WR1 = (HHV(HIGH, N1) - CLOSE) / (HHV(HIGH, N1) - LLV(LOW, N1)) * 100\n    return WR, WR1\n\ndef BIAS(CLOSE,L1=6, L2=12, L3=24):             \n    BIAS1 = (CLOSE - MA(CLOSE, L1)) / MA(CLOSE, L1) * 100\n    BIAS2 = (CLOSE - MA(CLOSE, L2)) / MA(CLOSE, L2) * 100\n    BIAS3 = (CLOSE - MA(CLOSE, L3)) / MA(CLOSE, L3) * 100\n    return BIAS1, BIAS2, BIAS3\n\ndef BOLL(CLOSE,N=20, P=2):                          \n    MID = MA(CLOSE, N); \n    UPPER = MID + STD(CLOSE, N) * P\n    LOWER = MID - STD(CLOSE, N) * P\n    return UPPER, MID, LOWER\n\ndef PSY(CLOSE,N=12, M=6):  \n    PSY=COUNT(CLOSE\u003eREF(CLOSE,1),N)/N*100\n    PSYMA=MA(PSY,M)\n    return PSY,PSYMA\n\ndef CCI(CLOSE,HIGH,LOW,N=14):  \n    TP=(HIGH+LOW+CLOSE)/3\n    return (TP-MA(TP,N))/(0.015*AVEDEV(TP,N))\n        \ndef ATR(CLOSE,HIGH,LOW, N=20):                    \n    TR = MAX(MAX((HIGH - LOW), ABS(REF(CLOSE, 1) - HIGH)), ABS(REF(CLOSE, 1) - LOW))\n    return MA(TR, N)\n\ndef BBI(CLOSE,M1=3,M2=6,M3=12,M4=20):             \n    return (MA(CLOSE,M1)+MA(CLOSE,M2)+MA(CLOSE,M3)+MA(CLOSE,M4))/4    \n\ndef DMI(CLOSE,HIGH,LOW,M1=14,M2=6):               \n    TR = SUM(MAX(MAX(HIGH - LOW, ABS(HIGH - REF(CLOSE, 1))), ABS(LOW - REF(CLOSE, 1))), M1)\n    HD = HIGH - REF(HIGH, 1);     LD = REF(LOW, 1) - LOW\n    DMP = SUM(IF((HD \u003e 0) \u0026 (HD \u003e LD), HD, 0), M1)\n    DMM = SUM(IF((LD \u003e 0) \u0026 (LD \u003e HD), LD, 0), M1)\n    PDI = DMP * 100 / TR;         MDI = DMM * 100 / TR\n    ADX = MA(ABS(MDI - PDI) / (PDI + MDI) * 100, M2)\n    ADXR = (ADX + REF(ADX, M2)) / 2\n    return PDI, MDI, ADX, ADXR  \n\n  \ndef TRIX(CLOSE,M1=12, M2=20):                      \n    TR = EMA(EMA(EMA(CLOSE, M1), M1), M1)\n    TRIX = (TR - REF(TR, 1)) / REF(TR, 1) * 100\n    TRMA = MA(TRIX, M2)\n    return TRIX, TRMA\n\ndef VR(CLOSE,VOL,M1=26):                            \n    LC = REF(CLOSE, 1)\n    return SUM(IF(CLOSE \u003e LC, VOL, 0), M1) / SUM(IF(CLOSE \u003c= LC, VOL, 0), M1) * 100\n\ndef EMV(HIGH,LOW,VOL,N=14,M=9):                     \n    VOLUME=MA(VOL,N)/VOL;       MID=100*(HIGH+LOW-REF(HIGH+LOW,1))/(HIGH+LOW)\n    EMV=MA(MID*VOLUME*(HIGH-LOW)/MA(HIGH-LOW,N),N);    MAEMV=MA(EMV,M)\n    return EMV,MAEMV\n\ndef DMA(CLOSE,N1=10,N2=50,M=10):                     \n    DIF=MA(CLOSE,N1)-MA(CLOSE,N2);    DIFMA=MA(DIF,M)\n    return DIF,DIFMA\n\ndef MTM(CLOSE,N=12,M=6):                             \n    MTM=CLOSE-REF(CLOSE,N);         MTMMA=MA(MTM,M)\n    return MTM,MTMMA\n\n \ndef EXPMA(CLOSE,N1=12,N2=50):                       \n    return EMA(CLOSE,N1),EMA(CLOSE,N2);\n\ndef OBV(CLOSE,VOL):                                 \n    return SUM(IF(CLOSE\u003eREF(CLOSE,1),VOL,IF(CLOSE\u003cREF(CLOSE,1),-VOL,0)),0)/10000\n\n```\n\n### Usage Example\n\n```python\n\nfrom  hb_hq_api import *         #  btc day data on Huobi cryptocoin exchange \nfrom  MyTT import *              #  to import lib\n\ndf=get_price('btc.usdt',count=120,frequency='1d');     #'1d'=1day , '4h'=4hour\n\n#-----------df view-------------------------------------------\n\n```\n\n|  |open|\tclose|\thigh\t|low|\tvol|\n|--|--|--|--|--|--|\n|2021-05-16\t|48983.62|\t47738.24|\t49800.00|\t46500.0\t|1.333333e+09 |\n|2021-05-17\t|47738.24|\t43342.50|\t48098.66|\t42118.0\t|3.353662e+09 |\n|2021-05-18\t|43342.50|\t44093.24|\t45781.52|\t42106.0\t|1.793267e+09 |\n\n\n```python\n\nCLOSE=df.close.values     #or  CLOSE=list(df.close)\nOPEN =df.open.values           \nHIGH =df.high.values    \nLOW = df.low.values            \n\nMA5=MA(CLOSE,5)                                       \nMA10=MA(CLOSE,10)                                     \n\nRSI12=RSI(CLOSE,12)\nCCI12=CCI(CLOSE,12)\nATR20=ATR(CLOSE,HIGH,LOW, N=20)\n\nprint('BTC5 MA5', MA5[-1] )                         \nprint('BTC MA10,RET(MA10))                         # RET(MA10) == MA10[-1]\nprint('today ma5 coross ma10? ',RET(CROSS(MA5,MA10)))\nprint('every close price\u003e ma10? ',EVERY(CLOSE\u003eMA10,5) )\n\n```\n\n### BOLL and  graphs\n\n```python\nup,mid,lower=BOLL(CLOSE)                                       \n\nplt.figure(figsize=(15,8))  \nplt.plot(CLOSE,label='shanghai');\nplt.plot(up,label='up');        \nplt.plot(mid,label='mid'); \nplt.plot(lower,label='lower');\n\n```\n\u003cdiv  align=\"center\"\u003e \u003cimg src=\"/img/boll.png\" width = \"960\" height = \"400\" alt=\"Boll\" /\u003e \u003c/div\u003e\n\n\n### python lib need to install \n* pandas numpy\n \n----------------------------------------------------\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpquant%2Fpython-financial-technical-indicators-pandas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmpquant%2Fpython-financial-technical-indicators-pandas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpquant%2Fpython-financial-technical-indicators-pandas/lists"}