行情數據處理爲分鐘數據(包含開盤價、最高價、最低價、收盤價)

#include
#include <fstream>
#include <iostream>
#include<string>
#include<boost/filesystem.hpp>
#include<boost/tokenizer.hpp>
#include<boost/typeof/typeof.hpp>
#include "acsy/util/acsyapplication.h"
using namespace std;
int main()
{
namespace fs = boost::filesystem;
std::string buf;
std::string time;
std::string op;
std::string cl;
double high;
double low;
int cnt = 0;
std::vector<std::string> vecBuf;
std::vector<std::string> vecDir;
std::vector<std::string> vecFil;
std::vector<std::string> vecFlo;
std::string rfloder = "H:\\data";
fs::recursive_directory_iterator end_iter;
for (fs::recursive_directory_iterator iter(rfloder); iter != end_iter; iter++)
{
if (fs::is_directory(*iter))
{
cout << *iter << endl;
vecDir.push_back(iter->path().string());
}
else
{
vecFlo.clear();
cout << *iter << endl;
std::string cont = iter->path().string();
vecFil.push_back(iter->path().string());
using namespace boost;
char_separator<char> sep("\\");
tokenizer<char_separator<char>> tok(cont, sep);
for (BOOST_AUTO(pos, tok.begin()); pos != tok.end(); ++pos)
{
vecFlo.push_back(*pos);
}
std::string filename = "h:\\" + vecFlo[3];
std::ifstream in(cont);
while (!in.eof())
{
cnt++;
getline(in, buf);
using namespace std;
using namespace boost; //分割buf裏面的字符,用逗號隔開.
char_separator<char> sep(","); //分割buf裏面的字符,用逗號隔開.
tokenizer<char_separator<char>> tok(buf, sep); //分割buf裏面的字符,用逗號隔開.
vecBuf.clear();
for (BOOST_AUTO(pos, tok.begin()); pos != tok.end(); ++pos) //分割buf裏面的字符,用逗號隔開.
{
// cout << *pos << "\n";
vecBuf.push_back(*pos);
}
if (buf.length() < 30)
{
break;
}
if (cnt > 1)
{
double high1 = std::stof(vecBuf[2]);
if (high1 > high)
{
high = high1; //取最高價
}
if (high1 < low)
{
low = high1; //取最低價
}
std::string time1 = vecBuf[1].substr(0, 5);
if (time1 != time)
{
cout << time << "," << op << "," << high << "," << low << "," << cl << endl;
string subs = acsy::util::strprintf("%s,%s,%f,%f,%s", time, op, high, low, cl);
namespace fs = boost::filesystem;


std::ifstream ifs(filename);
if (ifs)   //存在
{
std::ofstream fout(filename, std::ios::app);
fout << subs << endl;
fout.close();
}
else     //不存在
{
std::ofstream fout(filename);
fout << subs << endl;
}


cnt = 1;
}
cl = vecBuf[2];
}
if (cnt == 1)
{
op = vecBuf[2];
high = std::stof(vecBuf[2]);
low = std::stof(vecBuf[2]);
cl = vecBuf[2];
time = vecBuf[1].substr(0, 5);
}
}
}


}
return 0;
}
//sprintf(highc, "%d", high);
//highc = buf.substr(20, 10);
//lowc = buf.substr(20, 10);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章