stock_kline.cpp
来自「股票分析源代码」· C++ 代码 · 共 970 行 · 第 1/3 页
CPP
970 行
cout << "index_current : " << info.index_current << endl;
cout << "---------------------------------------------------------" << endl;
cout << "dist_highest_lowest : " << info.dist_highest_lowest << endl;
cout << "dist_highest_hc_lowest : " << info.dist_highest_hc_lowest << endl;
cout << "dist_highest_current : " << info.dist_highest_current << endl;
cout << "dist_hc_lowest_current : " << info.dist_hc_lowest_current << endl;
cout << "dist_lowest_current : " << info.dist_lowest_current << endl;
cout << "---------------------------------------------------------" << endl;
cout << "rate_highest_lowest : " << info.rate_highest_lowest << endl;
cout << "rate_highest_hc_lowest : " << info.rate_highest_hc_lowest << endl;
cout << "rate_highest_current : " << info.rate_highest_current << endl;
cout << "rate_hc_lowest_current : " << info.rate_hc_lowest_current << endl;
cout << "rate_lowest_current : " << info.rate_lowest_current << endl;
cout << "---------------------------------------------------------" << endl;
cout << "rate_highest_lowest_close : " << info.rate_highest_lowest_close << endl;
cout << "rate_highest_hc_lowest_close : " << info.rate_highest_hc_lowest_close << endl;
cout << "rate_highest_current_close : " << info.rate_highest_current_close << endl;
cout << "rate_hc_lowest_current_close : " << info.rate_hc_lowest_current_close << endl;
cout << "rate_lowest_current_close : " << info.rate_lowest_current_close << endl;
cout << "====================================================================" << endl;
}
void hbstock2::get_kline_wave_info(KLineWaveInfo& info,
const VectStockData& vect_data,
const unsigned int& len,
const bool& is_div,const float& div_rate,
const int& wave_field_width)
{
info.is_div = is_div;
info.div_rate = div_rate;
info.is_include_div_data = false;
info.wave_field_width = wave_field_width;
info.is_low_of_last_index = false;
unsigned int i_start = 0;
unsigned int i_end = vect_data.size();
if (len != 0 && len < i_end-1)
{
i_start = i_end - len ;
}
// init data
info.index_highest = i_start;
info.index_lowest = i_start;
float f_close_close_rate = 0;
KLineTop kline_top_low ;
KLineTop kline_top_high ;
kline_top_low.index = 0;
kline_top_low.is_high_point = false;
kline_top_high.index = 0;
kline_top_high.is_high_point = true;
float f_high_price = 0;
float f_low_price = 0;
//cout << "vect_data start : " << vect_data[i_start].date << endl;
unsigned int i_left = 0;
unsigned int i_right = 0;
bool is_low_point = false;
bool is_high_point = false;
unsigned int i_prev_low_index = 0;
unsigned int i_prev_high_index = 0;
for (unsigned int i=i_start+1;i<i_end;i++)
{
if (info.is_div)
{
f_close_close_rate = (vect_data[i].close_price-vect_data[i-1].close_price)*100/vect_data[i-1].close_price;
if (f_close_close_rate < div_rate)
{
info.is_include_div_data = true;
info.vect_div_data_index.push_back(i);
}
}
if (i <= i_start + wave_field_width)
{
i_left = 0;
} else
{
i_left = i - wave_field_width;
}
if (i + wave_field_width > i_end)
{
i_right = i_end;
} else
{
i_right = i + wave_field_width;
}
is_low_point = true;
// get low top
for (unsigned int j = i_left;j<i;j++)
{
// check low price
if (info.vect_top_index.size() > 0 &&
info.vect_top_index[info.vect_top_index.size()-1].is_high_point &&
j < info.vect_top_index[info.vect_top_index.size()-1].index)
{
if (info.vect_top_index[info.vect_top_index.size()-1].index > i_left &&
info.vect_top_index[info.vect_top_index.size()-1].index -i_left <= 2 )
{
continue;
}
}
if (vect_data[i].low_price > vect_data[j].low_price)
{
is_low_point = false;
break;
}
}
for (unsigned int j = i+1;j<i_right;j++)
{
// check low price
if (vect_data[i].low_price > vect_data[j].low_price)
{
is_low_point = false;
break;
}
}
if (is_low_point)
{
if (i_prev_low_index == 0 ||
(i_prev_low_index != 0 && i_prev_low_index + wave_field_width - 1 < i))
{
kline_top_low.index = i;
i_prev_low_index = i;
info.vect_top_index.push_back(kline_top_low);
}
}
// get high top
is_high_point = true;
for (unsigned int j = i_left;j<i;j++)
{
// check high price
if (info.vect_top_index.size() > 0 &&
!info.vect_top_index[info.vect_top_index.size()-1].is_high_point &&
j < info.vect_top_index[info.vect_top_index.size()-1].index)
{
if (info.vect_top_index[info.vect_top_index.size()-1].index > i_left &&
info.vect_top_index[info.vect_top_index.size()-1].index -i_left <= 2 )
{
continue;
}
}
if (vect_data[i].high_price < vect_data[j].high_price)
{
is_high_point = false;
break;
}
}
for (unsigned int j = i+1;j<i_right;j++)
{
// check high price
if (vect_data[i].high_price < vect_data[j].high_price)
{
is_high_point = false;
break;
}
}
/*
if (vect_data[i].date == "20050920")
{
cout << "is_high_point : " << is_high_point << endl;
cout << "wave_field_width : " << wave_field_width << endl;
cout << "i left date : " << vect_data[i_left].date << endl;
cout << "i right date : " << vect_data[i_right].date << endl;
}
*/
if (is_high_point)
{
if (i_prev_high_index == 0 || (i_prev_high_index != 0 && i_prev_high_index + wave_field_width - 1 < i))
{
i_prev_high_index = i;
kline_top_high.index = i;
info.vect_top_index.push_back(kline_top_high);
}
}
} //for (unsigned int i=i_start+1;i<i_end;i++)
if (vect_data.size() == 0)
{
return;
}
// get highest and lowest
f_high_price = 0;
f_low_price = 10000;
info.index_highest = info.vect_top_index[0].index;
info.index_lowest = info.vect_top_index[0].index;
for (unsigned int i=0;i<info.vect_top_index.size();i++)
{
if (info.vect_top_index[i].is_high_point &&
f_high_price < vect_data[info.vect_top_index[i].index].high_price)
{
f_high_price = vect_data[info.vect_top_index[i].index].high_price;
info.index_highest = info.vect_top_index[i].index;
}
if (!info.vect_top_index[i].is_high_point &&
f_low_price > vect_data[info.vect_top_index[i].index].low_price)
{
f_low_price = vect_data[info.vect_top_index[i].index].low_price;
info.index_lowest = info.vect_top_index[i].index;
}
}
if (!info.vect_top_index[info.vect_top_index.size()-1].is_high_point)
{
info.is_low_of_last_index = true;
}
}
void hbstock2::print_kline_wave_info(const KLineWaveInfo& info,
const VectStockData& vect_data)
{
cout << "====================================================================" << endl;
cout << "wave field width : " << info.wave_field_width << endl;
cout << "is div : " << info.is_div << endl;
cout << "div rate : " << info.div_rate << endl;
cout << "is include div data : " << info.is_include_div_data << endl;
cout << "---------------------------------------------------------" << endl;
cout << "highest index : " << info.index_highest << endl;
cout << "Highest date : " << vect_data[info.index_highest].day << endl;
cout << "lowest index : " << info.index_lowest << endl;
cout << "lowest date : " << vect_data[info.index_lowest].day << endl;
cout << "is low of last index : " << info.is_low_of_last_index << endl;
if (info.is_include_div_data)
{
cout << "---------------------------------------------------------" << endl;
for (unsigned int i=0;i<info.vect_div_data_index.size();i++)
{
cout << "Div index : " << info.vect_div_data_index[i] << endl;
cout << "Div date : " << vect_data[info.vect_div_data_index[i]].day << endl;
}
}
cout << "---------------------------------------------------------" << endl;
for (unsigned int i=0;i<info.vect_top_index.size();i++)
{
cout << "Top Point : " << (i+1) ;
cout << "\tIndex : " << info.vect_top_index[i].index ;
cout << "\tDate : " << vect_data[info.vect_top_index[i].index].day ;
cout << "\tType : " ;
if (info.vect_top_index[i].is_high_point)
{
cout << "High Point" ;
} else
{
cout << "Low Point" ;
}
cout << endl;
}
cout << "====================================================================" << endl;
}
void hbstock2::get_kline_convex_wave(KLineConvexWave& wave,
const KLineWaveInfo& info,
const VectStockData& vect_data)
{
memset(&wave,0,sizeof(wave));
wave.is_div = info.is_div;
wave.div_rate = info.div_rate;
wave.is_include_div_data = false;
wave.index_div = 0;
// check div
if (info.is_include_div_data)
{
for (unsigned int i=0;i<info.vect_div_data_index.size();i++)
{
if (info.vect_div_data_index[i] > info.index_lowest)
{
wave.is_include_div_data = true;
wave.index_div = info.vect_div_data_index[i];
break;
}
}
} //if (info.is_include_div_data)
// set is_convex
wave.is_convex = false;
if (info.index_highest > info.index_lowest && info.is_low_of_last_index)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?