Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We want to write two containers. One is to keep daily data and other one is to keep the first container type -- index (tickers) data.

This means that entire file will be saved line by line in first container -- each line representing an element in first container. For example, if a file has 10 lines, first container will have 10 elements. Second container will be used to keep containers of first container type. For example, if I have 4 index lines, my second container will contain 4 elements. This means that second container is a container of containers.
Double Top is a price formation pattern. It appears as two consecutive peaks of approximately the same price on a price-versus-time chart of a market. The two peaks are separated by a minimum in price, a valley. The price level of this minimum is called the neck line of the formation. The formation is completed and confirmed when the price falls below the neck line.

We have to do the following:
You are to open names.csv file, read a line and add .csv to make a filename. For example, qqq will be read from one of the lines in names.csv. sample data for names.csv is given below:

qqq msft aapl amzn

Once qqq.csv is filename string is created, you would make an attempt to locate qqq.csv file in …/Projects/final_project/data_files and read the data. Sample data from one of the csv file is given as follows:

Date,Adj Close,Volume
3/20/2017,129.719299,118404300
3/27/2017,131.457108,91838100
4/3/2017,131.049942,104686800
4/10/2017,129.490891,89035900
4/17/2017,131.635834,88364200
4/24/2017,135.041916,103641400
5/1/2017,136.5811,100949000
5/8/2017,137.633743,109176100
5/15/2017,136.879028,175959500
5/22/2017,140.235474,92869300
5/29/2017,142.459854,110879400

Need to read the data into STL container line by line. Each line representing each element in your first container. When creating your own type, say Data, with string, double, and long to hold the daily data. Thus, you need to define STL container as, say vector v. You need to overload given operators for type Data. The operators a
-- write in the entire line to a file -- read in the entire line from a file >, < -- comparison operators based on date == -- equal operator to test whether prices are same for two data objects [ ] operator to access your container and copy constructor for this above type.
Now, create a container to that have vector of type Data. Next, calculate if double top has occurred based on adj close column. Write this to new file calling qqq-final.csv including where exactly top double has occurred. Keep track of filenames where double top has occurred. Once done with all file processing, write your results into status.csv in "symbol,YES/NO" -- 1. YES representing double top created in this file. 2. NO for otherwise. We need to make sure to keep daily data in Data container and keep all the files in DataContainer.

Below is what I have done so far, could use some help.

What I have tried:

using namespace std;

Class Data {

private:
string date;
long long volume;
double close;
public:

virtual Data::~Data() {};
Data() {};
Data(string stockInfo);


void setDate(const string dates);

void setVolume(const long vol);

void setClose(const double _close);

string getDate() const;

long getVolume() const;

double getClose() const;

bool operator <(const Data& d2);
bool operator >(const Data& d2);
bool operator ==(const Data& d2);
Data operator =(Data& right);

friend ostream& operator << (ostream&, const Data&);
friend istream& operator >> (istream&, Data&);


};
Data::Data(string filePath) {
ifstream fileNames(filePath);

//make vector
vector<data> dataList;
string line;
char *token = nullptr;
int index;

//inputing file into vector
while (!fileNames.eof()) {

    getline(fileNames, line);
    stringstream dataStream(line);
    string cell;

    while (getline(dataStream, cell, ',')) {
        Data d(line);
        dataList.push_back(d);
    }

    dataStream >> date >> close >> volume;

    cout << dataList.size() << " elements in container" << endl;
 }
  fileNames.close();

 //Sort data from lowest close to hightest
 sort(dataList.begin(), dataList.end(), [](Data &d1, Data &d2) {
    return d1.getClose() > d2.getClose();
 });

 };


 void Data::setDate(const string dates) {
 date = dates;
 }

 void Data::setVolume(const long vol) {
 volume = vol;
 }

 void Data::setClose(const double _close) {
 close = _close;
 }

 string Data::getDate() const {
 return(date);
 }

 long Data::getVolume() const {
 return(volume);
 }

 double Data::getClose() const {
 return (close);
 }

 bool Data::operator <(const Data& d2) {
 if (date < d2.date)
    return true;
 return false;
}

 bool Data::operator >(const Data& d2) {
 if (date > d2.date)
    return true;
 return false;
 }

 bool Data::operator ==(const Data& d2) {
   if (close == d2.close)
    return true;
 return false;
 }

 Data Data::operator =(Data& right) {
 if (this != &right) {
    date = right.date;
 }
 return *this;
 }

 ostream& operator << (ostream& stream, const Data& obj) {
 stream << "Date: " << obj.date << " Closing Cost: " << obj.close << " 
 Volume: " << obj.volume << endl;
 return stream;
 }

 istream& operator >> (istream& strm, Data& obj)
 {
 cout << "Enter date: " << " ";
 strm >> obj.date;
 cout << endl;

 cout << "Enter closeing cost: " << " ";
 strm >> obj.close;
 cout << endl;

 cout << "Enter volume: " << " ";
 strm >> obj.volume;
 cout << endl;

 return strm;}

 class dataContainer : Data {
 public:

 virtual ~dataContainer() {};
 dataContainer() {};
 dataContainer(vector<data>);
 Data getDoubleTop();



 private:
 vector<data>vData;

 }; 

 string getFilename(string);

 int main() {

 string filename = "names.csv";
 Data data1(filename);
 vector<data> vd1;
 dataContainer dC1(vd1);
 //cout << "\n" << dC1.getDoubleTop();
 cout << vd1.size();




 system("Pause");
 return 0;}

string getFilename(string fileName) {

ofstream namesFile; 

namesFile.open(fileName);

namesFile << "QQQ\n";

namesFile << "MSFT\n";

namesFile << "APPL\n";

namesFile << "AMZN\n";

 namesFile.close();

 string dat;
 return dat;
 }</data></data></data></data>
Posted
Updated 30-Apr-18 7:29am
Comments
Richard MacCutchan 30-Apr-18 4:15am    
"could use some help."

Then please edit your question and explain exactly what help you need. We cannot guess what you are having trouble with.

1 solution

You must better understand the functions of the used classes. With getline you read to your data format delimeter. So repeat the call 3 times, but the last with a newline.
C++
getline(dataStream, date, ',');
getline(dataStream, close, ',');
getline(dataStream, volume, '\n');
//Than you have the parts to construct your object. 
Data d(data,close,volume);
It would make sense to store some index to syncronize the data between the file. Normally it isnt a good idea to split data which belongs together.

Learn to use the debugger and step into your code to learn coding. A good tutorials is Learn C++ and in chapter 1.11 is the debugging process explained.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900