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);
vector<data> dataList;
string line;
char *token = nullptr;
int index;
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(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 << 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>