For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
How to implement Percentile indicator?
-
pandas implementation
pctrank = lambda x: pd.Series(x).rank(pct=True).iloc[-1] df["n200"]=df["source"].rolling(200).apply(pctrank)
backtrader implementation ?
class Percentile(bt.Indicator): lines = ('percentile',) params = (('period', 15),) def __init__(self): self.lines.percentilee = pd.Series(self.data).rank(pct=True).iloc[-1]
-
It would seem you are looking for the
PercentRank
indicator.