ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Transform_TimeCSV.cpp
Go to the documentation of this file.
1 //============================================================================
2 // Name : Transform_TimeCSV.cpp
3 // Author : michael
4 // Version :
5 // Copyright : Your copyright notice
6 // Description : main C++, Ansi-style
7 //============================================================================
8 
9 #include <iostream>
10 #include <cstdlib>
11 
12 #include "Stock.h"
13 
14 using namespace std;
15 
16 const std::string path="/home/michael/www/www.my_portfolio_test.org/data";
17 
18 //entry expected: symbol timescale
19 int main(int argc, char* argv[]) {
20 
21  std::string symbol,tmp_str_time;
22  TimeScale timescale;
23  int tmp_timescale;
24 
25  if (argc != 3)
26  {
27  cout << "Error need 2 arguments: symbol timescale" << endl;
28  return 1;
29  }
30 
31  symbol.assign(argv[1]);
32  //symbol = path + symbol;
33  Stock * stock=new Stock(symbol,symbol,".");
34 
35  //case arg 2 is a string
36  tmp_str_time.assign(argv[2]);
37 
38  if (argc != 3)
39  {
40  cout << "Error need 2 arguments: symbol timescale" << endl;
41  return 1;
42  }
43 
44  // atoi only for C, keep argv[2]
45  if ( (tmp_timescale=atoi(argv[2])) != 0 )
46  timescale = (TimeScale) tmp_timescale;
47  // use of if, switch not possible (execpt more complex enum timescale)
48  else {
49  //std::cout << "argv2 is not an integer " << std::endl;
50  if ( tmp_str_time == "DAY" ) {timescale= DAY;}
51  else if ( tmp_str_time == "WEEK" ) timescale= WEEK;
52  else if ( tmp_str_time == "MONTH" ) timescale= MONTH;
53  else if ( tmp_str_time == "H1" ) timescale= H1;
54  else if ( tmp_str_time == "M30" ) timescale= M30;
55  else if ( tmp_str_time == "TRIM" ) timescale= TRIM;
56  else if ( tmp_str_time == "M10" ) timescale= M10;
57  else if ( tmp_str_time == "YEAR" ) timescale= YEAR;
58  else if ( tmp_str_time == "M5" ) timescale= M5;
59  else { cout << "argument2 " << tmp_str_time << " Not known, exit" << endl; return 1;}
60  }
61 
62  /* cannot do this, need more complex trick
63  switch (tmp_str_time) {
64  case "WEEK":
65  timescale = WEEK;
66  break;
67  case "MONTH":
68  timescale = MONTH;
69  break;
70  default:
71  std::cout << "Default exit" << std::endl;
72  return 1;
73  }
74  */
75  cout << "Stock " << symbol << "Timescale " << timescale << endl;
76 
77  //Make all test and load inside Stock, load in map, do not write
78  stock->Transform_TimeScale(timescale);
79  stock->PrintMap();
80 
81  //by default write in tmp
82  stock->WriteCSV(timescale);
83 
84  return 0;
85 }
Define the class Stock to deal with an unique stock: DJ, IBM...
Main class to deal with one stock.
Definition: Stock.h:56
int Transform_TimeScale(const ETime &new_tmscl)
Transform history values dcsv or DAY to M5,M10..H1 or WEEK, MONTH..YEAR.
Definition: Stock.cpp:273
void WriteCSV(const ETime tmscl, bool opt_tmp=false) const
Write historical data into files.
Definition: Stock.cpp:1247
int main(int argc, char *argv[])
const std::string path