Technical Indicators
Use a Technical Indicator
To use a technical indicator, the first step is to import the class. The code below will import the simple moving average indicator:
from surmount.technical_indicators import SMA
Next, just pass in the ticker, data dictionary, and any additional parameters required for the calculation. As you can see from the class definition for SMA, the only additional required parameter is length
, which is the number of days the moving average will be based on. The following run()
function will calculate the SMA of Apple over the past 50 days:
def run(self, data):
allocation_dict = {i: 1/len(self.tickers) for i in self.tickers}
ohlcv = data.get("ohlcv")
ratios = data.get(("insider_trading","AAPL"))
apple_sma_10days = SMA("AAPL", ohlcv, 10)
log(str(apple_sma_10days))
return TargetAllocation(allocation_dict)
The apple_sma_10days
variable will be a list in the following format:
[
177.024,
178.393,
179.671,
181.377,
183.421,
185.105,
...]
Technical Indicator Classes
technical_indicators.RSI(ticker, data, length)
Calculate relative strength index
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
|
technical_indicators.SMA(ticker, data, length)
Calculate simple moving average
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
|
technical_indicators.EMA(ticker, data, length)
Calculate exponential moving average
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
|
technical_indicators.MFI(ticker, data, length)
Calculate money flow index
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
|
technical_indicators.MACD(ticker, data, fast, slow)
Calculate moving average convergence divergence
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
fast
(int )
–
-
slow
(int )
–
|
Returns: |
-
Dict[str, List[float]]
–
dict with string key specifying MACD details and value list with float prices
|
technical_indicators.MACD_F(ticker, data, fast, slow)
Calculate moving average convergence divergence, same data as MACD above
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
fast
(int )
–
-
slow
(int )
–
|
Returns: |
-
Dict[str, List[float]]
–
dict with string key specifying MACD details and value list with float prices
|
technical_indicators.BB(ticker, data, length, std=1, band='')
Calculate Bollinger bands
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
-
std
(float , default:
1
)
–
the standard deviation width of the bollinger bands
-
band
(str , default:
''
)
–
an optional string that can be one of "upper", "lower", or "middle", returns all bands if empty
|
Returns: |
-
Dict[str, List[float]]
–
dict with string keys of upper, lower, and mid matching a list with float band prices
|
technical_indicators.Slope(ticker, data, length)
Calculate slope
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
|
technical_indicators.ADX(ticker, data, length)
Calculate ADX (average directional index)
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
|
technical_indicators.CCI(ticker, data, length)
Calculate CCI
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
|
technical_indicators.PPO(ticker, data, fast, slow)
Calculate PPO
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
fast
(int )
–
-
slow
(int )
–
|
technical_indicators.SO(ticker, data)
Calculate SO
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
|
technical_indicators.WillR(ticker, data, length)
Calculate Will%R
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
|
technical_indicators.STDEV(ticker, data, length)
Calculate STDEV
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
|
technical_indicators.VWAP(ticker, data, length)
Calculate VWAP
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
|
technical_indicators.Momentum(ticker, data, length)
Calculate Momentum
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
|
technical_indicators.PSAR(ticker, data)
Calculate PSAR
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
|
technical_indicators.OBV(ticker, data, length=0)
Calculate OBV
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int , default:
0
)
–
|
technical_indicators.ATR(ticker, data, length)
Calculate ATR
Parameters: |
-
ticker
(str )
–
-
data
(List[Dict[str, Dict[str, float]]] )
–
data as provided from the OHLCV data function
-
length
(int )
–
|