Install XWiki on Glassfish and Derby
I've upgraded blogtrade.org to glassfish b48, with XWiki and javadb (Apache Derby) integrated. Here is a short guide I posted:
http://blogtrader.org/wiki/bin/view/KnowledgeBase/XWikiGlassfishDerby
Primary support for Buy/Sell Signals in BlogTrader Platform
The primary support for Buy/Sell signals has been implemented in BlogTrader Platform, inculding SignalChart, SignalIndictor etc.The signal indicators will be put in a separate module: "BlogTrader Platform Modules Basic Signal"
Below is a screenshot of signals generated by MACD's slow line cross fast line. The blue arrows indicate the signals:
The sample code:
public class MACDSignal extends AbstractSignalIndicator { Opt periodFast = new DefaultOpt("Period EMA Fast", 12.0); Opt periodSlow = new DefaultOpt("Period EMA Slow", 26.0); Opt periodSignal = new DefaultOpt("Period Signal", 9.0); Varfast = new DefaultVar(); Var slow = new DefaultVar(); { _sname = "MACD Signal"; _lname = "Moving Average Convergence/Divergence Signal"; } void computeCont(int begIdx) { for (int idx = begIdx; idx < _dataSize; idx++) { fast.set(idx, macd(idx, C, periodSlow, periodFast)); slow.set(idx, ema(idx, fast, periodSignal)); if (crossOver(idx, fast, slow)) { signal(idx, Sign.EnterLong); } if (crossUnder(idx, fast, slow)) { signal(idx, Sign.ExitLong); } } } }
Design of Function of Technical Analysis (Part I)
As the basic atom for indicator computation, the function design for TA should consider:
- It can be computed at any idx or time point, whenever -- computeSpot(int idx) or computeSpot(long time)
- It can correspond to the Options change (Options are transfered in by the caller as reference)
- It can remember the intermedial status of function instance to avoid redundant computation. The status includes
- backward values (as it's a TimeSeries's variable)
- the based Variables
- the Options
- the caller
Then an indicator instance can call it to:
- compute from 'begIdx' to 'endIdx'
- compute at point 'idx'
Supported TA Functions Currently
Below are the TA functions that have been implemented. The corresponding indicators were re-written based on these functions too.
More functions will be listed here as they are implemented.
float max(int idx, Var var, Opt period) float min(int idx, Var var, Opt period) float sum(int idx, Var var, Opt period) float ma(int idx, Var var, Opt period) float ema(int idx, Var var, Opt period) float stdDev(int idx, Var var, Opt period) float tr(int idx) float dmPlus(int idx) float dmMinus(int idx) float diPlus(int idx, Opt period) float diMinus(int idx, Opt period) float dx(int idx, Opt period) float adx(int idx, Opt periodDi, Opt periodAdx) float adxr(int idx, Opt periodDi, Opt periodAdx) float bollUpper(int idx, Var var, Opt period, Opt alpha) float bollLower(int idx, Var var, Opt period, Opt alpha) float bollMiddle(int idx, Var var, Opt period, Opt alpha) float cci(int idx, Opt period, Opt alpha) float macd(int idx, Var var, Opt periodSlow, Opt periodFast) float mfi(int idx, Opt period) float mtm(int idx, Var var, Opt period) float obv(int idx) float roc(int idx, Var var, Opt period) float rsi(int idx, Opt period) float sar(int idx, Opt initial, Opt step, Opt maximum) Direction sarDirection(int idx, Opt initial, Opt step, Opt maximum) float stochK(int idx, Opt period, Opt periodK) float stochD(int idx, Opt period, Opt periodK, Opt periodD) float stochJ(int idx, Opt period, Opt periodK, Opt periodD) float wms(int idx, Opt period) float[][] probMass(int idx, Varvar, Opt period, Opt nInterval) float[][] probMass(int idx, Var var, Var weight, Opt period, Opt nInterval) -------------------------------------------------------------- boolean crossOver(int idx, Var var1, Var var2) boolean crossOver(int idx, Var var, float value) boolean crossUnder(int idx, Var var1, Var var2) boolean crossUnder(int idx, Var var, float value) boolean turnUp(int idx, Var var) boolean turnDown(int idx, Var var) -------------------------------------------------------------- signal(int idx, Sign sign, String name) signal(int idx, Sign sign) enum Sign { EnterLong, ExitLong, EnterShort, ExitShort; } --------------------------------------------------------------
Switch to GPL
BlogTrader Platform has switched to GPL license.
The source code that have been released under BSD will be moved to a special tag on SVN, the trunk will be the newer GPLed source tree.
This project won't accept new developers until all the license policy is clearly defined.
(See discuss in Switch to GPL license?)
Patchs and bugs report are welcome.
Do we need two forms for each TA function?
There are 2 forms could be defined for each TA function, such as:</p>
1. Var emaVar(Var var, Opt period) 2. float ema(int idx, Var var, Opt period)
The first one will return a series of variable which have been calculated;<br /> The second one just return one value in the series that is exactly at point idx.
Now, let's apply the two forms to the MACD indicator:
public class MACDIndicator extends AbstractContIndicator { Opt periodS = new DefaultOpt("Period Short", 12.0); Opt periodL = new DefaultOpt("Period Long", 26.0); Opt periodD = new DefaultOpt("Period Diff", 9.0 ); Var<Float> dif, dea, macd, ema1, ema2; protected void go() { dif = new DefaultVar("DIF", Chart.LINE); // here, the emaVar may be wrongly used, because the dif // should be pre-calculated. dea = emaVar(dif, periodD); macd = new DefaultVar("MACD", Chart.STICK); ema1 = emaVar(C, periodS); ema2 = emaVar(C, periodL); } protected void computeCont(int begIdx) { for (int i = begIdx; i < _dataSize; i++) { dif.set(i, ema1.get(i) - ema2.get(i)); macd.set(i, dif.get(i) - dea.get(i)); } } }
In the MACD example, there came out calculating dependency order issue if we apply 1st form function no properly. That is, the 'dea' actually should be calculated after the 'dif'. And it's difficult to insert the emaVar() into the proper place (should be in the 'for' clause, exactly after the point 'i' of 'dif' is calculated), because emaVar() is not aware of 'i'
To avoid these confusion, we should only provide the second function:
float ema(int idx, Var var, Opt period)
and force the developer to write the code as:
public class MACDIndicator extends AbstractContIndicator { Opt periodS = new DefaultOpt("Period Short", 12.0); Opt periodL = new DefaultOpt("Period Long", 26.0); Opt periodD = new DefaultOpt("Period Diff", 9.0 ); Var<Float> dif, dea, macd, ema1, ema2; { _sname = "MACD"; _lname = "Moving Average Convergence/Divergence"; ema1 = new DefaultVar(); ema2 = new DefaultVar(); dif = new DefaultVar("DIF", Chart.LINE); dea = new DefaultVar("DEA", Chart.LINE); macd = new DefaultVar("MACD", Chart.STICK); } protected void computeCont(int begIdx) { for (int i = begIdx; i < _dataSize; i++) { ema1.set(i, ema(i, C, periodS)); ema2.set(i, ema(i, C, periodL)); dif.set(i, ema1.get(i) - ema2.get(i)); dea.set(i, ema(i, dif, periodD)); macd.set(i, dif.get(i) - dea.get(i)); } } }
This version makes the calculating dependency order clearly, no more confusion.</p>