ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Private Member Functions | Private Attributes
Stock Class Reference

Main class to deal with one stock. More...

#include <Stock.h>

Collaboration diagram for Stock:
Collaboration graph
[legend]

Public Member Functions

Constructors, destructor
 Stock ()
 Default constructor. More...
 
 Stock (const std::string iname, const std::string isymbol, const std::string ipath)
 to delete More...
 
 Stock (const std::string iname, const std::string ipath=Utils::GetPathData())
 Set the name (symbol == name), optionally the path of the data. More...
 
virtual ~Stock ()
 
Getters/Setters to private data
std::string GetName () const
 
std::string GetSymbol () const
 
std::string GetPath () const
 
Check / Retrieve content of the Stock
bool CheckLoaded (const ETime &tmscl) const
 
bool CheckLoaded (const ETime &tmscl, const Indicator &indic, const std::vector< int > &param=std::vector< int >()) const
 Check with a TimeScale and an indicator. More...
 
bool CheckLoaded (const ETime &tmscl, const std::string &sname) const
 Check with a TimeScale and the shortname. More...
 
bool IsEmpty () const
 Test if some ListData are still present, whatever the timescale. More...
 
ListDataStockBaseGetListData (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. More...
 
ListDataStockBaseGetListData (const ETime &tmscl, const std::string &sname) const
 Get the ListDataStock from a TimeScale and a string with the shortname format: "Indicator_params". More...
 
Load/Compute new indicators
int LoadListData (const ETime &tmscl, const Indicator &indic=Indicator::StockCSV, const std::vector< int > &param=std::vector< int >(), Utils::firstlast_dates dates=Utils::get_fldate_default()) throw (StockException)
 Load or/and compute an indicator in the Stock. More...
 
Delete List data from the Stock
void DeleteListData (const ETime &tmscl, const Indicator &indic, std::vector< int > param=std::vector< int >())
 Delete a list given the TimeScale, Indicator and param. More...
 
void DeleteListData (const ETime &tmscl, const std::string &sname)
 Delete a list given the TimeScale and the ShortName "indic_params". More...
 
void DeleteAllListData (const ETime &tmscl)
 Delete all data of the given TimeScale. More...
 
Update the List(s)
int AddListDataToMap (const ETime &tmscl, ListDataStockBase *p_listdata)
 Insert a ListDataStock to the map. More...
 
void Updated (const ETime tmscl)
 Return the last available date of historical data. More...
 
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. More...
 
int UpdateCSVFromFile (const ETime tmscl)
 Load the last historical data from the filesystem into a List in memory. More...
 
int UpdateCSVFromWeb (const std::string &source, Utils::firstlast_dates opt_dates=Utils::get_fldate_default()) throw (StockException)
 Update data from the Python parser (and save into the filesystem). More...
 
void MergeStock (const Stock *new_stock, bool)
 Merge entries with an other stock. More...
 
Nice output to console
void PrintMapChrono (const unsigned int verbose=0) const
 Print map content to the console. More...
 
Python embedded functions, access ServerPortfolio classes and methods
int LoadDictionary (std::string dict="")
 Load the dictionary of Stock, see ServerPortfolio. More...
 
int TestwrapPython (std::string source)
 
int TestwrapPython2 (std::string source)
 

Private Types

iterator typedefs for the map
typedef std::map< ETime,
std::vector< ListDataStockBase * >
>::iterator 
it_map
 
typedef std::map< ETime,
std::vector< ListDataStockBase * >
>::const_iterator 
cit_map
 
typedef std::vector
< ListDataStockBase * >
::iterator 
it_listdata
 
typedef std::vector
< ListDataStockBase * >
::const_iterator 
cit_listdata
 

Private Member Functions

void SetLDataFullName (ListDataStockBase *p_listdata) const
 Function to complete the fullname of a listdatastock. More...
 
Internal methods function to access iterators to ListDataStock from the map
Warning
To call if sure than it_map is not at end(), no check performed inside
cit_listdata GetItList (cit_map &it_m, const Indicator &indic, const std::vector< int > &param=std::vector< int >()) const
 
cit_listdata GetItList (cit_map &it_m, const std::string &sname) const
 
it_listdata GetItList (it_map &it_m, const Indicator &indic, const std::vector< int > &param=std::vector< int >())
 version non-const More...
 
it_listdata GetItList (it_map &it_m, const std::string &sname)
 version non-const More...
 
Helper methods for loading and computing indicators
void LoadCSVData (const ETime &tmscl, Utils::firstlast_dates &dates) throw (StockException)
 Get Indicator::StockCSV or StockdCSV with the correct TimeScale Call functions to read and load data from file ReadCSV, day or dcsv. More...
 
int Transform_TimeScale (const ETime &new_tmscl)
 Transform history values dcsv or DAY to M5,M10..H1 or WEEK, MONTH..YEAR. More...
 
int ComputeTA (const ETime &tmscl, const std::string &name_indic) throw (TALibException)
 Compute an indicator using the TAlib library. More...
 

Static Private Member Functions

Helper (static) methods to Read/Write headers files
static int ReadLineHeader (const std::string &line, Utils::firstlast_dates &dates)
 Extract dates from the header of the historic data files. More...
 
static void WriteLineHeader (const ETime &tmscl, const Utils::firstlast_dates &dates, std::ostringstream &ss_header)
 Write the header in a stream. More...
 

Private Attributes

std::string name
 Name of the stock. More...
 
std::string symbol
 symbol refers to the code, i.e., CAC40 More...
 
const std::string path
 File path for the data directory. More...
 
TAlibAPIp_talib
 pointer to TA-lib API object, use a lazy initialization of the library More...
 
std::map< ETime, std::vector
< ListDataStockBase * > > 
mapTime_ListData
 map TimeScale : vector of ListDataStockBase pointers More...
 

Related to file I/O

unsigned int ReadCSV (const ETime tmscl, Utils::firstlast_dates dates=Utils::get_fldate_default()) throw ( StockFileError )
 Read DAY or INST file depending on the TimeScale. More...
 
void WriteCSV (const ETime tmscl, bool opt_tmp=false) const throw ( StockException )
 Write historical data into files. More...
 
int SaveCSV (const ETime tmscl, bool opt_tmp=false) const
 Save Historical data to file. More...
 
int Read_HeaderCSV (ETime tmscl, Utils::firstlast_dates &dates) const throw ( StockFileError )
 Read the dates from the header file. More...
 
static int Read_HeaderCSV_static (std::string namestock, ETime tmscl, Utils::firstlast_dates &dates) throw ( StockFileError )
 Static version of Read_HeaderCSV. More...
 
static int UpdateCSV_Inst (std::string namestock, DataStock &inst_value, DataStock &inst_volume, ETime tmscl, bool opt_tmp=false) throw ( StockFileError )
 Update file with TimeScale INST. More...
 

Detailed Description

Main class to deal with one stock.

Object defined for each stock (e.g. DJ, FP, CAC40 )
Store ListDataStock's for historic values and indicators at all TimeScale.

Usage:

// creates a new Stock to follow the French CAC40 indices
Stock *st = new Stock("CAC40");
// Load the daily historic, read all data available from the file system
// Compute the Simple Moving Average of 15 days size, and store the data in memory
st->LoadListData( ETime::DAY, "SMA_15" );

Implementation details:
For each key (TimeScale enumeration ETime) a list of pointer on a ListDataStock :

Definition at line 56 of file Stock.h.

Member Typedef Documentation

typedef std::vector<ListDataStockBase *>::const_iterator Stock::cit_listdata
private

Definition at line 64 of file Stock.h.

typedef std::map<ETime, std::vector<ListDataStockBase *> >::const_iterator Stock::cit_map
private

Definition at line 62 of file Stock.h.

typedef std::vector<ListDataStockBase *>::iterator Stock::it_listdata
private

Definition at line 63 of file Stock.h.

typedef std::map<ETime, std::vector<ListDataStockBase *> >::iterator Stock::it_map
private

Definition at line 61 of file Stock.h.

Constructor & Destructor Documentation

Stock::Stock ( )
inline

Default constructor.

Definition at line 198 of file Stock.h.

References p_talib.

Referenced by SaveCSV().

Here is the caller graph for this function:

Stock::Stock ( const std::string  iname,
const std::string  isymbol,
const std::string  ipath 
)

to delete

Definition at line 29 of file Stock.cpp.

References p_talib.

Stock::Stock ( const std::string  iname,
const std::string  ipath = Utils::GetPathData() 
)

Set the name (symbol == name), optionally the path of the data.

Definition at line 39 of file Stock.cpp.

References p_talib, and symbol.

Stock::~Stock ( )
virtual

Definition at line 47 of file Stock.cpp.

References mapTime_ListData, name, p_talib, and symbol.

Member Function Documentation

int Stock::AddListDataToMap ( const ETime tmscl,
ListDataStockBase p_listdata 
)

Insert a ListDataStock to the map.

Check if one already exists:

  • if CSV, dCSV or volume check if it is an update
  • if TA always call Replace ( recompute all TA by default )
    Else:
  • Insert the new list

Return value :

  • if new insertion return 0
  • if update of an existing listdata (update or replace) return 1 => need to delete the entry p_listdata
  • else error or exit, 2 : if entry has size 0, makes assert
Precondition
  • p_listdata must be allocated on the heap
  • size of p_listdata > 0, checked by an assert
  • shortname of p_listdata must be similar for a correct update
Postcondition
  • fullname of the inserted list is correct
  • if return 1 (update), the caller must delete p_listdata otherwise the list will not be deleted !

code example with return value and delete

Parameters
tmsclTimeScale of the list
p_listdatapointer on the list data to insert
Returns
int code status, see comments above

Definition at line 622 of file Stock.cpp.

References ListDataStockBase::AddToList(), ListDataStockBase::GetFullName(), ShortName::GetIndicator(), GetListData(), ListDataStockBase::GetName(), ListDataStockBase::GetSize(), mapTime_ListData, ListDataStockBase::Replace(), SetLDataFullName(), Indicator::StockCSV, Indicator::StockInst, and Indicator::Volume.

Referenced by MergeStock(), SaveCSV(), StockManager::SendDatadCSV(), Transform_TimeScale(), and wrapUpdateCSV().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Stock::CheckLoaded ( const ETime tmscl) const

Definition at line 529 of file Stock.cpp.

References mapTime_ListData.

Referenced by StockManager::Load(), and UpdateCSVFromFile().

Here is the caller graph for this function:

bool Stock::CheckLoaded ( const ETime tmscl,
const Indicator indic,
const std::vector< int > &  param = std::vector<int>() 
) const

Check with a TimeScale and an indicator.

Definition at line 539 of file Stock.cpp.

References GetItList(), and mapTime_ListData.

Here is the call graph for this function:

bool Stock::CheckLoaded ( const ETime tmscl,
const std::string &  sname 
) const

Check with a TimeScale and the shortname.

Definition at line 553 of file Stock.cpp.

References GetItList(), and mapTime_ListData.

Here is the call graph for this function:

int Stock::ComputeTA ( const ETime tmscl,
const std::string &  name_indic 
)
throw (TALibException
)
private

Compute an indicator using the TAlib library.

Parameters
tmscl: timescale
name_indic: shortname of the indicator, e.g. "SMA_3"
Exceptions
TALibException

Definition at line 352 of file Stock.cpp.

References Indicator::AD, INST, Indicator::label(), Indicator::nb_output(), Indicator::nb_param(), Indicator::Null, Indicator::Set(), Indicator::StockCSV, Indicator::StockInst, Utils::toString(), Indicator::Volume, and TALibException::what().

Referenced by UpdateAllTimeScale().

Here is the call graph for this function:

Here is the caller graph for this function:

void Stock::DeleteAllListData ( const ETime tmscl)

Delete all data of the given TimeScale.

Definition at line 916 of file Stock.cpp.

References mapTime_ListData, and PrintMapChrono().

Referenced by StockManager::DeleteAllListDataFromTimeScale().

Here is the call graph for this function:

Here is the caller graph for this function:

void Stock::DeleteListData ( const ETime tmscl,
const Indicator indic,
std::vector< int >  param = std::vector<int>() 
)

Delete a list given the TimeScale, Indicator and param.

Definition at line 872 of file Stock.cpp.

References Indicator::label(), and ShortName::MakeShortName().

Referenced by StockManager::DeleteListData().

Here is the call graph for this function:

Here is the caller graph for this function:

void Stock::DeleteListData ( const ETime tmscl,
const std::string &  sname 
)

Delete a list given the TimeScale and the ShortName "indic_params".

Definition at line 885 of file Stock.cpp.

References GetItList(), and mapTime_ListData.

Here is the call graph for this function:

Stock::cit_listdata Stock::GetItList ( Stock::cit_map it_m,
const Indicator indic,
const std::vector< int > &  param = std::vector<int>() 
) const
private

Definition at line 72 of file Stock.cpp.

References ShortName::MakeShortName().

Referenced by CheckLoaded(), DeleteListData(), GetItList(), and GetListData().

Here is the call graph for this function:

Here is the caller graph for this function:

Stock::cit_listdata Stock::GetItList ( Stock::cit_map it_m,
const std::string &  sname 
) const
private

Definition at line 81 of file Stock.cpp.

Stock::it_listdata Stock::GetItList ( it_map it_m,
const Indicator indic,
const std::vector< int > &  param = std::vector<int>() 
)
private

version non-const

Definition at line 94 of file Stock.cpp.

References GetItList(), and ShortName::MakeShortName().

Here is the call graph for this function:

Stock::it_listdata Stock::GetItList ( it_map it_m,
const std::string &  sname 
)
private

version non-const

Definition at line 101 of file Stock.cpp.

ListDataStockBase * Stock::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.

Parameters
tmsclTimeScale, e.g., ETime::DAY, ETime::YEAR
indicIndicator, e.g., Indicator::StockCSV, Indicator::Volume
paramvector of int to set optional parameters
Returns
a pointer to the list or nullptr if it is not found

Definition at line 581 of file Stock.cpp.

References GetItList(), and mapTime_ListData.

Referenced by AddListDataToMap(), StockManager::GetListData(), SaveCSV(), StockManager::SendDatadCSV(), Transform_TimeScale(), and UpdateCSVFromFile().

Here is the call graph for this function:

Here is the caller graph for this function:

ListDataStockBase * Stock::GetListData ( const ETime tmscl,
const std::string &  sname 
) const

Get the ListDataStock from a TimeScale and a string with the shortname format: "Indicator_params".

The string can be constructed with Utils::MakeShortName( Indicator, vec_params )

Parameters
tmsclTimeScale, e.g., ETime::DAY, ETime::YEAR
snamedescribes fully a list in ShortName format, e.g., "SMA_15","MACD_12_9_26"
Returns
a pointer to the list or nullptr if it is not found

Definition at line 597 of file Stock.cpp.

References GetItList(), and mapTime_ListData.

Here is the call graph for this function:

std::string Stock::GetName ( ) const
inline

Definition at line 210 of file Stock.h.

References name.

Referenced by StockManager::AddStock(), StockManager::DeleteAllListDataFromTimeScale(), StockManager::DeleteListData(), MergeStock(), PrintMapChrono(), and SetLDataFullName().

Here is the caller graph for this function:

std::string Stock::GetPath ( ) const
inline

Definition at line 212 of file Stock.h.

References path.

std::string Stock::GetSymbol ( ) const
inline

Definition at line 211 of file Stock.h.

References symbol.

bool Stock::IsEmpty ( ) const

Test if some ListData are still present, whatever the timescale.

Definition at line 567 of file Stock.cpp.

References mapTime_ListData, and name.

Referenced by StockManager::DeleteAllListDataFromTimeScale(), and StockManager::DeleteListData().

Here is the caller graph for this function:

void Stock::LoadCSVData ( const ETime tmscl,
Utils::firstlast_dates dates 
)
throw (StockException
)
private

Get Indicator::StockCSV or StockdCSV with the correct TimeScale Call functions to read and load data from file ReadCSV, day or dcsv.


And transform the TimeScale if needed.

Check than both StockCSV/StockInst and Volume are present before TransformTimeScale is called.
Otherwise, force to re-read the file (existing Lists should be "replaced")

Parameters
tmsclTimeScale to load
datesrange of dates when reading the data. Default use all.
Exceptions
StockException

Definition at line 177 of file Stock.cpp.

References DAY, INST, Indicator::StockCSV, Indicator::StockInst, Indicator::Volume, and StockFileError::what().

Here is the call graph for this function:

int Stock::LoadListData ( const ETime tmscl,
const Indicator indic = Indicator::StockCSV,
const std::vector< int > &  param = std::vector<int>(),
Utils::firstlast_dates  dates = Utils::get_fldate_default() 
)
throw (StockException
)

Load or/and compute an indicator in the Stock.

If an indicator is already present (whatever the initial dates range), the function return 1, it does not try to update.
Update can be done by calling again ReadCSV (with some limitations about dates) for DAY or INST
or call method UpdateAllTimeScale for Indicators

By default the historical data at the same TimeScale are loaded before the indicator are computed,
so that it is possible to ask for a SMA 3 directly.

Example of usage:

  • Load daily historical data of the SP500, all dates available from the file
    stock = new Stock("SP500");
    stock->LoadListData( ETime::DAY );
  • Compute SMA with a moving block of 3 weeks, on weekly data from the start of the year 2012
    // set the dates range, important to set default values here
    fldates.first = Utils::StringToTime_t("2012-01-01");
    // if last is not specified, it is assumed up to the last data available
    // fldates.last = Utils::StringToTime_t("2012-12-31");
    stock->LoadListData( ETime::WEEK, Indicator::SMA, std::vector<int>{3}, fldates );
Parameters
tmsclTimeScale
indicIndicator, default StockCSV, the function loads the historical data from files
paraman optional vector containing the parameters of the indicator. (Some indicators have a default values (see Indicator.h), but not used here)
datesoptional dates to limit the range. Apply only when reading the file (DAY and INST), other TimeScale are transformed from them. Default use all available (in memory or in file)
Returns
status 0 : loaded correctly, 1 the indicator was already present, others problems throw exception
Exceptions
StockExceptionerror in filesystem or cannot compute the indicator

Definition at line 801 of file Stock.cpp.

References TimeScale::GetTimeScaleName(), ShortName::MakeShortName(), Indicator::Null, Utils::Time_tToString(), and TALibException::what().

Referenced by StockManager::Load(), SaveCSV(), and TransDateBox::Valid().

Here is the call graph for this function:

Here is the caller graph for this function:

void Stock::MergeStock ( const Stock new_stock,
bool   
)

Merge entries with an other stock.

The calling object will insert new entries and replace or discard existing ones

Parameters
new_stockstock to merge into this
to_replaceif true the new entries will replace the existing ones, otherwise they are discarded. Partly implemented

Definition at line 730 of file Stock.cpp.

References AddListDataToMap(), GetName(), and mapTime_ListData.

Referenced by StockManager::AddStock().

Here is the call graph for this function:

Here is the caller graph for this function:

void Stock::PrintMapChrono ( const unsigned int  verbose = 0) const

Print map content to the console.

verbose similar to ListDataStock::PrintData() :

  • 0 Print first and last data of each ListDataStock, with header
  • 1 Print all data, no header
    Parameters
    verbose: level of detail 0 or 1

Definition at line 2127 of file Stock.cpp.

References GetName(), and mapTime_ListData.

Referenced by DeleteAllListData(), MainControllerIndicatorTHStock::Validation(), and wrapUpdateCSV().

Here is the call graph for this function:

Here is the caller graph for this function:

int Stock::Read_HeaderCSV ( ETime  tmscl,
Utils::firstlast_dates dates 
) const
throw (StockFileError
)

Read the dates from the header file.

Open and read header of namestock.DAY/INST.csv
will assign first/last date called before stock created in gui, want to call static Stock::Read_Header

Parameters
tmsclTimeScale, will read DA> or INST
datesstructure will contain first and last dates after execution
Returns
status 0 is ok
Exceptions
StockFileErrorcannot be open, or missing header

Definition at line 1487 of file Stock.cpp.

References TimeScale::GetTimeScaleName(), path, and Indicator::StockCSV.

Referenced by SaveCSV(), UpdateCSVFromFile(), and MainControllerIndicatorTHStock::Validation().

Here is the call graph for this function:

Here is the caller graph for this function:

int Stock::Read_HeaderCSV_static ( std::string  namestock,
ETime  tmscl,
Utils::firstlast_dates dates 
)
throw (StockFileError
)
static

Static version of Read_HeaderCSV.

Read file : "Utils::GetPathData()/historical/namestock.tmscl.csv"
Test version
path is taken from Utils::GetPathData()

Parameters
namestockname of the stock, considered similar as symbol
tmsclTimeScale to read
datesstructure will contain first and last dates after execution
Returns
status 0 is ok
Exceptions
StockFileErrorcannot be open, or missing header

Definition at line 1519 of file Stock.cpp.

References Utils::GetPathData(), TimeScale::GetTimeScaleName(), and Indicator::StockCSV.

Referenced by wrapLastCSVUpdate().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int Stock::ReadCSV ( const ETime  tmscl,
Utils::firstlast_dates  dates = Utils::get_fldate_default() 
)
throw (StockFileError
)

Read DAY or INST file depending on the TimeScale.

Create a ListDataStock with TimeScale ETime::DAY or ETime::INST (Indicator::StockCSV or Indicator::StockInst) and insert to the map.
Files are read from the data member path, setup by default to Utils::GetPathData().
Theses files are in the subdirectory "historical_data"

If dates.first only is specified (dates.last = 0), load all data from dates.first to last in file
If dates.last only (dates.first = 0), load all data from first in file to dates.last

Note
It is advised to initialize the structure, i.e.,

This function can be called 2 times for an update if :

  • the first time is equal to the first time of the list in memory, it replaces all existing data
  • the first time is equal or superior to the last time in memory (assert in ListDataStock::AddToList, it tries to update)
    Parameters
    tmsclTimescale
    datesoptional structure (Utils::firstlast_dates), range of dates to load, default (0,0) all.
    Returns
    the number of data read from the file. (Could return the integer from AddListToMap ?)
    Exceptions
    StockFileError

Definition at line 957 of file Stock.cpp.

References ListDataStockBase::AddData(), CHRONO, DAY, Utils::firstlast_dates::first, DataStock::GetDate(), ListDataStockBase::GetSize(), TimeScale::GetTimeScaleName(), INST, Utils::firstlast_dates::last, NO_CHRONO, not_a_time, ListDataStockBase::Order(), path, SimpleData::SetData(), ListDataStockBase::SetDates(), Utils::splitline(), Indicator::StockCSV, Utils::StringToTime_t(), and Utils::Time_tToString().

Referenced by UpdateCSVFromFile().

Here is the call graph for this function:

Here is the caller graph for this function:

int Stock::ReadLineHeader ( const std::string &  line,
Utils::firstlast_dates dates 
)
staticprivate

Extract dates from the header of the historic data files.

Parameters
linestring input, header format 4 or 6 fields
datesfill the Utils::firstlast_dates structure with dates read from the line
Returns
0 ok, else problem with string format

Definition at line 116 of file Stock.cpp.

References Utils::ERROR_StrToTime, Utils::firstlast_dates::first, Utils::firstlast_dates::last, Utils::splitline(), Utils::StringToTime_t(), and Utils::Time_tToString().

Here is the call graph for this function:

int Stock::SaveCSV ( const ETime  tmscl,
bool  opt_tmp = false 
) const

Save Historical data to file.

This method assures than no data are lost when writing to file.
It should be preferred to WriteCSV in this sense

Parameters
tmsclTimeScale to save
opt_tmpif true will write to PATH_DATA/historical_data_tmp directory, for tests (to not overwrite original)
Returns
status, 0 normal data have been saved to file, -1 (did nothing) List not loaded in memory or File already up to date
Exceptions
StockExceptionthrow by WriteCSV

Definition at line 1357 of file Stock.cpp.

References AddListDataToMap(), Utils::firstlast_dates::first, Utils::get_fldate_default(), ListDataStockBase::GetFirstTime(), GetListData(), INST, Utils::firstlast_dates::last, ListDataStockBase::LastUpdate(), LoadListData(), M5, name, not_a_time, Read_HeaderCSV(), Stock(), Indicator::StockCSV, Indicator::StockInst, Indicator::Volume, and WriteCSV().

Referenced by wrapUpdateCSV().

Here is the call graph for this function:

Here is the caller graph for this function:

void Stock::SetLDataFullName ( ListDataStockBase p_listdata) const
private

Function to complete the fullname of a listdatastock.


Done automaticaly when new data are inserted

Parameters
ListDataStockBasepointer on the List to modify

Definition at line 258 of file Stock.cpp.

References ListDataStockBase::GetName(), GetName(), ListDataStockBase::GetTimeScale(), TimeScale::GetTimeScaleName(), and ListDataStockBase::SetFullName().

Referenced by AddListDataToMap().

Here is the call graph for this function:

Here is the caller graph for this function:

int Stock::Transform_TimeScale ( const ETime new_tmscl)
private

Transform history values dcsv or DAY to M5,M10..H1 or WEEK, MONTH..YEAR.

Always try

Parameters
new_tmsclnew timescale to compute, different of dcsv or DAY (assert)
Returns
status 0 ok, 1 error the list dcsv or DAY cannot be retrieved

Definition at line 273 of file Stock.cpp.

References AddListDataToMap(), DAY, GetListData(), INST, not_a_time, Indicator::StockCSV, Indicator::StockInst, ListDataStock_Utils::TransformTimeScale(), and Indicator::Volume.

Referenced by main(), and UpdateAllTimeScale().

Here is the call graph for this function:

Here is the caller graph for this function:

void Stock::UpdateAllTimeScale ( const ETime  tmscl,
Utils::firstlast_dates  opt_dates = Utils::get_fldate_default(),
bool  b_readfile = true 
)

Update all indicators of the given TimeScale.

DAY, call to UpdateCSVFromWeb (query Yahoo), and save data to file if new ones available. INST (normally updated by Server), but could call UpdateCSVFromFile (argument or check dates)

Then transform to the correct TimeScale and recompute ta-lib Indicators

Parameters
tmsclTimeScale to update
opt_datesoptional, specify a range of dates for the update
b_readfile
Returns
size of ListData StockCSV, the largest one, not implemented ? useful ? maybe the number of update better

Definition at line 1892 of file Stock.cpp.

References ComputeTA(), DAY, FullName::GetNameStock(), INST, Utils::firstlast_dates::last, mapTime_ListData, Indicator::Null, Indicator::Set(), Transform_TimeScale(), UpdateCSVFromFile(), and UpdateCSVFromWeb().

Referenced by Updated().

Here is the call graph for this function:

Here is the caller graph for this function:

int Stock::UpdateCSV_Inst ( std::string  namestock,
DataStock inst_value,
DataStock inst_volume,
ETime  tmscl,
bool  opt_tmp = false 
)
throw (StockFileError
)
static

Update file with TimeScale INST.

Append the new data (instantaneous value and volume) to the file and update the header.
Creates the file if it does not exist.

Implemented for wrapPyStock, python modules can update the file with a correct format of string and modify the header.
Files at timescale ETime::INST are in a chronological order. Faster to append data than reading all previous data.

Parameters
namestocknecessary if want to keep as static function
inst_value,inst_volumeDataStocks for instantaneous value and volume
tmsclshould only be ETime::INST. Maybe later follow same logic for writing M5, M10 because often updated
Returns
status 0 ok new data added. -1 error data have not been added
Exceptions
StockFileErrorproblem in opening or writing into the file

Definition at line 1555 of file Stock.cpp.

References Utils::firstlast_dates::first, Utils::get_fldate_default(), Utils::GetPathData(), TimeScale::GetTimeScaleName(), INST, Utils::firstlast_dates::last, not_a_time, and Indicator::StockCSV.

Referenced by wrap_SaveInst().

Here is the call graph for this function:

Here is the caller graph for this function:

int Stock::UpdateCSVFromFile ( const ETime  tmscl)

Load the last historical data from the filesystem into a List in memory.

Original use with INST data, ServerPortfolio always writes the new data to files, and the List was not updated by the Server.
With DAY works the same, when update from Yahoo is asked by an other process.
Assume the file has been updated (not a precondition), the function will make a call to ReadCSV to add the new data.
If the List contains more data than the file (updated by other way: ServerSM), return -1 (or special code CANNOT_UPDATE)
If only a range of the initial data have been loaded all the new data will be added. (maybe not expected with GUI use)
If the List is empty (call from a script), load all the data.

Parameters
tmsclETime::INST or ETime::DAY (assert to release later)
Returns
number of new data added to the list, 0 nothing has been added, -1 cannot update (in memory more recent than file)
Exceptions
StockFileErrormay be throw by ReadCSV

Definition at line 2068 of file Stock.cpp.

References CheckLoaded(), Utils::firstlast_dates::first, Utils::get_fldate_default(), GetListData(), INST, Utils::firstlast_dates::last, ListDataStockBase::LastUpdate(), Indicator::Null, Read_HeaderCSV(), ReadCSV(), Indicator::StockCSV, Indicator::StockInst, and Utils::Time_tToString().

Referenced by UpdateAllTimeScale().

Here is the call graph for this function:

Here is the caller graph for this function:

void Stock::Updated ( const ETime  tmscl)

Return the last available date of historical data.

First read the last date form the header.
If already loaded in-memory use the last date of it.
If load_list and not in-memory force to load the list in Stock, should be the same date as header.

Check than date in header is not larger than date in-memory. It means only a range has been loaded and update may cause problems. What's about the first date ? If not in memory will need to take care when saving to file.

Before, always load the data in memory, some calling function need this
But could only read the header by default (see LastCSVUpdateFromFile)

Parameters
tmscltimescale query, should be ETime::DAY or ETime::INST
boolload_list force to load the ListDataStock if not in memory, default read only the header
Returns
time_t or 0 if error : wrong timescale
Exceptions
StockException
Deprecated:
to delete, easy to read_header

Indicate than data at tmscl have updated, will recompute all (historical data and indicators) for larger TimeScale.

Call by StockManger when a new TCP message has been received and new data have been added.
Inform than new data have been provided ( dcsv for now, later can be CSV as well ) and call UpdateAllTimeScale, specifying Data must not been read from file. All other update, recompuation similar

Should not use LoadListData for this purpose

Parameters
tmsclwill recompute all indicators at this TimeScale

Definition at line 1799 of file Stock.cpp.

References TimeScale::as_uint(), DAY, Utils::get_fldate_default(), INST, M5, mapTime_ListData, not_a_time, and UpdateAllTimeScale().

Referenced by StockManager::SendDatadCSV().

Here is the call graph for this function:

Here is the caller graph for this function:

void Stock::WriteCSV ( const ETime  tmscl,
bool  opt_tmp = false 
) const
throw (StockException
)

Write historical data into files.

Write the values and the volume at a specified TimeScale, do not check for previous data in file.

Note
Prefer SaveCSV to assure than no data are lost in writing the file.

Only DAY is used (INST files are normally written by python ServerPortfolio, now by UpdateCSV_Inst),
other are implemented and unit-tested, but not used at the moment inside the library.

Parameters
tmsclTimeScale to write
opt_tmpif true will write to PATH_DATA/historical_data_tmp directory for tests (not overwrite original)
Exceptions
StockException

Definition at line 1247 of file Stock.cpp.

References ListDataStockBase::ChronologicAt(), ListDataStock< T, PolicyChronologic >::ChronologicAt(), ListDataStockBase::GetDates(), ListDataStockBase::GetSize(), TimeScale::GetTimeScaleName(), INST, ListDataStockBase::NoChronologicAt(), ListDataStock< T, PolicyChronologic >::NoChronologicAt(), not_a_time, path, Indicator::StockCSV, Indicator::StockInst, and Indicator::Volume.

Referenced by main(), and SaveCSV().

Here is the call graph for this function:

Here is the caller graph for this function:

void Stock::WriteLineHeader ( const ETime tmscl,
const Utils::firstlast_dates dates,
std::ostringstream &  ss_header 
)
staticprivate

Write the header in a stream.

include version number(fixed not used) include TimeScale in string format include dates of first and last data

Parameters
tmsclTimeScale
dates
ss_headerfilled with correct infos

Definition at line 159 of file Stock.cpp.

References DAY, Utils::firstlast_dates::first, Utils::firstlast_dates::last, and Utils::Time_tToString().

Here is the call graph for this function:

Field Documentation

std::map<ETime, std::vector<ListDataStockBase *> > Stock::mapTime_ListData
private
std::string Stock::name
private

Name of the stock.

By default name == symbol, but may change later.
Used to construct FullName.

Definition at line 71 of file Stock.h.

Referenced by GetName(), IsEmpty(), SaveCSV(), and ~Stock().

TAlibAPI* Stock::p_talib
private

pointer to TA-lib API object, use a lazy initialization of the library

Definition at line 89 of file Stock.h.

Referenced by Stock(), and ~Stock().

const std::string Stock::path
private

File path for the data directory.

See Also
Utils::PATH_DATA

Definition at line 86 of file Stock.h.

Referenced by GetPath().

std::string Stock::symbol
private

symbol refers to the code, i.e., CAC40

Definition at line 77 of file Stock.h.

Referenced by GetSymbol(), Stock(), and ~Stock().


The documentation for this class was generated from the following files: