29 Stock::Stock(
const std::string iname,
const std::string isymbol,
const std::string ipath):
30 name(iname), symbol(isymbol),
path(ipath) {
32 std::cout <<
" Constructor Stock, depreaceated version with symbol " << std::endl;
40 name(iname),
path(ipath) {
49 std::cout <<
"Default destructor stock" << std::endl;
53 for(
it_listdata it_l = it_m->second.begin(); it_l != it_m->second.end(); ++it_l) {
78 return GetItList( it_m, full_indic_label );
85 for( it_l = (*it_m).second.begin(); it_l != (*it_m).second.end(); it_l ++) {
86 if ( (*it_l)->GetName() == sname ) {
90 return (*it_m).second.end();
98 return GetItList( it_m, full_indic_label );
104 for(
it_listdata it_l = (*it_m).second.begin(); it_l != (*it_m).second.end(); it_l ++) {
105 if ( (*it_l)->GetName() == sname ) {
109 return (*it_m).second.end();
118 std::vector<std::string> line_split;
125 if ( line_split.size() == 4 ) {
129 }
else if ( line_split.size() == 6 ) {
136 std::cout <<
"ERROR Stock::ReadLineHeader in reading dates, return 1 " << std::endl;
143 std::cout <<
"ERROR Stock::ReadLineHeader from Utils::StringToTime_t, return 1" << std::endl;
180 std::cout <<
"Stock::LoadCSVData argument tmscl: " << tmscl << std::endl;
189 std::cout <<
"Indicator::StockInst and Volume for timescale " << tmscl <<
" is already loaded" << std::endl;
197 std::cout <<
"Indicator::StockCSV and Volume for timescale " << tmscl <<
" is already loaded" << std::endl;
207 std::cout <<
" ReadCSV timescale " << tmscl << std::endl;
212 ReadCSV( tmscl, dates );
215 std::cout <<
"LoadListData catch FileError exception" << std::endl;
216 std::cout <<
"what() " << e.
what() << std::endl;
217 std::cout <<
"Will Create a StockFileError " << std::endl;
241 std::cout <<
"At least one missing, force to read the file " << std::endl;
247 std::cout <<
"before transform_timescale " << std::endl;
248 if ( Transform_TimeScale(tmscl) != 0 ) {
250 std::cout <<
"TransformTimeScale problem throw exception " << std::endl;
251 throw (
StockException( name,
"Error in Transform_TimeScale tmscl") );
263 std::cout <<
"Entry Stock::SetLDataFullName " << std::endl;
264 std::cout <<
" tmp_string " << tmp_string << std::endl;
276 std::cout <<
"\n\tEntry Transform_TimeScale " << new_tmscl << std::endl;
292 std::cout <<
" new_tmscl > DAY " << new_tmscl << std::endl;
297 if ( in_vol ==
nullptr ) {
298 std::cout <<
"ERROR in Stock::Transform_TimeScale in dynamic_cast volume " << std::endl;
303 if ( in_csv ==
nullptr ) {
304 std::cout <<
"ERROR in Stock::Transform_TimeScale in dynamic_cast candle" << std::endl;
314 std::cout <<
" new_tmscl < DAY " << new_tmscl << std::endl;
318 if ( in_vol ==
nullptr ) {
319 std::cout <<
"ERROR in Stock::Transform_TimeScale in dynamic_cast volume " << std::endl;
323 if ( in_dcsv ==
nullptr ) {
324 std::cout <<
"ERROR in Stock::Transform_TimeScale in dynamic_cast candle " << std::endl;
333 std::cout <<
"return 1 (update) from AddListData, so delete temporary list" << std::endl;
340 std::cout <<
"return 1 (update) from AddListData, so delete temporary " << std::endl;
355 std::cout <<
"\n\tEntry Stock::ComputeTA, name_new_indic: " << name_new_indic << std::endl;
362 std::vector<int> vec_param;
364 new_indic.
Set(name_new_indic,vec_param);
374 std::cout <<
"\n\t Stock::ComputeTA" << std::endl;
375 std::cout <<
"Error, indicator is null" << std::endl;
376 std::cout <<
"label indicator after extract "<< new_indic.
label() << std::endl;
378 std::string msg =
"TALibException: Error, indicator is null or nb_output <= 0, label received = "+
Utils::toString(name_new_indic);
383 if ( new_indic.
nb_param() != (int)vec_param.size() ) {
385 std::cout <<
"\n\t Stock::ComputeTA" << std::endl;
386 std::cout <<
"Error required number of parameters "<< new_indic.
nb_param() << std::endl;
394 std::cout << new_indic.
label() <<
" will give " << new_indic.
nb_output() <<
" output " << std::endl;
410 std::cout <<
"case : nb_output 1 " << std::endl;
412 ldata_base_out =
new ldata_ta_sd( name_new_indic, tmscl );
418 ldata_base_out =
new ldata_ta_md( name_new_indic, tmscl );
423 std::vector< ListDataStockBase *> vec_ldata_in;
434 std::cout <<
" case of AD need the volume in vec_ldata_in " << std::endl;
440 std::cout <<
"ldata_in[0] Name " << vec_ldata_in[0]->GetName() << std::endl;
441 std::cout <<
"ldata_in[0] Size " << vec_ldata_in[0]->GetSize() << std::endl;
450 if ( p_talib ==
nullptr ) {
452 std::cout <<
"p_talib is null, must initialize the library " << std::endl;
458 std::cout <<
"p_talib is not null, library already initialized " << std::endl;
464 retour = p_talib->Compute( tmscl, new_indic, vec_param, vec_ldata_in, ldata_base_out);
466 std::cout <<
"TAlibAPI::Compute retour " << retour << std::endl;
470 std::cout <<
"Catch Stock::ComputeTA TALibException " << std::endl;
471 std::cout <<
"what() of TALib " << e.
what() << std::endl;
475 delete ldata_base_out; ldata_base_out =
nullptr;
482 new_size = ldata_base_out->GetSize();
483 std::cout <<
" size new data " << new_size << std::endl;
503 ldata_base_out->SetDates();
507 if ( AddListDataToMap ( tmscl, ldata_base_out ) == 1 ) {
509 std::cout <<
" update will delete original list " << std::endl;
511 delete ( ldata_base_out );
512 ldata_base_out =
nullptr;
517 std::cout <<
"\n\t retour of TAlib::Compute !=0 Error\n" << std::endl;
518 delete ( ldata_base_out );
523 std::cout <<
"\n\treturn from Stock::ComputeTA no error\n" << std::endl;
547 if ( it_l == (*it_m).second.end() ) {
561 if ( it_l == (*it_m).second.end() ) {
571 std::cout <<
" The map of Stock " <<
name <<
" Is empty " << std::endl;
590 if ( it_l == (*it_m).second.end() ) {
604 if ( it_l == (*it_m).second.end() ) {
625 std::string sname = p_listdata->
GetName();
626 unsigned int new_ldata_size = p_listdata->
GetSize();
631 std::cout <<
"\n\t Stock::AddListDataToMap " << tmscl ;
632 std::cout <<
" new list p_listdata->name " << p_listdata->
GetName() ;
633 std::cout <<
" new list p_listdata->size " << p_listdata->
GetSize() << std::endl;
638 if ( new_ldata_size == 0 ) {
639 std::cout <<
"Stock::AddListDataToMap p_listdata size = 0 , return 2, SHOULD NOT APPEAR !!" << std::endl;
640 assert ( new_ldata_size !=0 );
650 std::cout <<
"In Map, ETime " << tmscl <<
" does not exist, create " << std::endl;
652 std::vector < ListDataStockBase* > vec;
663 std::cout <<
"Check old data with same name " << sname << std::endl;
669 std::cout <<
" Will Update existing ListDataStock " << std::endl;
670 std::cout <<
" name listdata old " << ldata_old->
GetName() << std::endl;
681 std::cout <<
"Update Stock or Volume, call AddToList " << std::endl;
692 std::cout <<
"Will replace indicator (SMA,MACD...) " << std::endl;
700 ldata_old->
Replace( p_listdata );
704 std::cout <<
"ldata_old exists, an update has been done, return 1" << std::endl;
713 std::cout <<
"ListData does not exist, insert " << std::endl;
714 std::cout <<
"Check if fullname exist to set fullname :" << p_listdata->
GetFullName() << std::endl;
723 (*it_m).second.push_back(p_listdata);
733 std::cout <<
"Entry MergeStock " << std::endl;
734 std::cout <<
"this " <<
this << std::endl;
735 std::cout <<
"new_stock " << new_stock << std::endl;
739 const Stock & rnew_stock = (*new_stock);
742 if (
this == new_stock ) {
744 std::cout <<
"Same pointer ! already updated ? just return...\n" << std::endl;
750 std::cout <<
"Different pointer ! Make a copy... " << std::endl;
760 ETime tmscl = (*it_map_new).first;
761 std::cout <<
"ETime " << (*it_map_new).first << std::endl;
764 for ( it_list_new = (*it_map_new).second.cbegin();
765 it_list_new != (*it_map_new).second.cend();
768 std::cout <<
"fullname list " << (*it_list_new)->GetFullName() << std::endl;
769 std::cout <<
"name list " << (*it_list_new)->
GetName() << std::endl;
777 std::cout <<
"status 0: insertion " << std::endl;
778 }
else if (status == 1) {
779 std::cout <<
"status 1: update " << std::endl;
808 std::cout <<
"\n\tEntry Stock::LoadListData ";
809 std::cout <<
"timescale " << tmscl << std::endl;
810 std::cout <<
" indic " << indic.label() << std::endl;
811 std::for_each(param.cbegin(),param.cend(),
812 [](
int value){std::cout << value <<
" ";} );
813 std::cout <<
"first time " << dates.first <<
" " <<
Utils::Time_tToString( dates.first,
true ) << std::endl;
814 std::cout <<
"last time " << dates.last <<
" " <<
Utils::Time_tToString ( dates.last,
true ) << std::endl;
815 std::cout <<
"ShortName " << sname << std::endl;
820 throw StockException(
"StockException: LoadListData with indicator Null");
825 if ( CheckLoaded( tmscl, sname ) ) {
827 std::cout <<
"Indicator " << sname <<
" Already in Map" << std::endl;
838 LoadCSVData( tmscl, dates );
841 if ( indic.NeedToComputeTA() ) {
844 std::cout <<
"LoadListData call ComputeTA " << std::endl;
850 ComputeTA( tmscl, sname );
854 std::cout <<
"Stock::LoadListData catch TALibException " << std::endl;
855 std::cout <<
"what() " << e.
what() << std::endl;
863 std::cout <<
"Exit Stock::LoadListDataStock without problem " << std::endl;
875 std::cout <<
"Stock::DeleteListData with indic" << indic.
label() <<
" tmscl " << tmscl << std::endl;
888 std::cout <<
"Stock::DeleteListData " << sname <<
" tmscl " << tmscl << std::endl;
898 if ( it_l != (*it_m).second.end() ) {
907 std::cout <<
" size of map with key " << tmscl <<
" is empty, delete it " << std::endl;
919 std::cout <<
" Entry DeleteAllListData " << tmscl << std::endl;
930 for (
it_listdata it_l = ((*it_m).second.begin()); it_l != (*it_m).second.end(); it_l++ ) {
932 std::cout << (*it_l)->GetName() << std::endl;
943 std::cout <<
"Stock::End DeleteAllListData " << std::endl;
961 std::cout <<
"\n\tEntry ReadCSV ,timescale " << tmscl << std::endl;
962 std::cout <<
" opt dates first " << dates.first <<
" " <<
Utils::Time_tToString( dates.first,
true ) << std::endl;
963 std::cout <<
" opt dates last " << dates.last <<
" " <<
Utils::Time_tToString( dates.last ) << std::endl;
964 std::cout <<
" path data: " <<
path << std::endl;
968 std::vector<std::string> line_split;
977 std::string filename;
994 std::cout <<
"read filename " << filename << std::endl;
998 file.open ( filename.c_str(), std::ios_base::in );
1000 if ( file.fail() ) {
1002 std::cout <<
"Stock::ReadCVS Opening failed, will throw exception StockFileError with a FileOpenError " << std::endl;
1008 std::getline( file, line );
1010 if ( file.fail() ) {
1012 std::cout <<
"Get first line failed, throw exception " << std::endl;
1020 if ( ReadLineHeader( line, dates_file ) ) {
1022 std::cout <<
"Error return from ReadLineHeader " << std::endl;
1031 if ( dates.first == 0 )
1032 dates.first = dates_file.
first;
1033 if ( dates.last == 0 )
1034 dates.last = dates_file.
last;
1044 std::getline( file, line );
1057 if ( ( time_tmp >= dates.first ) && ( time_tmp <= dates.last ) )
1062 std::cout <<
" count " << count <<
" lines " << std::endl;
1068 std::cout <<
"will throw a StockFileError, dates are wrong " << std::endl;
1071 std::string msg =
"Dates provided give no data \ndates used: " +
1079 file.seekg(0, std::ios::beg);
1090 plist_data =
new ldata_dcsv(
"StockInst", tmscl, count);
1096 plist_data =
new ldata_candle(
"StockCSV", tmscl, count);
1100 plist_volume =
new ldata_volume(
"Volume", tmscl, count);
1103 getline (file,line);
1108 while ( std::getline(file,line) ) {
1134 if ( ( time_tmp >= dates.first ) && ( time_tmp <= dates.last ) ) {
1139 tmp_vol = Utils::fromString<type_value_data>( line_split[line_split.size()-1] );
1143 data_volume.
SetData( data->GetDate(), tmp_vol );
1145 plist_volume->
AddData( data_volume );
1150 if ( ( tmscl ==
ETime::DAY ) && ( time_tmp < dates.first ) ) {
1154 std::cout <<
" \nNo need to read others if DAY, can stop !\n " << std::endl;
1163 delete ( data ); data =
nullptr;
1165 new_size = plist_volume->
GetSize();
1168 std::cout <<
" size new list volume " << plist_volume->
GetSize() <<
" " << new_size << std::endl;
1169 std::cout <<
" should be equal to count " << count << std::endl;
1173 assert ( new_size==count );
1203 if ( AddListDataToMap( tmscl, plist_data ) == 1 ) {
1205 std::cout <<
"AddListDataToMap list_data==1 delete plist_data " << std::endl;
1207 delete ( plist_data ); plist_data=0;
1210 if ( AddListDataToMap ( tmscl,plist_volume ) == 1 ) {
1212 std::cout <<
"AddListDataToMap list_volume==1 delete plist_data " << std::endl;
1214 delete ( plist_volume ); plist_volume=0;
1219 std::cout <<
"ReadCSV new_size==0, Not call AddListDataToMap and return 0" << std::endl;
1220 std::cout <<
"and need to delete listdata" << std::endl;
1222 delete ( plist_data ); plist_data=0;
1223 delete ( plist_volume ); plist_volume=0;
1230 std::cout <<
"End ReadCSV, return new_size " << new_size << std::endl;
1250 std::cout <<
"\tWriteCSV" << std::endl;
1251 std::cout <<
"opt_tmp " << opt_tmp << std::endl;
1256 std::string filename;
1258 std::stringstream ss (std::stringstream::in | std::stringstream::out);
1261 std::ostringstream ss_header;
1266 if ( opt_tmp ==
false )
1273 std::cout <<
"write csv filename :" << filename << std::endl;
1298 if ( (!csv) or (!vol) ) {
1299 std::cout <<
"Error casting in write CSV csv !" << std::endl;
1300 throw StockException( name,
"Error in getting the indicators pointers !!!");
1304 file.open ( filename.c_str(), std::ios_base::out );
1306 if ( file.fail() ) {
1308 std::cout <<
"Stock::WriteCVS Opening failed, will throw exception StockFileError with a FileOpenError " << std::endl;
1312 std::cout <<
"Stock::WriteCSV file opened, " << filename.c_str() << std::endl;
1315 WriteLineHeader( tmscl, csv->
GetDates(), ss_header );
1317 file << ss_header.str() << std::endl;
1321 for (
unsigned int i = 0; i < csv->
GetSize(); ++i ) {
1338 file << ss.str() << std::endl;
1339 if ( file.fail() ) {
1340 std::cout <<
"\n Failed in writing, big error, disk space ??" << std::endl;
1346 std::cout <<
"End Stock::WriteCSV" << std::endl;
1360 std::cout <<
"\n Stock::SaveCSV tmscl " << tmscl << std::endl;
1361 std::cout <<
"opt_tmp " << opt_tmp << std::endl;
1384 if ( lb ==
nullptr ) {
1385 std::cout <<
"List is not loaded in memory, nothing to do, return -1" << std::endl;
1401 std::cout <<
"Header is Up to date, return -1" << std::endl;
1415 std::cout <<
"Ok dates first== && last >, after an update can write and return" << std::endl;
1426 std::cout <<
"First dates are missing, need a tmp_stock trick ! " << std::endl;
1429 int status_ll, status_al;
1443 std::cout <<
"Error in loading data in tmp_stock, return -1" << std::endl;
1458 assert (status_al == 1);
1466 assert (status_al == 1);
1470 tmp_stock->
WriteCSV( tmscl, opt_tmp );
1473 delete tmp_stock; tmp_stock =
nullptr;
1491 std::cout <<
"Read_HeaderCSV version with timescale " << std::endl;
1493 std::string filename;
1499 std::cout <<
"read filename " << filename << std::endl;
1503 std::ifstream file( filename.c_str() );
1504 if ( file.fail() ) {
1506 std::cout <<
"Opening failed, will create and throw a StockFileError " << std::endl;
1511 std::getline( file, line );
1513 ReadLineHeader( line, dates );
1523 std::cout <<
"Read_HeaderCSV_static " << std::endl;
1525 std::string filename;
1531 std::cout <<
"read filename " << filename << std::endl;
1535 std::ifstream file( filename.c_str() );
1536 if ( file.fail() ) {
1538 std::cout <<
"Opening failed, will create and throw a StockFileError " << std::endl;
1543 std::getline( file, line );
1547 ReadLineHeader( line, dates );
1562 std::string filename;
1567 bool new_file =
false;
1569 std::stringstream ss (std::stringstream::in | std::stringstream::out);
1571 std::ostringstream ss_header;
1577 if ( opt_tmp ==
false )
1584 std::cout <<
"update csv INST filename :" << filename << std::endl;
1588 file.open ( filename.c_str() );
1589 if ( !file.is_open() ) {
1591 file.open ( filename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc );
1592 assert ( file.good() == true );
1597 dates_data.
first = inst_value.GetDate();
1598 dates_data.
last = inst_value.GetDate();
1603 WriteLineHeader( tmscl, dates_data, ss_header );
1605 file << ss_header.str() << std::endl;
1607 ss << inst_value << inst_volume << std::endl;
1613 std::getline( file, line );
1615 if ( file.fail() ) {
1617 std::cout <<
"Get first line failed, throw exception " << std::endl;
1623 if ( ReadLineHeader( line, dates_header ) ) {
1625 std::cout <<
"Error return from ReadLineHeader " << std::endl;
1635 if ( dates_header.
last > dates_data.
last ) {
1636 std::cout <<
"Error Stock::UpdateCSV_Inst dates are wrong " << std::endl;
1640 if ( dates_header.
last == dates_data.
last ) {
1641 std::cout <<
"Warning Stock::UpdateCSV_Inst dates last identical with present in header!!!" << std::endl;
1646 file.seekg(0, std::ios::beg);
1647 WriteLineHeader( tmscl, dates_data, ss_header );
1648 file << ss_header.str();
1650 file.seekg(0, std::ios::end);
1652 ss << inst_value << inst_volume << std::endl;
1802 std::cout <<
"Entry Stock::Updated tmscl " << tmscl << std::endl;
1803 std::cout <<
"(TimeScale) dcsv: " <<
ETime::INST << std::endl;
1804 std::cout <<
"(TimeScale) M5: " <<
ETime::M5 << std::endl;
1809 ETime tmscl_to_update;
1816 std::cout <<
"Need to update all indic between INST and H1" << std::endl;
1823 tmscl_to_update =
static_cast<ETime>( i );
1824 std::cout <<
"tmscl_to_update " <<
as_uint(tmscl_to_update) << std::endl;
1838 std::cout <<
"\n Need to update all indic between DAY and year not implemented yet \n" << std::endl;
1895 std::cout <<
"\n\t Entry Stock::UpdateAllTimeScale: " << tmscl << std::endl;
1896 std::cout <<
"opt_dates first/last " << opt_dates.
last << std::endl;
1912 unsigned int new_added_size = 0;
1914 bool recompute =
true;
1917 std::string name_indic;
1919 std::vector< std::string > vec_indic;
1923 if ( opt_dates.
last == 0 ) {
1924 opt_dates.
last = time ( NULL );
1926 std::cout <<
"opt_date set up to now by call to time(NULL) " << std::endl;
1932 for (
it_listdata it_l = it_m->second.begin(); it_l != it_m->second.end() ; it_l++ ) {
1933 std::cout <<
" name listdata " << (*it_l)->GetName() << std::endl;
1934 name_indic = (*it_l)->GetName();
1937 if ( ( name_indic ==
"StockCSV" ) || ( name_indic ==
"StockInst") ) {
1947 std::cout <<
"b_readfile is true " << std::endl;
1952 std::cout <<
" UpdateCSV, Yahoo, data and volume " << std::endl;
1961 std::cout <<
"Caught an exception " << std::endl;
1970 std::cout <<
" Update INST, (Bourso to do?) Read from file *dcsv " << std::endl;
1981 if ( new_added_size == 0 ) {
1983 std::cout <<
"\n\t UpdateAllTimeScale returned new_added_size == 0" << new_added_size << std::endl;
1996 std::cout <<
"Will call Transform_TimeScale tmscl= " << tmscl << std::endl;
2001 if ( status_tt != 0 ) {
2002 std::cout <<
"\nERROR in Stock::UpdateAllTimeScale in TransformTimeScale !!\n" << std::endl;
2008 else if ( name_indic ==
"Volume")
2016 std::cout <<
"Add " << name_indic <<
" to the list of indicator to recompute " << std::endl;
2018 vec_indic.push_back( name_indic );
2026 std::cout <<
"test to recompute other indicators, recompute: " << recompute << std::endl;
2034 for (
unsigned int i=0; i< vec_indic.size(); i++ ) {
2036 std::string name_ind;
2038 std::vector< int > vec_param;
2043 new_indic.
Set( vec_indic[i], vec_param );
2049 std::cout <<
"ComputeTA to test for exception" << std::endl;
2070 unsigned int new_size;
2075 time_t last_in_memory = 0;
2078 std::cout <<
"\n\t Entry Stock::UpdateCSVFromFile tmscl " << tmscl << std::endl;
2103 if ( last_in_memory > dates_header.
last )
2107 new_size =
ReadCSV( tmscl, dates_to_load );
2110 std::cout <<
"UpdateCSVFromFile ReadCSV return new_size " << new_size << std::endl;
2129 std::cout <<
"===================\n\t ShowMap Stock Chrono " <<
GetName() << std::endl;
2134 std::cout <<
"timescale: " << it_m->first << std::endl;
2135 if ( (it_m->second).empty() ) {
2136 std::cout <<
" list data defined and empty" << std::endl;
2138 else if ( (it_m->second).size() > 0 ) {
2140 std::cout <<
" list data defined, " << (it_m->second).size() <<
" pointeur on List " << std::endl;
2141 for(
cit_listdata it_l= it_m->second.begin(); it_l !=it_m->second.end(); it_l++) {
2143 std::cout <<
"\t========================" << std::endl;
2144 (*it_l)->PrintData( verbose );
2151 std::cout <<
"\n" << std::endl;
ListDataStock< DataCSV, VecChronologic > ldata_candle
Define a default policy for candlestick.
Define the class Stock to deal with an unique stock: DJ, IBM...
int SaveCSV(const ETime tmscl, bool opt_tmp=false) const
Save Historical data to file.
Define a list of DataStock objects.
Specific, inherit from FileError from utils.
virtual void AddData(DataStock &)=0
Add a copy of the DataStock into the ListDataStock.
"Clever" enumeration of the ListDataStock type : StockCSV, Volume, EMA, BOLL,...
int nb_param() const
Nb of parameters necessary to be computed.
void Set(std::string str_name, std::vector< int > ¶m)
int UpdateCSVFromFile(const ETime tmscl)
Load the last historical data from the filesystem into a List in memory.
static Indicator const Null
Predefined static instances of the class.
int UpdateCSVFromWeb(const std::string &source, Utils::firstlast_dates opt_dates=Utils::get_fldate_default())
Update data from the Python parser (and save into the filesystem).
void SetLDataFullName(ListDataStockBase *p_listdata) const
Function to complete the fullname of a listdatastock.
virtual time_t LastUpdate() const =0
Get the date of the last data (always chronological meaning)
virtual int AddToList(const ListDataStockBase *)=0
Append all data from a new list ( coming from an Update or ReadCSV normally ) to an existing list...
ListDataStock< SimpleData, VecChronologic > ldata_volume
Volume has also one value.
double type_value_data
Type of the floating values to be stored, can be set to float or double before compilation.
Base class for error handling with files.
std::map< ETime, std::vector< ListDataStockBase * > >::iterator it_map
static int ReadLineHeader(const std::string &line, Utils::firstlast_dates &dates)
Extract dates from the header of the historic data files.
ListDataStock< SimpleData, VecChronologic > ldata_dcsv
dcsv is for instantateneous values, only one value
std::vector< ListDataStockBase * >::iterator it_listdata
const T & NoChronologicAt(const unsigned int offset) const
Get nth element in a non chronological order.
Base Exception for Stock and StockManager, all src_cpp code.
std::map< ETime, std::vector< ListDataStockBase * > >::const_iterator cit_map
bool IsEmpty() const
Test if some ListData are still present, whatever the timescale.
Use a policy PolicyChronologic, default VecNoChronologic.
static Indicator const AD
Specific class when the file cannot be found and opened.
std::string GetNameStock(const std::string &fname)
Extract the name of the stock.
void UpdateAllTimeScale(const ETime tmscl, Utils::firstlast_dates opt_dates=Utils::get_fldate_default(), bool b_readfile=true)
Update all indicators of the given TimeScale.
Main class to deal with one stock.
Data type to describe Japanese candlesticks : open, high, low and close values.
auto as_uint(ETime const value) -> unsigned int
Provides explicit conversion to unsigned int.
virtual time_t GetFirstTime() const =0
Get the date of the first data (always chronological meaning)
for dealing with error in reading, problem of formatting for instance
int AddListDataToMap(const ETime &tmscl, ListDataStockBase *p_listdata)
Insert a ListDataStock to the map.
const time_t ERROR_StrToTime
Error code returned by StringToTime_t if the string cannot be parsed correctly Must be a time_t...
virtual const char * what() const noexcept
for getting the message with standard interface do not throw exception
Wrapper/Adapter to the library ta-lib.
virtual void Order(const EPChrono chrono)=0
Function to reverse the internal vector in its original policy.
std::vector< ListDataStockBase * >::const_iterator cit_listdata
Indicator GetIndicator(const std::string &sname)
Extract the indicator from a frame name.
void DeleteListData(const ETime &tmscl, const Indicator &indic, std::vector< int > param=std::vector< int >())
Delete a list given the TimeScale, Indicator and param.
virtual void Replace(const ListDataStockBase *)=0
Replace all DataStock's of the list with ldata_in.data, without checking for update.
static void WriteLineHeader(const ETime &tmscl, const Utils::firstlast_dates &dates, std::ostringstream &ss_header)
Write the header in a stream.
static Indicator const Volume
ETime
Enumeration for the different time representation, from instantaneous (INST) to year(YEAR) ...
int nb_output() const
Nb of ListDataStock output of TALib computation.
int Transform_TimeScale(const ETime &new_tmscl)
Transform history values dcsv or DAY to M5,M10..H1 or WEEK, MONTH..YEAR.
static Indicator const StockInst
ListDataStock< SimpleData, VecChronologic > ldata_ta_sd
For technical indicator, TAlib process and return always chronologic data.
ListDataStockBase * GetListData(const ETime &tmscl, const Indicator &indic, const std::vector< int > param=std::vector< int >()) const
Get the ListDataStock from a TimeScale, Indicator and vector of parameters.
void LoadCSVData(const ETime &tmscl, Utils::firstlast_dates &dates)
Get Indicator::StockCSV or StockdCSV with the correct TimeScale Call functions to read and load data ...
virtual Utils::firstlast_dates GetDates() const
Return the structure Utils::firstlast_dates of the private data member, not from the data...
std::string toString(const T &t)
virtual const DataStock & ChronologicAt(const unsigned int offset) const =0
Get the nth element in a chronological order.
void WriteCSV(const ETime tmscl, bool opt_tmp=false) const
Write historical data into files.
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.
bool CheckLoaded(const ETime &tmscl) const
ListDataStock< MultiData, VecChronologic > ldata_ta_md
For dealing with multiple values, e.g., MACD.
virtual void SetData(const time_t d, const std::vector< type_value_data > &vec)
Set a full Data : date + value(s) in a vector.
Stock()
Default constructor.
time_t StringToTime_t(const std::string &str_date)
Return the time_t from a string .
Specific for TALib part of the code.
void MergeStock(const Stock *new_stock, bool)
Merge entries with an other stock.
unsigned int ReadCSV(const ETime tmscl, Utils::firstlast_dates dates=Utils::get_fldate_default())
Read DAY or INST file depending on the TimeScale.
std::string GetTimeScaleName(const ETime &tmscl)
Get the string, i.e., "DAY".
std::string GetPathData()
int ComputeTA(const ETime &tmscl, const std::string &name_indic)
Compute an indicator using the TAlib library.
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.
virtual void SetDates(const time_t first, const time_t last)
Set dates, 2 arguments.
virtual const char * what() const noexcept
static Indicator const StockCSV
std::string GetName() const
virtual std::string GetFullName() const
Abstract base class for the ListDataStock, for storing base pointers in vectors.
void Updated(const ETime tmscl)
Return the last available date of historical data.
void DeleteAllListData(const ETime &tmscl)
Delete all data of the given TimeScale.
TAlibAPI * p_talib
pointer to TA-lib API object, use a lazy initialization of the library
void PrintMapChrono(const unsigned int verbose=0) const
Print map content to the console.
Base class for exception coming from talibapi interface.
time_t GetDate() const
Get the date data member.
virtual void SetFullName(std::string fname)
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::map< ETime, std::vector< ListDataStockBase * > > mapTime_ListData
map TimeScale : vector of ListDataStockBase pointers
static int Read_HeaderCSV_static(std::string namestock, ETime tmscl, Utils::firstlast_dates &dates)
Static version of Read_HeaderCSV.
int LoadListData(const ETime &tmscl, const Indicator &indic=Indicator::StockCSV, const std::vector< int > ¶m=std::vector< int >(), Utils::firstlast_dates dates=Utils::get_fldate_default())
Load or/and compute an indicator in the Stock.
API for using TA_lib of X in ROOT_Application.
cit_listdata GetItList(cit_map &it_m, const Indicator &indic, const std::vector< int > ¶m=std::vector< int >()) const
int Read_HeaderCSV(ETime tmscl, Utils::firstlast_dates &dates) const
Read the dates from the header file.
static int UpdateCSV_Inst(std::string namestock, DataStock &inst_value, DataStock &inst_volume, ETime tmscl, bool opt_tmp=false)
Update file with TimeScale INST.
std::string MakeShortName(const Indicator &indic, const std::vector< int > ¶m)
Create a short name from its components.
virtual ETime GetTimeScale() const
void splitline(const std::string &str, const std::string &delimiters, std::vector< std::string > &tokens)
splitline
general structure for dates in csv files
std::string symbol
symbol refers to the code, i.e., CAC40
File included by Stock.cpp, Function for embedding python in Stock class.
add my own, if file is empty really or empty of data
std::string GetName() const
Abstract base class for all Data to be stored in ListDataStock.
std::string const label() const
Get the label.
std::string name
Name of the stock.
const T & ChronologicAt(const unsigned int offset) const
Get the nth element in a chronological order.
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...