28 std::cout <<
"List<T> Clear()" << std::endl;
83 std::cout <<
"List<T> AddToList" << std::endl;
86 bool replace_last =
false;
87 std::vector<T> vec_new;
89 unsigned int first_to_skip = 0;
102 assert ( new_list !=
nullptr );
103 assert ( new_list->
GetSize() > 0 );
105 if ( ( !new_list ) || ( new_list->
GetSize() == 0 ) ) {
107 std::cout <<
"Pointer not valid or size is null" << std::endl;
116 std::cout <<
" GetFirstTime are equal, replace all data " << std::endl;
120 Replace ( new_list );
128 std::cout <<
"Last date of old == first date of new" << std::endl;
129 std::cout <<
"first to skip " << first_to_skip << std::endl;
133 replace_last = NoChronologicAt(0)
136 std::cout <<
"replace_last " << replace_last << std::endl;
139 if ( replace_last ) {
152 std::cout <<
"First dates, no overlap of dates, will append all data" << std::endl;
171 std::cout <<
"update only dates.last" << std::endl;
177 if ( new_list->
GetSize() - first_to_skip == 0 ) {
179 std::cout <<
" size_new_list_update == 0, nothing to do " << std::endl;
186 std::cout <<
"call AddChronoToList with first_to_skip " << first_to_skip << std::endl;
194 std::cout <<
"End ListDataStock::AddToList " << std::endl;
207 std::cout <<
"ListDataStock::Replace " << std::endl;
212 std::vector<T> new_vector;
216 ListData.insert( ListData.end(), new_vector.begin(), new_vector.end());
270 const unsigned int no )
const
273 std::cout <<
"Entry GetCArray" << std::endl;
274 std::cout <<
" b_order " << b_order << std::endl;
275 std::cout <<
" no " << no << std::endl;
276 std::cout <<
" size_listdata " << GetSize() << std::endl;
279 size_t size_data = GetSize();
284 std::cout <<
"After allocation memory " << std::endl;
289 for (
size_t i = 0; i < size_data; ++i ) {
297 for (
size_t i = 0; i < size_data; ++i ) {
312 std::initializer_list<unsigned int> list_no )
const
316 std::cout <<
"GetCArray2 with initializer_list" << std::endl;
317 std::cout <<
"b_order " << b_order << std::endl;
318 std::cout <<
"number in list " << list_no.size() << std::endl;
319 std::cout <<
"size_data " << GetSize() << std::endl;
322 std::vector<unsigned int> vec_indic;
324 unsigned int nb_indic = list_no.size();
330 for (
auto& value : list_no) {
331 vec_indic.push_back(value);
338 unsigned int count = 0;
340 for (
auto &nb_indic : vec_indic ) {
343 if (
float*** pf = boost::get<float***>(arraydata_c) )
344 this->GetCArray( &((*pf)[count]), b_order, nb_indic );
345 }
catch ( boost::bad_get &e ) {
347 std::cout <<
"Got exception for float, try float " << std::endl;
350 if (
double*** pd = boost::get<double***>(arraydata_c) )
351 this->GetCArray( &((*pd)[count]), b_order, nb_indic );
352 }
catch ( boost::bad_get &e ) {
353 std::cout <<
"Got exception for double, try int " << std::endl;
356 if (
int*** pi = boost::get<int***>(arraydata_c) )
357 this->GetCArray( &((*pi)[count]), b_order, nb_indic );
358 }
catch ( boost::bad_get &e ) {
359 std::cout <<
"Got exception for int, rethrow " << std::endl;
377 const unsigned int nb_data,
378 const unsigned size_indic,
380 const unsigned int offset_begin,
381 const unsigned int offset_end,
386 using namespace TimeScale;
389 std::cout <<
"In ListDataStock::PutCArray with offset_begin/offset_end " << std::endl;
390 std::cout <<
"nb_data " << nb_data << std::endl;
391 std::cout <<
"offset_begin " << offset_begin << std::endl;
392 std::cout <<
"offset_end " << offset_end << std::endl;
393 std::cout <<
"size_indic " << size_indic << std::endl;
394 std::cout <<
"bool chrono " << b_chrono << std::endl;
395 std::cout <<
"full_array " << full_array << std::endl;
406 assert ( nb_data == ldata_date.
GetSize() - offset_begin - offset_end );
410 std::cout <<
"Warning, TimeScale has been reset to " << ldata_date.
GetTimeScale() << std::endl;
415 T sdata( size_indic );
420 std::vector<type_value_data> vec_values;
423 unsigned int shift_data = 0;
429 shift_data = offset_begin;
431 shift_data = offset_end;
438 for (
unsigned int i= 0; i < nb_data; ++i ) {
441 for (
unsigned int j=0; j < size_indic; ++j ) {
443 vec_values.push_back( boost::apply_visitor(
visitor_type_array(j,i+shift_data), arraydata_c ) );
471 using namespace TimeScale;
473 std::cout <<
"\tname: " << GetName() <<
" size: " << GetSize() << \
474 " ,capacity: " << Capacity() << policy() << std::endl;
475 std::cout <<
"\ttimescale: " <<
GetTimeScale() << std::endl;
476 std::cout <<
"\tfullname: " << GetFullName() << std::endl;
480 if ( ListData.size() == 0 ) {
481 std::cout <<
"\tList is empty" << std::endl;
485 if ( verbose == 0 ) {
486 std::cout <<
"\t First: " << std::endl;
487 this->ChronologicAt(0).PrintData( 1 );
490 std::cout <<
"\t Last: " << std::endl;
491 this->ChronologicAt( ListData.size()-1 ).PrintData( 1 );
495 if ( verbose == 1 ) {
496 std::cout <<
"Will call ListDataStock::PrintData(0), no header in loop " << std::endl;
497 for (
unsigned int i =0; i < ListData.size(); ++i ) {
498 this->ChronologicAt( i ).PrintData( 0 );
507 namespace ListDataStock_Utils {
530 template <
class>
class Policy1,
531 template <
class>
class Policy2,
532 template <
class>
class Policy3,
533 template <
class>
class Policy4
540 using namespace TimeScale;
543 std::cout <<
"\tTransformTimeScale, input DataCSV\n" << std::endl;
546 unsigned int size_input_csv= list_csv_in.
GetSize();
560 std::cout <<
"Error, TimeScale of the input are different, return 1 " << std::endl;
571 std::cout <<
"Warning, Transform TimeScale from WEEK leads to different results " << std::endl;
574 std::cout <<
"Error, new tmscl must be >= ETime::M5, your input: " << new_tmscl << std::endl;
579 std::cout <<
"Error, Input lists must have the same size " << std::endl;
584 if ( list_csv_out.
GetName() != shortname_csv ) {
586 if ( ! list_csv_out.
GetName().empty() )
587 std::cout <<
"Warning Set correct name for list_csv_out " << shortname_csv << std::endl;
588 list_csv_out.
SetName( shortname_csv );
597 std::cout <<
"Warning Set correct TimeScale to list_csv_out " << new_tmscl << std::endl;
602 if ( list_vol_out.
GetName() != shortname_vol ) {
604 if ( ! list_vol_out.
GetName().empty() )
605 std::cout <<
"Warning Set correct name for list_vol_out " << shortname_vol << std::endl;
606 list_vol_out.
SetName( shortname_vol );
612 std::cout <<
"Warning Set correct TimeScale to list_csv_out " << new_tmscl << std::endl;
619 bool change_candle=
false;
625 int prev_value[3]={-1,-1,-1};
627 int previous_value = -1;
638 list_csv_out.
Reserve(size_input_csv);
639 list_vol_out.
Reserve(size_input_csv);
652 time_tm = new_candle.GetDateTm();
655 prev_value[1] = time_tm.tm_hour;
658 prev_value[2] = time_tm.tm_min;
660 prev_value[0] = time_tm.tm_mday;
662 switch ( new_tmscl ) {
664 case ETime::M10 : prev_value[2] = time_tm.tm_min /10;
break;
665 case ETime::M30 : prev_value[2] = time_tm.tm_min /30;
break;
668 case ETime::H1 : prev_value[1] = time_tm.tm_hour;
break;
671 strftime ( tmp_str,3,
"%W", &time_tm);
672 previous_value=atoi(tmp_str);
break;
674 case ETime::MONTH : previous_value = time_tm.tm_mon;
break;
675 case ETime::TRIM : previous_value = (int)(time_tm.tm_mon/3);
break;
676 case ETime::YEAR : previous_value = time_tm.tm_year;
break;
677 default: std::cout <<
"Error switch new_tmscl, return 1" << std::endl;
return 1;
687 for (
unsigned int i=1; i< size_input_csv; i++) {
709 switch ( new_tmscl ) {
713 if ( ( time_tm.tm_min/10) != prev_value[2] ) {
716 prev_value[2] = time_tm.tm_min / 10;
723 if ( ( time_tm.tm_min/30) != prev_value[2] ) {
726 prev_value[2] = time_tm.tm_min / 30 ;
732 if ( time_tm.tm_hour != prev_value[1]) {
734 prev_value[1] = time_tm.tm_hour;
749 strftime ( tmp_str,3,
"%W", &time_tm);
750 if ( atoi(tmp_str) != previous_value ) {
752 previous_value=atoi(tmp_str);
756 if ( time_tm.tm_mon != previous_value ) {
758 previous_value = time_tm.tm_mon;
762 if ( (
int)(time_tm.tm_mon/3) != previous_value ) {
764 previous_value = (int)(time_tm.tm_mon/3);
768 if ( time_tm.tm_year != previous_value ) {
769 change_candle =
true;
770 previous_value = time_tm.tm_year;
775 std::cout <<
"Error in TimeScale Default Switch in TransformTimeScale " << std::endl;
779 if ( change_candle ) {
782 change_candle =
false;
790 new_vol.SetData ( new_candle.GetDate(), tmp_volume );
792 list_csv_out.
AddData( new_candle );
793 list_vol_out.
AddData( new_vol );
812 new_vol.SetData( new_candle.GetDate(), tmp_volume);
814 list_csv_out.
AddData( new_candle );
815 list_vol_out.
AddData( new_vol );
840 template <
class>
class Policy1,
841 template <
class>
class Policy2,
842 template <
class>
class Policy3,
843 template <
class>
class Policy4
849 using namespace TimeScale;
851 unsigned int size_input_csv = list_dcsv_in.
GetSize();
854 std::cout <<
"\n\tTransformTimeScale with input SimpleData\n" << std::endl;
855 std::cout <<
"Size ListData input " << size_input_csv << std::endl;
868 std::cout <<
"Error, Input must be a ETime::INST" << std::endl;
873 std::cout <<
"Error, new tmscl must be < ETime::DAY, your input: " << new_tmscl << std::endl;
878 std::cout <<
"Error, Input lists must have the same size " << std::endl;
883 if ( list_csv_out.
GetName() != shortname_csv ) {
885 if ( ! list_csv_out.
GetName().empty() )
886 std::cout <<
"Warning Set correct name for list_csv_out " << shortname_csv << std::endl;
887 list_csv_out.
SetName( shortname_csv );
893 std::cout <<
"Warning Set correct TimeScale to list_csv_out " << new_tmscl << std::endl;
898 if ( list_vol_out.
GetName() != shortname_vol ) {
900 if ( ! list_vol_out.
GetName().empty() )
901 std::cout <<
"Warning Set correct name for list_vol_out " << shortname_vol << std::endl;
902 list_vol_out.
SetName( shortname_vol );
908 std::cout <<
"Warning Set correct TimeScale to list_csv_out " << new_tmscl << std::endl;
915 list_csv_out.
Reserve(size_input_csv);
916 list_vol_out.
Reserve(size_input_csv);
918 bool change_candle=
false;
924 int prev_value[3]={-1,-1,-1};
944 time_tm = new_candle.GetDateTm();
946 prev_value[0] = time_tm.tm_hour;
949 prev_value[1] = time_tm.tm_min;
950 switch ( new_tmscl ) {
951 case ETime::M5 : prev_value[1] = time_tm.tm_min /5;
break;
952 case ETime::M10 : prev_value[1] = time_tm.tm_min /10;
break;
953 case ETime::M30 : prev_value[1] = time_tm.tm_min /30;
break;
958 prev_value[2] = time_tm.tm_mday;
966 for (
unsigned int i = 1 ; i < size_input_csv ; ++i ) {
972 minute = time_tm.tm_min;
981 if ( (minute/5) != prev_value[1] ) {
984 prev_value[1] = minute/5 ;
989 if ( (minute/10) != prev_value[1] ) {
991 prev_value[1]= minute/10;
997 if ( (minute/30) != prev_value[1] ) {
999 prev_value[1]= minute/30;
1004 if ( time_tm.tm_hour != prev_value[0]) {
1006 prev_value[0] = time_tm.tm_hour;
1012 std::cout <<
"Error in switch timescale, return 1" << std::endl;
1019 if ( time_tm.tm_mday != prev_value[2]) {
1022 prev_value[2] = time_tm.tm_mday;
1025 if ( change_candle ) {
1027 change_candle =
false;
1038 list_csv_out.
AddData( new_candle);
1039 list_vol_out.
AddData( new_vol);
1059 new_vol.SetData ( new_candle.GetDate(),
1063 list_csv_out.
AddData( new_candle );
1064 list_vol_out.
AddData( new_vol );
1080 std::cout <<
"TestSize out_csv " << list_csv_out.
GetSize() << std::endl;
1081 std::cout <<
"TestSize out_vol " << list_vol_out.
GetSize() << std::endl;
void Replace(const ListDataStockBase *ldata_in)
Replace all DataStock's of the list with ldata_in.data, without checking for update.
void SetName(const std::string iname)
type_value_data GetValue() const
Get the unique value.
void AddData(DataStock &data)
Add a copy of the DataStock into the ListDataStock.
void PrintData(const unsigned int verbose=0) const
Nice formatting output on console.
unsigned int GetSize() const
Return the size of the vector.
virtual time_t LastUpdate() const =0
Get the date of the last data (always chronological meaning)
double type_value_data
Type of the floating values to be stored, can be set to float or double before compilation.
boost::variant< float **, double **, int ** > var_types
time_t GetFirstDate() const
Get first date from the private data member dates.
const T & NoChronologicAt(const unsigned int offset) const
Get nth element in a non chronological order.
Use a policy PolicyChronologic, default VecNoChronologic.
EPChrono
Define convenient name for the chronology, makes algorithms clearer.
virtual void GetVectorData(std::vector< DataCSV > &, const EPChrono) const
time_t GetLastDate() const
Get last date from the private data member dates.
Data type to describe Japanese candlesticks : open, high, low and close values.
virtual time_t GetFirstTime() const =0
Get the date of the first data (always chronological meaning)
void Reserve(const unsigned int new_size)
Reserve new_size elements.
boost::variant< float ***, double ***, int *** > var_types2
static Indicator const Volume
ETime
Enumeration for the different time representation, from instantaneous (INST) to year(YEAR) ...
virtual void AdditionData(const DataCSV &new_data)
With an other candlestick.
void Order(const EPChrono b_chronologic=EPChrono::CHRONO)
Function to reverse the internal vector in its original policy.
virtual const DataStock & ChronologicAt(const unsigned int offset) const =0
Get the nth element in a chronological order.
std::string Time_tToString(const time_t &time, const bool b_hour)
Return a string representing the date All times are expressed in the localtime.
virtual void SetTimeScale(const ETime new_tmscl)
void Swap()
Reduce the capacity of the internal vector to fit its size.
void SetDates()
Set the correct first/last dates from the DataStock in the vector.
type_value_data GetOpen() const
struct tm GetDateTm() const
Get a tm structure of the date.
Derive class which contains only one value of type type_value_data (float or double).
virtual unsigned int GetSize() const =0
Return the size of the vector.
static Indicator const StockCSV
void Clear()
Clear the vector and reinitialize data members to default values.
std::string GetName() const
Abstract base class for the ListDataStock, for storing base pointers in vectors.
time_t GetDate() const
Get the date data member.
virtual const DataStock & NoChronologicAt(const unsigned int offset) const =0
Get nth element in a non chronological order.
static SUPPRESS_NOT_USED_WARN firstlast_dates get_fldate_default()
need to be static for using default argument in a function
std::string MakeShortName(const Indicator &indic, const std::vector< int > ¶m)
Create a short name from its components.
virtual ETime GetTimeScale() const
int AddToList(const ListDataStockBase *new_list)
Append all data from a new list ( coming from an Update or ReadCSV normally ) to an existing list...
unsigned int GetCArray(var_types arraydata_c, const EPChrono b_order, const unsigned int no=0) const
Extract the data into a one dimensional C-array.
ETime GetTimeScale(const std::string &fname)
Extract the TimeScale from a fullname.
int PutCArray(const ListDataStockBase &ldata_date, const unsigned int nb_data, const unsigned size_indic, var_types arraydata_c, const unsigned int offset_begin, const unsigned int offset_end=0, const EPChrono b_chrono=EPChrono::CHRONO, bool full_array=false)
Fill a ListDataStock<T> from a 2 dimensional C-array.
int TransformTimeScale(const ETime new_tmscl, const ListDataStock< DataCSV, Policy1 > &list_csv_in, const ListDataStock< SimpleData, Policy2 > &list_vol_in, ListDataStock< DataCSV, Policy3 > &list_csv_out, ListDataStock< SimpleData, Policy4 > &list_vol_out)
Transform StockCSV and Volume from M5 into a StockCSV with larger TimeScale, typical DAY to WEEK...