Skip to content

Commit

Permalink
change dir structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mw66 committed Sep 14, 2020
1 parent 3e5ecf4 commit 9d4a039
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 23 deletions.
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@

DUB=/usr/bin/dub
DUB=dub # /usr/bin/dub

SRC=source/talibd


all:
make -B source/talib_func.d
$(DUB) build -q
./talibd
make -B $(SRC)/talib_func.d
$(DUB) test --build=unittest


DPP=~/.dub/packages/dpp-0.4.2/dpp/bin/d++
DPPFLAGS = --preprocess-only --hard-fail --include-path=/home/linuxbrew/.linuxbrew/Cellar/ta-lib/0.4.0/include/ta-lib --keep-d-files --compiler=ldmd2 #dmd #ldc2 #
talib:
$(DPP) $(DPPFLAGS) source/talib.dpp
$(DPP) $(DPPFLAGS) $(SRC)/talib.dpp

source/talib_func.d: source/talib_func.h
$(SRC)/talib_func.d: $(SRC)/talib_func.h
cpp -P $< | sed 's/__NL__/\n/g' > $@

clean:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ just type `make` to run it:
$ make
...
$ ./talibd
Run some tests
prices.length=755
test TA_MA
Expand Down
5 changes: 0 additions & 5 deletions source/package.d

This file was deleted.

6 changes: 4 additions & 2 deletions source/oo.d → source/talibd/oo.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import talib;
import talibd;
module talibd.oo;

import talibd.talib;
import talibd.talib_func;

// oo wrapper

Expand Down
5 changes: 5 additions & 0 deletions source/talibd/package.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module talibd;

public import talibd.talib; // raw D interface of C
public import talibd.talib_func; // simplified D func
public import talibd.oo; // D wrapper
1 change: 1 addition & 0 deletions source/talib.d → source/talibd/talib.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module talibd.talib;

public import core.stdc.stdio;

Expand Down
File renamed without changes.
11 changes: 6 additions & 5 deletions source/talib_func.d → source/talibd/talib_func.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module talibd.talib_func;
import std.math;
import fluent.asserts;
import talib;
import talibd.talib;
/+
TA_RetCode TA_RSI( int startIdx,
int endIdx,
Expand Down Expand Up @@ -58,7 +59,7 @@ bool TA_MA(double[] inData , double[] outMA , int MA_optInTimePeriod=default_MA_
}
outMA[0..lookback] = 0;

auto r = talib.TA_MA(0, cast(int)(inData.length-1), inData.ptr, MA_optInTimePeriod,optInMAType, &begin, &num ,
auto r = talibd.talib.TA_MA(0, cast(int)(inData.length-1), inData.ptr, MA_optInTimePeriod,optInMAType, &begin, &num ,
&(outMA[lookback]));

Assert.equal(lookback, begin);
Expand All @@ -70,7 +71,7 @@ bool TA_MA(double[] inData , double[] outMA , int MA_optInTimePeriod=default_MA_

/+ manual wrapper
bool TA_RSI(double[] inData, double[] outRSI, int period=default_RSI_optInTimePeriod) {
auto r = talib.TA_RSI(0, cast(int)(inData.length-1), inData.ptr, period, &begin, &num, &(outRSI[lookback]));
auto r = talibd.talib.TA_RSI(0, cast(int)(inData.length-1), inData.ptr, period, &begin, &num, &(outRSI[lookback]));
}
+/
immutable int default_RSI_optInTimePeriod = 14;
Expand All @@ -86,7 +87,7 @@ bool TA_RSI(double[] inData , double[] outRSI , int RSI_optInTimePeriod=default_
}
outRSI[0..lookback] = 0;

auto r = talib.TA_RSI(0, cast(int)(inData.length-1), inData.ptr, RSI_optInTimePeriod, &begin, &num ,
auto r = talibd.talib.TA_RSI(0, cast(int)(inData.length-1), inData.ptr, RSI_optInTimePeriod, &begin, &num ,
&(outRSI[lookback]));

Assert.equal(lookback, begin);
Expand Down Expand Up @@ -115,7 +116,7 @@ bool TA_MACD(double[] inData , double[] outMACD, double[] outMACDSignal, double[
outMACDSignal[0..lookback] = 0;
outMACDHist[0..lookback] = 0;

auto r = talib.TA_MACD(0, cast(int)(inData.length-1), inData.ptr, optInFastPeriod,optInSlowPeriod,optInSignalPeriod, &begin, &num ,
auto r = talibd.talib.TA_MACD(0, cast(int)(inData.length-1), inData.ptr, optInFastPeriod,optInSlowPeriod,optInSignalPeriod, &begin, &num ,
&(outMACD[lookback]),
&(outMACDSignal[lookback]),
&(outMACDHist[lookback]));
Expand Down
8 changes: 5 additions & 3 deletions source/talib_func.h → source/talibd/talib_func.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module talibd.talib_func;

import std.math;

import fluent.asserts;

import talib;
import talibd.talib;


#define HEAD(x, ...) x
Expand Down Expand Up @@ -124,7 +126,7 @@ bool TA_FUNC(double[] inData FOR_EACH(DECL_ARRAY_TYPE, FUNC_OUTS) FOR_EACH(SPLIT
return false; __NL__\
} __NL__\
FOR_EACH(INIT_OUTPUT, FUNC_OUTS) __NL__\
auto r = talib.TA_FUNC(0, cast(int)(inData.length-1), inData.ptr, FOR_EACH(SPLIT_THEN_TAKE_VAR, FUNC_INS) &begin, &num OUT_PARAMS(FUNC_OUTS)); __NL__\
auto r = talibd.talib.TA_FUNC(0, cast(int)(inData.length-1), inData.ptr, FOR_EACH(SPLIT_THEN_TAKE_VAR, FUNC_INS) &begin, &num OUT_PARAMS(FUNC_OUTS)); __NL__\
__NL__\
Assert.equal(lookback, begin); /* RSI's start 0-data need to compare with prev close, so this assert holds; in contrast for TA_MA */ __NL__\
Assert.equal(begin + num, cast(int)(inData.length)); __NL__\
Expand All @@ -147,7 +149,7 @@ DECL_TA_FUNC(TA_MA, MA_INS, MA_OUTS, (MA_optInTimePeriod-1))

/+ manual wrapper
bool TA_RSI(double[] inData, double[] outRSI, int period=default_RSI_optInTimePeriod) {
auto r = talib.TA_RSI(0, cast(int)(inData.length-1), inData.ptr, period, &begin, &num, &(outRSI[lookback]));
auto r = talibd.talib.TA_RSI(0, cast(int)(inData.length-1), inData.ptr, period, &begin, &num, &(outRSI[lookback]));
}
+/

Expand Down
13 changes: 12 additions & 1 deletion source/app.d → source/talibd/test.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module talibd.test;

import std.algorithm;
import std.csv;
import std.experimental.logger;
Expand All @@ -7,11 +9,16 @@ import std.typecons;

import fluent.asserts;
public import jdiutil;
import talibd;

public import talibd.talib; // raw D interface of C
public import talibd.talib_func; // simplified D func
public import talibd.oo; // D wrapper


alias logger = std.experimental.logger;

unittest {

void main() {
writeln("read test data");
string fn = "testdata/SPY.csv";
Expand Down Expand Up @@ -114,3 +121,7 @@ void main() {
assert(approxEqual(ema13[$-1], 340.794, maxRelDiff));
}
}

main();

}

0 comments on commit 9d4a039

Please sign in to comment.