This page introduces the API related to calculating stock market indicators. All the functions here without extra specified, will calculate indicator for the current date, according to the global date pointer.
Calculate the n days' moving average of a security.
Argument | Type | Function | Remarks |
---|---|---|---|
permno | String | Indicate the target security | |
n | Positive Integer > 1 | Indicate length of the moving window including today |
Return
Double, if the security exists. nil
otherwise.
Example
=> (moving-avg "28636" 10)
Calculate the n days' moving standard deviation of a security.
Argument | Type | Function | Remarks |
---|---|---|---|
permno | String | Indicate the target security | |
n | Positive Integer > 1 | Indicate length of the moving window including today |
Return
Double, if the security exists. nil
otherwise.
Example
=> (moving-sd "28636" 10)
Calculate the EMA of a security. If called the first time, will return the EMA-CYCLE
-day moving average. After this, EMA will be updated based on its definition. This update process is automatic.
Argument | Type | Function | Remarks |
---|---|---|---|
permno | String | Indicate the target security |
Relevant Parameter
EMA-CYCLE
: the length of moving average when EMA first called.
Return
Double, if the security exists. nil
otherwise.
Example
=> (EMA "28636")
Generator of the EMA function for the specified cycle.
Argument | Type | Function | Remarks |
---|---|---|---|
cycle | Positive Int | Indicate the size of cycle |
Return
EMA function having the same usage as above with a different cycle.
Example
=> (def EMA10 (EMA-generator 10))
=> (EMA10 "28636")
8.0375
=> (def EMA20 (EMA-generator 20))
=> (= (EMA20 "28636") (EMA "28636"))
true
Calculate the Moving average convergence / divergence of a security.
Argument | Type | Function | Remarks |
---|---|---|---|
permno | String | Indicate the target security |
Relevant Parameter
MACD-SIGNAL
: the cycle of the signal EMA
MACD-SHORT
: the cycle of the short EMA
MACD-LONG
: the cycle of the long EMA
Return
A sequence, [{MACD} {Signal EMA} {Short EMA} {Long EMA}], if the security exists. nil
otherwise.
Example
=> (MACD "28636")
[-0.34999999999999787 11.182222222222222 11.185 11.534999999999998]
Generator of the MACD function for the specified cycle.
Argument | Type | Function | Remarks |
---|---|---|---|
signal-cycle | Positive Int | Indicate the size of EMA cycle of the signal line | |
short-cycle | Positive Int | Indicate the size of EMA cycle of the short line | |
long-cycle | Positive Int | Indicate the size of EMA cycle of the long line |
Return
MACD function having the same usage as above with a different cycle.
Example
=> (def MACD102030 (MACD-generator 10 20 30))
=> (MACD102030 "28636")
[-0.03958333333333286 8.0375 8.70625 8.745833333333334]
=> (def MACD91226 (MACD-generator 9 12 26))
=> (= (MACD91226 "28636") (MACD "28636"))
true
parabolic-SAR
This function calculates the Parabolic Stop and Reverse (SAR).
Parameters:
permno
- the symbol of a securitymode
- "lazy" or "non-lazyaf
- acceleration factorprev-psar
- SAR value of the previous periodOutput:
parabolic-SAR
Possible usages:
(let [prev-close (Double/parseDouble (get (first (get-prev-n-days :PRC 1 "OMFGA")) :PRC))]
(println (parabolic-SAR "OMFGA" "non-lazy" 0.2 prev-close))
)
ROC
This function calculates the Rate of Change (ROC) indicator.
Parameters:
permno
- the name of the securityn
- time windowOutput:
ROC
Possible usages:
(println (ROC "58043" 20)
RSI
This function calculates the Relative Strength Index (RSI) indicator.
Parameters:
permno
- the name of the securityOutput:
RSI
Related Parameter:
RSI-CYCLE
: By default 14.Possible usages:
(RSI "58043" 20)
RSI-generator
This function generates user-defined Relative Strength Index (RSI) calculator.
Parameters:
n
- time windowOutput:
RSI
Possible usages:
=> (def RSI10 (RSI-generator 10))
=> (RSI10 "28636")
52.67
=> (def RSI14 (RSI-generator 14))
=> (= (RSI14 "28636") (RSI "28636"))
true
ATR
This function calculates standard deviation of a stock for the last n days.
Parameters:
permno
- the name of the securityn
- average of the daily TR values for the last n daysPossible usages:
=> (ATR "28637" 10)
keltner-channel
This function calculates the Keltner Channel value of a stock for the last n days.
Parameters:
permno
- the name of the securitywindow
- time windowPossible usages:
=> (keltner-channel "28637" 10)