行情数据处理为分钟数据(包含开盘价、最高价、最低价、收盘价)

#include <iostream>
#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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值