-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
96 lines (83 loc) · 2.23 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <QCoreApplication>
#include <QFile>
#include <QDebug>
#include "stock.h"
QList<Stock> initStockData(QFile &file);
QList<Stock> findMaximas(QList<Stock> &stockData);
QList<Stock> findMinimas(QList<Stock> &stockData);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFile file("C:/Users/ojas/qt-projects/CupWithHandle/msft-meta.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
qDebug() << "File Not Found";
QList<Stock> stockData;
stockData = initStockData(file);
for(Stock stock : stockData)
{
// stock.print();
}
QList<Stock> maximas;
maximas = findMaximas(stockData);
for(Stock stock : maximas) stock.print();
QList<Stock> minimas;
minimas = findMinimas(stockData);
for(Stock stock : minimas) stock.print();
return a.exec();
}
QList<Stock> findMinimas(QList<Stock> &stockData)
{
QList<Stock> minimas;
int i = 0;
qDebug() << "MINIMAS";
while(i < stockData.size()-1)
{
if(stockData.at(i).close <= stockData.at(i+1).close)
{
qDebug() << i;
minimas.append(stockData.at(i));
}
i++;
}
return minimas;
}
QList<Stock> findMaximas(QList<Stock> &stockData)
{
QList<Stock> maximas;
int i = 0;
qDebug() << "MAXIMAS";
while(i < stockData.size()-1)
{
if(stockData.at(i).close <= stockData.at(i+1).close)
{
qDebug() << i+1;
maximas.append(stockData.at(i+1));
}
i++;
}
return maximas;
}
QList<Stock> initStockData(QFile &file)
{
Stock s;
QList<Stock> stockData;
QTextStream in(&file);
QString line;
QStringList splitline;
while (!in.atEnd())
{
line = in.readLine();
splitline = line.split(",");
s.ticker = splitline.at(0);
s.datetime = QDateTime::fromString(splitline.at(1),"dd-MMM-yyyy");
s.timestamp = s.datetime.toTime_t();
s.open = splitline.at(2).toFloat();
s.high = splitline.at(3).toFloat();
s.low = splitline.at(4).toFloat();
s.close = splitline.at(5).toFloat();
s.volume = splitline.at(6).toInt();
stockData.append(s);
s.init();
}
return stockData;
}