|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectfinance.Stats
public class Stats
This class contains functions that manipulate stock quotes. By placing them together in a single class, they can be used by both the Gondola language and charting functions.
| Field Summary | |
|---|---|
static int |
DEFAULT_RSI_PERIOD
This is the default/recommended period for the RSI. |
| Method Summary | |
|---|---|
static double |
avg(double[] source,
int period)
Find the average of the given quotes. |
static double |
avg(double[] source,
int period,
int startPoint)
|
static double |
bestFit(double[] source,
int period)
Calculate the line of best fit of the data given by source. |
static double[] |
bestFitFunction(double[] source,
int period)
Return the equation of the line of best fit of the data given by source. |
static double |
bollingerLower(double[] source,
int period)
Calculate the lower band of the bollinger graph. |
static double |
bollingerUpper(double[] source,
int period)
Calculate the upper band of the bollinger graph. |
static double |
corr(double[] x,
double[] y,
int period)
Calculate the Pearson product-moment correlation between the two variables. |
static double |
corr(double[] x,
double[] y,
int period,
int startpoint)
Calculate the Pearson product-moment correlation between the two variables. |
static double |
ema(double[] source,
int period,
double smoothingConstant)
Calculate the Exponential Moving Average (EMA) value. |
static double |
ema(double[] source,
int period,
int startPoint,
double smoothingConstant)
|
static double[] |
getAvg(double[] source,
int period)
Find the average of the given quotes. |
static double[] |
getEma(double[] source,
int period,
double smoothingConstant)
Calculate the Exponential Moving Average (EMA) value. |
static double |
macd(double[] sourceSlow,
double[] sourceFast)
Calculate the Moving Average Convergence Divergence (MACD) value. |
static void |
main(java.lang.String[] args)
|
static double |
momentum(double[] source,
int period)
Calculate the Momentum value. |
static int |
obv(double[] sourceOpen,
double[] sourceClose,
double[] sourceVolume,
int range,
int initialValue)
Calculate the On Balance Volume (OBV) value. |
static double |
roundDouble(double d,
int places)
|
static double |
rsi(double[] source,
int period)
Calculate the Relative Strength Indicator (RSI) value. |
static double |
sd(double[] source,
int period)
Find the standard deviation of the given values. |
static double |
sd(double[] source,
int period,
int startpoint)
Find the standard deviation of the given values. |
static double |
sma(double[] in,
int startPoint,
int period)
|
static void |
testSma()
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_RSI_PERIOD
| Method Detail |
|---|
public static double sd(double[] source,
int period)
source - the source quottesperiod - the number of days to average
public static double sd(double[] source,
int period,
int startpoint)
source - the source quottesperiod - the number of days to average
public static double[] getAvg(double[] source,
int period)
source - source of quotes to averageperiod - the number of days to average
public static double avg(double[] source,
int period,
int startPoint)
public static double corr(double[] x,
double[] y,
int period,
int startpoint)
r = sum(Zx * Zy)
------------
N - 1
Where Zx = X - E(X)
--------
Sx
Where E(X) is the mean of X and Sx is the standard deviation of X.
Simillarly for Zy.
x - values to test againsty - values to detect correlation against xperiod - number of days to analyse
public static double[] getEma(double[] source,
int period,
double smoothingConstant)
k is a smoothing
constant.
source - the source of quotes to averageperiod - the number of days to analysesmoothingConstant -
public static double ema(double[] source,
int period,
int startPoint,
double smoothingConstant)
public static double avg(double[] source,
int period)
source - source of quotes to averageperiod - the number of days to average
public static double corr(double[] x,
double[] y,
int period)
r = sum(Zx * Zy)
------------
N - 1
Where Zx = X - E(X)
--------
Sx
Where E(X) is the mean of X and Sx is the standard deviation of X.
Simillarly for Zy.
x - values to test againsty - values to detect correlation against xperiod - number of days to analyse
public static double rsi(double[] source,
int period)
100
RSI = 100 - ------
1 + RS
average of x days' up closes
RS = ------------------------------
average of x days' down closes
To calculate an X day RSI you need X + 1 quote values. So make
the period argument one more day that the period of the RSI.
public static double ema(double[] source,
int period,
double smoothingConstant)
k is a smoothing
constant.
source - the source of quotes to averageperiod - the number of days to analysesmoothingConstant - a smoothing constant
public static double macd(double[] sourceSlow,
double[] sourceFast)
sourceSlow - the source of quotes used by EMA to average (slow average)sourceFast - the source of quotes used by EMA to average (fast average)
public static double momentum(double[] source,
int period)
source - the source of quotes
public static int obv(double[] sourceOpen,
double[] sourceClose,
double[] sourceVolume,
int range,
int initialValue)
sourceOpen - the source of open quotessourceClose - the source of close quotessourceVolume - the source of volumesrange - the range which we calculate overinitialValue - the starting value of OBV
public static double bollingerUpper(double[] source,
int period)
source - the source of quotesperiod - the number of days to analyse
public static double bollingerLower(double[] source,
int period)
source - the source of quotesperiod - the number of days to analyse
public static double roundDouble(double d,
int places)
public static double bestFit(double[] source,
int period)
source - the source of quotesperiod - the number of days to analyse
public static double[] bestFitFunction(double[] source,
int period)
source - the source of quotesperiod - the number of days to analyse
public static void main(java.lang.String[] args)
public static void testSma()
public static double sma(double[] in,
int startPoint,
int period)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||