#include #include "../../shared/TwoDLookup.h" #include "../../shared/MiscSupport.h" bool hasEnding (std::string const &fullString, std::string const &ending) { if (fullString.length() >= ending.length()) { return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending)); } else { return false; } } int main() { const long int RARE = std::numeric_limits< long int >::min(); TwoDArray input; TwoDArray earningsCSV; TwoDArray factsetFundamentalsCSV; TwoDArray factsetProfilesCSV; int total_line_breaks = 0; earningsCSV.add("symbol","",""); earningsCSV.add("prev date","",""); earningsCSV.add("prev time","",""); earningsCSV.add("next date","",""); earningsCSV.add("next time","",""); input.loadFromCSV("factset.csv"); for(std::string s : input.getRowHeaders()) { std::string ticker = input.get("Company Ticker", s); if (hasEnding(ticker, "-US")) { //std::cout<< s << " " << ticker << " " << "\n"; ticker.erase(ticker.size()-3, 3); // earnings std::string prevDate = input.get("Previous Earnings Date", s); std::string prevTime = input.get("Previous Earnings Time", s); std::string nextDate = input.get("Next Earnings Date", s); std::string nextTime = input.get("Next Earnings Time", s); if (prevDate.compare("@NA") != 0) { earningsCSV.add("prev date", ticker, prevDate); earningsCSV.add("prev time", ticker, prevTime); } if (nextDate.compare("@NA") != 0) { earningsCSV.add("next date", ticker, nextDate); earningsCSV.add("next time", ticker, nextTime); } // fundamentals for RequestHistory.exe double epsGrowthAnnual = strtodDefault(input.get("Estimated Annual EPS Growth", s), RARE); if (epsGrowthAnnual != RARE) factsetFundamentalsCSV.add("EstimatedAnnualEarningsGrowth", ticker, dtoa(epsGrowthAnnual / 100.0)); double epsGrowthQuarterly = strtodDefault(input.get("Estimated Quarterly EPS Growth", s), RARE); if (epsGrowthQuarterly != RARE) factsetFundamentalsCSV.add("EstimatedQuarterlyEarningsGrowth", ticker, dtoa(epsGrowthQuarterly / 100.0)); double eps = strtodDefault(input.get("Last Quarter's EPS Actual", s), RARE); if (eps != RARE) factsetFundamentalsCSV.add("EPSLatest12Month", ticker, dtoa(eps)); double quarterlyEarningsGrowth = strtodDefault(input.get("Quarterly Earnings Growth", s), RARE); if (quarterlyEarningsGrowth != RARE) factsetFundamentalsCSV.add("QtrlyEarningsGrowth", ticker, dtoa(quarterlyEarningsGrowth / 100.0)); double quarterlyRevenueGrowth = strtodDefault(input.get("Quarterly Revenue Growth", s), RARE); if (quarterlyRevenueGrowth != RARE) factsetFundamentalsCSV.add("QtrlyRevenueGrowth", ticker, dtoa(quarterlyRevenueGrowth / 100.0)); double heldByInsiders = strtodDefault(input.get("% Held by Insiders", s), RARE); if (heldByInsiders != RARE) factsetFundamentalsCSV.add("PercentHeldByInsiders", ticker, dtoa(heldByInsiders / 100.0)); double heldByInstitutions = strtodDefault(input.get("% Held by Instituitons", s), RARE); if (heldByInstitutions != RARE) factsetFundamentalsCSV.add("PercentHeldByInstitutions", ticker, dtoa(heldByInstitutions / 100.0)); double pegRatio = strtodDefault(input.get("PEG Ratio", s), RARE); if (pegRatio != RARE) factsetFundamentalsCSV.add("PEGRatio", ticker, dtoa(pegRatio)); double shortGrowth = strtodDefault(input.get("Short Growth", s), RARE); if (shortGrowth != RARE) factsetFundamentalsCSV.add("ShortGrowth", ticker, dtoa(shortGrowth / 100.0)); double shortFloat = strtodDefault(input.get("Short Float", s), RARE); if ((shortFloat != RARE) && (shortFloat != 0.0)) factsetFundamentalsCSV.add("ShortPercentOfFloat", ticker, dtoa(shortFloat / 100.0)); double daysToCover = strtodDefault(input.get("Days to cover", s), RARE); if (daysToCover != RARE) factsetFundamentalsCSV.add("DaysToCover", ticker, dtoa(daysToCover)); double dividend = strtodDefault(input.get("Dividend", s), RARE); if (dividend != RARE) factsetFundamentalsCSV.add("Dividend", ticker, dtoa(dividend)); double beta = strtodDefault(input.get("Beta (3 Year)", s), RARE); if (beta != RARE) factsetFundamentalsCSV.add("Beta", ticker, dtoa(beta)); double revenue = strtodDefault(input.get("Revenue", s), RARE); if (revenue != RARE) factsetFundamentalsCSV.add("Revenue", ticker, lltoa(revenue * 1000000LL)); double interestIncome = strtodDefault(input.get("Interest Income", s), RARE); if (interestIncome != RARE) factsetFundamentalsCSV.add("InterestIncome", ticker, dtoa(interestIncome)); long long flt = strtollDefault(input.get("Float", s), 0); if (flt != 0) factsetFundamentalsCSV.add("Float", ticker, lltoa(flt)); double enterpriseValue = strtodDefault(input.get("Enterprise Value", s), RARE); if (enterpriseValue != RARE) factsetFundamentalsCSV.add("EnterpriseValue", ticker, lltoa(enterpriseValue * 1000000LL)); double debt = strtodDefault(input.get("Current debt", s), RARE); if (debt != RARE) factsetFundamentalsCSV.add("Debt_Yahoo", ticker, lltoa(debt * 1000000LL)); double cash = strtodDefault(input.get("Cash", s), RARE); if (cash != RARE) factsetFundamentalsCSV.add("TotalCash", ticker, lltoa(cash * 1000000LL)); double sharesOutstanding = strtodDefault(input.get("Shares outstanding", s), RARE); if (sharesOutstanding != RARE) factsetFundamentalsCSV.add("SharesOutstanding", ticker, lltoa(sharesOutstanding * 1000)); double income = strtodDefault(input.get("Net Income", s), RARE); if (income != RARE) factsetFundamentalsCSV.add("Income", ticker, itoa(lround(income * 1000))); double assets = strtodDefault(input.get("Assets", s), RARE); if (income != RARE) factsetFundamentalsCSV.add("Assets", ticker, itoa(lround(assets * 1000))); std::string country = input.get("Country", s); factsetProfilesCSV.add("Country", ticker, country); std::string website = input.get("Website", s); if (website != "NA") factsetProfilesCSV.add("Website", ticker, website); std::string profileSummary = input.get("Long Business Description", s); if (!profileSummary.empty()) { std::string::size_type pos = 0; while ( ( pos = profileSummary.find ("\r\n",pos) ) != std::string::npos ) { profileSummary.replace(pos, 2, " "); total_line_breaks++; } pos = 0; while ( ( pos = profileSummary.find ("\n",pos) ) != std::string::npos ) { profileSummary.replace(pos, 1, " "); total_line_breaks++; } factsetProfilesCSV.add("Profile", ticker, profileSummary); } } } if (total_line_breaks > 0) std::cout << "Total line breaks in profiles: " << total_line_breaks << std::endl; earningsCSV.writeToCSV("earnings.csv"); factsetFundamentalsCSV.writeToCSV("FundamentalsFactset.csv"); factsetProfilesCSV.writeToCSV("ProfilesFactset.csv"); }