-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdditionalInformation.cpp
More file actions
109 lines (90 loc) · 2.87 KB
/
AdditionalInformation.cpp
File metadata and controls
109 lines (90 loc) · 2.87 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "AdditionalInformation.h"
#include "FinanceDataLoader.h"
#include "CSVParser.h"
using namespace quantserver;
AdditionalInformation::AdditionalInformation(void)
{
yahooDataQueryElements.clear();
yahooDataQueryElements["symbol"] = std::string("s") ;
yahooDataQueryElements["name"] = std::string("n") ;
yahooDataQueryElements["dividendYield"] = std::string("y") ;
yahooDataQueryElements["dividendPerShare"] = std::string("d") ;
yahooDataQueryElements["eps"] = std::string("e") ;
yahooDataQueryElements["epsEstimate"] = std::string("e7") ;
yahooDataQueryElements["epsEstimateNextYr"] = std::string("e8") ;
yahooDataQueryElements["bookValue"] = std::string("b4") ;
yahooDataQueryElements["marketCap"] = std::string("j1") ;
yahooDataQueryElements["ebitda"] = std::string("j4") ;
yahooDataQueryElements["P/E_Ratio"] = std::string("r") ;
yahooDataQueryElements["targetPrice"] = std::string("t4") ;
yahooDataQueryElements["outstandingShares"] = std::string("f6") ;
yahooDataQueryElements["PEG_Ratio"] = std::string("r5") ;
yahooDataQueryElements["PS_Ratio"] = std::string("p5") ;
yahooDataQueryElements["bid"] = std::string("b2") ;
yahooDataQueryElements["ask"] = std::string("b3") ;
yahooDataQueryElements["error"] = std::string("e1") ;
}
AdditionalInformation::~AdditionalInformation(void)
{
}
std::string AdditionalInformation::constructYahooMetadataUrl(std::vector<std::string>& symbols)
{
std::string str("http://finance.yahoo.com/d/quotes.csv?s=");
//http://finance.yahoo.com/d/quotes.csv?s=XOM+EK+JNJ+MSFT&f=snd1t1l1ohgvwdyr
int i = 0 ;
for(i = 0 ; i < symbols.size() ; i++ )
{
str.append(symbols[i]);
if(i < symbols.size() -1 )
{
str.append(std::string("+"));
}
}
str.append(std::string("&f="));
PtrStringVector ptrStringVector = StockMetadata::getRequiredItems();
for(int i = 0 ; i < ptrStringVector->size() ; i++ )
{
str.append(yahooDataQueryElements[
ptrStringVector->at(i)
]);
}
return str;
}
bool AdditionalInformation::isError(PtrStringVector& data)
{
if(data->at(1).size() > 5)
{
return true;
}
else
{
return false;
}
}
ptr_stockMetaDataPtrCollection AdditionalInformation::getStockMetaData(std::vector<std::string>& symbols)
{
std::string url = constructYahooMetadataUrl(symbols);
FinanceDataLoader dataLoader(url,true);
std::string& localFile = dataLoader.getLocalReadable();
CSVParser csvParser(localFile, 1 , false) ;
ptr_stockMetaDataPtrCollection metaCollection( new vec_metadata_ptr() ) ;
int s_read= 0 ;
for( int i = 0 ; i < csvParser.getNumberOfLines() ; i++ )
{
PtrStringVector sv = csvParser.getDataAt(i) ;
if(sv->size() > 1 )
{
std::string& readSymbol = sv->at(0);
if(readSymbol == symbols[s_read] )
{
if(!isError(sv))
{
ptr_stockMetaData metaData( new StockMetadata(readSymbol , sv) ) ;
metaCollection->push_back(metaData) ;
}
s_read++ ;
}
}
}
return metaCollection;
}