Commit b407be28 authored by denis's avatar denis

daynr bug and related faulty creation of translation currencies under certain conditions resolved.

parent 63435c03
Pipeline #12398572 passed with stage
in 1 minute and 57 seconds
CC = gcc-5
CC = gcc
CXX = g++
CSRCPATH = $(wildcard src/*.c)
CXXSRCPATH = $(wildcard src/*.cpp)
......
......@@ -101,7 +101,7 @@ unsigned int create_currency_translation_table(bstring *currencies,
(*from_curr)[nr_table_entries-1] = bstrcpy(currencies[i]);
// set this symbol´s currency translation table position
(*tablepos)[i] = nr_table_entries-1;
printf("%s found. %i ", bdata(currencies[i]), nr_table_entries);
// printf("%s found. %i ", bdata(currencies[i]), nr_table_entries);
}
already_in_list=false;
......@@ -338,16 +338,42 @@ bool assign_translation_currencies(bstring *symbols, bstring *currencies,
return no_error;
}
// reorder markets in a way that markets with account currency come first
// (otherwise the algorithm used in assign_translation_currencies will fail)
// (easy example: configured markets with currencies USD, EUR --> first loop
// iteration will overwrite translation_currencie[0] with USDEUR which is not
// desired)
///////////////////////////////////////////////////////////////////////////////
/**
* @brief reorder markets so that the ones in account currency come first
*
* This function reorders the markets in a way that markets with account
* currency come first (otherwise the algorithm used in
* assign_translation_currencies will fail- easy example: configured markets
* with currencies USD, EUR --> first loop iteration will overwrite
* translation_currencie[0] with USDEUR which is not desired).
* The function simple sorts all market-related 1xN vectors using bubblesort
*
* @note by convention the first element of the translation table is the
* account currency to account currency (which is 1 of course)
* looks rather silly but simplifies the handling of all symbols
* without catching the special case when a market is in the account
* currency
*
* @note example: account currency is EUR, currency of 1st symbol
* (stored in from_curr[0]) is JPY
* ==> translation_currencies[1].symbol = "JPYEUR"
*
* @param *symbols pointer to 1xN vector with all symbols/markets as configured
* @param nr_symbols uint total number of symbols/markets
* @param *ticks_pips float pointer to 1xN vector with all markets tick sizes
* @param *contract_sizes float pointer to 1xN vector with all contract sizes
* @param *currencies bstring pointer to 1xN vector with all markets currencies
* @param *symboltype bstring pointer to [...] market types
* @return true successfull, false if not
*/
///////////////////////////////////////////////////////////////////////////////
//
int reorder_markets_by_currency(bstring *symbols, int nr_symbols, float *ticks_pips, float *contract_sizes, bstring *currencies, bstring *symboltypes)
{
extern parameter parms; // parms are declared global in ichinscratchy.c
// use bubblesort to sort symbols (and relevant 1xN vectors
for(unsigned int i=0; i<nr_symbols-1; i++)
{
for(unsigned int j=0; j<nr_symbols-i-1; j++)
......@@ -388,7 +414,27 @@ int reorder_markets_by_currency(bstring *symbols, int nr_symbols, float *ticks_p
return EXIT_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
/**
* @brief fill translation currencies with data (quotes, dates, daynrs)
*
* This function fills the translation currencies with data (quotes, dates,
* daynrs).
*
* @note by convention the first element of the translation table is the
* account currency to account currency (which is 1 of course)
* looks rather silly but simplifies the handling of all symbols
* without catching the special case when a market is in the account
* currency
*
* @note the 2nd argument is the number of currencies (e.g. "2"), the 1xN
* vector with the currencies themselves starts at position 0.
*
* @param **currencies pointer to 1xN vector with translation currencies
* @param nr_currencies uint with total number of currencies
* @return true successfull, false if not
*/
///////////////////////////////////////////////////////////////////////////////
int populate_translation_currencies(translation_currency **currencies, unsigned int nr_currencies)
{
extern parameter parms; // parms are declared global in ichinscratchy.c
......@@ -457,6 +503,18 @@ int populate_translation_currencies(translation_currency **currencies, unsigned
return EXIT_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
/**
* @brief return translation quote for given date (YYYY-MM-DD)
*
* This function returns the quote of a given translation currencies for a
* specified date (format YYYY-MM-DD)
*
* @param the_date bstring with date (YYYY-MM-DD)
* @param *the_currency pointer to translation currency
* @return quote as float
*/
///////////////////////////////////////////////////////////////////////////////
float get_translation_quote(bstring the_date, translation_currency *the_currency)
{
float the_quote = 0.0;
......
......@@ -62,4 +62,5 @@ int populate_translation_currencies(translation_currency **currencies, unsigned
float get_translation_quote(bstring the_date, translation_currency *the_currency);
#endif // CURRENCIES_H
// eof
......@@ -270,18 +270,10 @@ int main (int argc, char **argv)
ichimoku_plot_chart(symbols[current_symbol]);
}
printf("\n");
for(unsigned int i=0; i<nr_symbols; i++)
printf("\t%s", bdata(symbols[i]));
// reorder markets in a way that markets in account currency
// come 1st. Otherwise the assignment of translation currencies
// can fail under certain conditions
reorder_markets_by_currency(symbols, nr_symbols, ticks_pips, contract_sizes, currencies, symboltypes);
printf("\n");
for(unsigned int i=0; i<nr_symbols; i++)
printf("\t%s", bdata(symbols[i]));
printf("\n");
// for each symbol get the position in the currency translation table
bstring *from_currency=NULL;
......@@ -298,14 +290,11 @@ int main (int argc, char **argv)
// create a matrix of translation currency "objects" which will later
// store the currency pair name and quote data
translation_currency *translation_currencies[nr_table_entr-1];
// populate translation_currencies vector with currency pairs (first step: symbols)
if(!assign_translation_currencies(symbols, currencies, nr_symbols, currency_table_position, from_currency, nr_table_entr, translation_currencies))
return 1; // if a translation currency for a symbol can not be found, abort
populate_translation_currencies(translation_currencies, nr_table_entr);
// for(unsigned int i=0; i<parms.SIGNAL_DAYS_TO_EXECUTE; i++)
// printf("\n%s\t%i\t%s\t%i\t%f", bdata(translation_currencies[0]->date[i]), translation_currencies[0]->daynr[i], bdata(translation_currencies[0]->symbol), translation_currencies[0]->reversed_flag, translation_currencies[0]->quotes[i]);
// execute signals
execution_manager(account, symbols,nr_symbols, today, ticks_pips, contract_sizes, currencies, symboltypes, currency_table_position, translation_currencies);
......
......@@ -749,7 +749,8 @@ float get_portfolio_riskfree_equity(accounts* the_account, int nr_entries, portf
float transl_quote = 1.0; // first pos in currency table is account currency
if(currency_table_position[current_position])
if(currency_table_position[symbolpos])
//if(currency_table_position[current_position])
{
transl_quote = get_translation_quote(today, translation_currencies[currency_table_position[symbolpos]]);
}
......
......@@ -22,15 +22,3 @@ ToDo/feature wishlist/brainstorm
already (see symbol.conf)
- looks like there is a bug with duplicated senkou cross signals: check Gold August 08/07, BuFu August 03/04
- left for money branch: alter statistics routine to use account currency, update account balance after each trade, add display of balance to -p/--portfolio output
- bug in currency translation: within assign_translation_currencies (line 335) with DAX:
(gdb) print translation_currencies[0]->symbol->data
$12 = (unsigned char *) 0xc58460 "EUREUR"
(gdb) print translation_currencies[1]->symbol->data
$13 = (unsigned char *) 0xc0b220 "USDEUR"
without DAX:
(gdb) print translation_currencies[0]->symbol->data
$14 = (unsigned char *) 0x940640 "EUREUR"
(gdb) print translation_currencies[1]->symbol->data
$15 = (unsigned char *) 0x682710 "EUREUR"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment