Skip to content

Commit

Permalink
Merge pull request #7 from jkotra/2.0
Browse files Browse the repository at this point in the history
algoticks 2.0
  • Loading branch information
jkotra authored Mar 17, 2021
2 parents f046de3 + de1757e commit 4790a7c
Show file tree
Hide file tree
Showing 31 changed files with 1,080 additions and 916 deletions.
25 changes: 23 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,33 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "(gdb) Launch",
"name": "(gdb) Launch (Linux)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/debug/algoticks",
"args": ["-D","1", "-s", "7117"],
"args": ["-D","1"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/bin/debug/",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},

{
"name": "(gdb) Launch (Windows)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/debug/algoticks.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/bin/debug/",
"environment": [],
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ upon successful compilation, the binary executable along with config files are f
### Building on Windows (experimental)

1. Install [MSYS2](https://www.msys2.org/)
2. Install [CMake for Windows.](https://cmake.org/download/)
2. Add the following to System PATH:
```
C:\msys64\mingw64\include
Expand All @@ -67,17 +68,16 @@ C:\msys64\mingw64\lib
C:\msys64\usr\bin
```

Run the following commands in MSYS2 terminal:
Run the following commands in `mingw64.exe` terminal:
```
pacman -S base-devel mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb mingw-w64-x86_64-json-c mingw-w64-x86_64-zeromq
cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
```

Run the following in CMD from repository root directory:
Run the following commands from repository root directory:
```
mkdir bin
cd bin
cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
cmake -G "MSYS Makefiles" ..
make
```

Expand Down
2 changes: 1 addition & 1 deletion assets/configs/linux/benchmark.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"quantity": [10],
"target": [1.5,2,2.5],
"stoploss": [2,2.5,3,3.5],
"is_training_sl": [true,false],
"is_trailing_sl": [true,false],
"trailing_sl_val": [1,2,3],

"sliding": [true, false],
Expand Down
2 changes: 1 addition & 1 deletion assets/configs/linux/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"quantity": 100,
"target": 5,
"stoploss": 7,
"is_training_sl": false,
"is_trailing_sl": false,
"trailing_sl_val": 1,

"sliding": true,
Expand Down
2 changes: 1 addition & 1 deletion assets/configs/windows/benchmark.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"quantity": [10],
"target": [1.5,2,2.5],
"stoploss": [2,2.5,3,3.5],
"is_training_sl": [true,false],
"is_trailing_sl": [true,false],
"trailing_sl_val": [1,2,3],

"sliding": [true, false],
Expand Down
2 changes: 1 addition & 1 deletion assets/configs/windows/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"quantity": 100,
"target": 5,
"stoploss": 7,
"is_training_sl": false,
"is_trailing_sl": false,
"trailing_sl_val": 1,

"sliding": true,
Expand Down
Binary file modified assets/derivative_example.zip
Binary file not shown.
5 changes: 4 additions & 1 deletion include/callbacks.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
int load_callbacks(algoticks_config config);
int load_callbacks(algoticks_config *config);
int send_callbacks(algoticks_event events);
int close_callbacks();
algoticks_event make_event_from_positionresult(algoticks_positionresult positionresult);
algoticks_event make_event_from_signal(algoticks_signal signal);
algoticks_event make_event_from_position(algoticks_row pos_storage, algoticks_dashboard dashboard);
6 changes: 3 additions & 3 deletions include/csvutils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define MAXCHARPERLINE 1024
#define MAXCSVHEAD 11
#define MAXCSVHEAD 12

/* Declarations */
void reset_header_skip();
Expand All @@ -9,6 +9,6 @@ int change_in_modified_date(char* filename);
int reopen_datasource(char* filename, FILE** fp, char* mode);
algoticks_row tokenize_row(char *row);
void set_ohlcv_as_header();
int process_csv_header(algoticks_settings settings, char *row);
int read_csv(algoticks_settings settings,algoticks_config config, FILE *fp, char *fname, algoticks_row *storage, int seek_offset);
int process_csv_header(algoticks_settings *settings, char *row);
int read_csv(algoticks_settings *settings,algoticks_config *config, FILE *fp, char *fname, algoticks_row *storage, int seek_offset);
int is_quoted(char *str);
2 changes: 1 addition & 1 deletion include/dashboard.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* Declarations */
float getPnL(algoticks_dashboard dashboard);
void print_dashboard(algoticks_settings settings,algoticks_config config,algoticks_dashboard dashboard);
void print_dashboard(algoticks_settings *settings,algoticks_config *config,algoticks_dashboard dashboard);
14 changes: 7 additions & 7 deletions include/debug.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Declarations */
void debug_msg(algoticks_settings settings, int debug_level, char *op, char *loc, char *remarks);

void debug_msg(bool settings_debug, int settings_debug_level, int msg_debug_level, char *file_name, const char *function, int line_n, char *message);
void debug_msg_simple(char* msg);
/* struct debug */
void print_config_struct(algoticks_config config);
void print_dashboard_struct(algoticks_dashboard dashboard);
void print_signal_struct(algoticks_signal signal);
void print_simresult_struct(algoticks_simresult simresult);
void print_row_struct(algoticks_row row);
void print_config_struct(algoticks_config *config);
void print_dashboard_struct(algoticks_dashboard *dashboard);
void print_signal_struct(algoticks_signal *signal);
void print_simresult_struct(algoticks_simresult *simresult);
void print_row_struct(algoticks_row *row);
112 changes: 56 additions & 56 deletions include/dtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ typedef struct Settings
int debug;
int debug_level;

char config_f[512];
char benchmark_f[512];
char *config_f;
char *benchmark_f;

int is_live_data;
int is_live_data_socket;
char socket_port[12];
char *socket_port;
int is_derivative;
int is_benchmark; /* for windows usage */

Expand All @@ -20,80 +20,80 @@ typedef struct Settings
}algoticks_settings;

typedef struct Dervative{
char derivative_datasource[512];
char *derivative_datasource;
int derivative_interval;
}algoticks_derivative;



typedef struct Config
{
char *algo;
char *datasource;
algoticks_derivative derivative;
char *symbol;
int candles;
int interval;

char **callbacks;
int n_callbacks;

double target;
double stoploss;
int is_trailing_sl; /* FLAG */
double trailing_sl_val;
int quantity;

int sliding; /* FLAG */
int intraday; /* FLAG */

int skip_header; /* FLAG */
}algoticks_config;

typedef struct BenchmarkConfig
{
char algo[1024][32];
int n_algo;

char datasource[1024][512];
char *symbol;

int n_algo;
char **algo_arr;

int n_datasource;
char **datasource_arr;

algoticks_derivative derivative;
int n_derivative;

char symbol[32];

int candles[1024];
int n_candles;
int *candles_arr;

int interval[1024];
int n_interval;
int *interval_arr;

double target[1024];
int n_target;
double *target_arr;

double stoploss[1024];
int n_stoploss;
double *stoploss_arr;

int n_is_trailing_sl;
int *is_trailing_sl; /* array of bool */

int is_training_sl[2];
int n_is_training_sl;

double trailing_sl_val[1024];
int n_trailing_sl_val;
double *trailing_sl_val_arr;

int quantity[1024];
int n_quantity;

int sliding[2];
int n_quantity;
int *quantity_arr;

int n_sliding;
int *sliding; /* array of bool */

int intraday[2];
int n_intraday;
int *intraday; /* array of bool */

int skip_header;

}algoticks_benchmarkconfig;


typedef struct Config
{
char algo[32];
char datasource[512];
algoticks_derivative derivative;
char symbol[32];
int candles;
int interval;

char callbacks[6][32];
int n_callbacks;

double target;
double stoploss;
int is_training_sl;
double trailing_sl_val;
int quantity;

int sliding;
int intraday;

int skip_header;
}algoticks_config;


typedef struct Dashboard
{
char date[32];
Expand All @@ -117,9 +117,9 @@ typedef struct row_ti{
float ti3;

int is_ti_others_p;
char ti_others[2048];
char *ti_others;

}algoticks_tow_ti;
}algoticks_row_ti;

typedef struct Row
{
Expand All @@ -131,7 +131,7 @@ typedef struct Row
float close;
int volume;

algoticks_tow_ti technical_indicators;
algoticks_row_ti technical_indicators;

int curr;
int n_rows; //this is to be set in case of Row array of non-predetermined size.
Expand Down Expand Up @@ -194,11 +194,11 @@ typedef struct Event {
int t_h;
int sl_h;

int tsl;
float tsl_t;
float tsl_sl;
int tsl; /* trailing SL */
float tsl_t; /* trailing SL target */
float tsl_sl; /* trailing SL stoploss */

char date[64];
char date[32];
float a;
float b;
float pnl;
Expand Down
12 changes: 6 additions & 6 deletions include/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
algoticks_cb_l load_cb(char *algo);
algo_func load_algo_func(char *algo);
void close_algo_func();
void write_simresult_to_csv(algoticks_simresult simresult);
void write_simresult_to_csv(algoticks_simresult *simresult);
void create_setting_config_benchmark_files(int type);
int is_file_exists(const char * filename);
void chomp(char *s);
algoticks_benchmarkconfig parse_benchmark_from_json(char *filename);
algoticks_settings parse_settings_from_json(char *filename);
algoticks_config parse_config_from_json(char *filename);
algoticks_config filter_boundaries(algoticks_config config, int is_short);
void filter_boundaries(algoticks_config *config, int is_short);
int is_target_hit(algoticks_dashboard dashboard, float target);
int is_stoploss_hit(algoticks_dashboard dashboard, float stoploss);
float brokerage_calc();
void convert_to_lowercase(char *str);
void remove_quotes(char *str);
void remove_quotes(char *str);
void free_algoticks_config(algoticks_config *config);
void free_algoticks_settings(algoticks_settings *settings);
void free_algoticks_benchmark(algoticks_benchmarkconfig *benchmark);
3 changes: 3 additions & 0 deletions include/parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
algoticks_settings parse_settings_from_json(char *filename);
algoticks_config parse_config_from_json(char *filename);
algoticks_benchmarkconfig parse_benchmark_from_json(char *filename);
4 changes: 2 additions & 2 deletions include/sim.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* Declarations */
algoticks_simresult run_sim(algoticks_settings settings, algoticks_config config);
algoticks_positionresult take_position(algoticks_signal signal, FILE *fp, int curr, algoticks_settings settings, algoticks_config config,algoticks_row lastrow);
algoticks_simresult run_sim(algoticks_settings *settings, algoticks_config *config);
algoticks_positionresult take_position(algoticks_signal signal, FILE *fp, int curr, algoticks_settings *settings, algoticks_config *config,algoticks_row lastrow);
4 changes: 2 additions & 2 deletions include/sim_derivative.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* Declarations */
algoticks_simresult run_sim_w_derivative(algoticks_settings settings, algoticks_config config);
algoticks_positionresult take_position_w_derivative(algoticks_signal signal, FILE *index_f, FILE *derivative_f, algoticks_settings settings, algoticks_config config, algoticks_row lastrow);
algoticks_simresult run_sim_w_derivative(algoticks_settings *settings, algoticks_config *config);
algoticks_positionresult take_position_w_derivative(algoticks_signal signal, FILE *index_f, FILE *derivative_f, algoticks_settings *settings, algoticks_config *config, algoticks_row lastrow);
2 changes: 1 addition & 1 deletion include/timeutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ int is_date_over_or_eq_intraday(char *date, int intraday_hour, int intraday_min)
int is_date_after(char *date_a, char *date_b);
int is_date_before(char *date_a, char *date_b);
int get_time_with_sscanf_from_string(char* date, struct tm *time_struct);
int sync_curr(algoticks_settings settings, algoticks_config config, FILE *f, char* fname, char *date, int seek_offset, int debug);
int sync_curr(algoticks_settings *settings, algoticks_config *config, FILE *f, char* fname, char *date, int seek_offset, int debug);
Loading

0 comments on commit 4790a7c

Please sign in to comment.