Пример #1
0
CMqlx::CMqlx(CString strIniFileName)
{
	cout<<"This is CMqlx Construction Fuction."<<endl;
	cout<<"IniFileName = "<<strIniFileName<<endl;
	int TOTALCONTRACT ;

		// 读入初始化文件的数据

	FILE *fpIni=fopen(strIniFileName,"rt") ;
	if (fpIni==NULL){
		cout<<"Open Ini file "<<strIniFileName<<" Error."<<endl;
		return ;
	}

	char buf[128] ;
	CString strContractFile ;
	typedef pair <CString,CPtrArray*> StrPtr_Pair;

	fscanf ( fpIni,"%s",buf ) ;
	m_strDestFile = CString("\\txtday\\")+buf ;
	fscanf ( fpIni,"%s",buf ) ;
	m_strCvtFile = buf ;

	fscanf ( fpIni,"%d", &TOTALCONTRACT) ;
	cout << "TOTALCONTRACT = "<<TOTALCONTRACT<<endl ;

	map<CString,CPtrArray*> &cb = CodeBook ;

	for ( int i=0; i<TOTALCONTRACT; i++ )
	{
		fscanf ( fpIni,"%s",buf ) ;
        strContractFile =  CString("\\txtday\\")+buf+".txt" ;
		CPtrArray *pAQ1= new CPtrArray() ;
		ReadQuotes(strContractFile,*pAQ1);
		cb.insert(StrPtr_Pair(buf,pAQ1)) ;
		cout <<"合约 = "<<buf<<endl ;
	}

	ReadCvtDate(m_strCvtFile,m_pCvt);

	return ;
}
Пример #2
0
int main(int argc, char *argv[] ) {
    //std::cout << "Enter name of input file from yahoo.com: ";
    std::string strInputFile = "/home/shiva/Downloads/s1.csv";
    //std::cin >> strInputFile;
    Quotes quotes = ReadQuotes( strInputFile );
    //std::copy( quotes.rbegin(), quotes.rend(), std::ostream_iterator< Quote >( std::cout, "\n" ) );
    Quote minVal{ "Initial", std::numeric_limits< double >::max() }, maxVal{ "Initial", std::numeric_limits< double >::min() };
    BestPrice bestPrice = std::make_pair( maxVal, minVal );
    std::for_each( quotes.begin(), quotes.end(), [ &minVal, &maxVal, &bestPrice ] ( const Quote &q ) {
        if( q.dPrice < minVal.dPrice )
            minVal = Quote( q.strDate, q.dPrice );

        std::cout << "minValue " << minVal << std::endl;

        if( abs( bestPrice.first.dPrice ) - abs( bestPrice.second.dPrice ) < abs( maxVal.dPrice ) - abs( minVal.dPrice ) )
            bestPrice = std::make_pair( maxVal, minVal );

        std::cout << "bestPrice1 " << bestPrice.first << " => " << bestPrice.second << std::endl;

        if( q.dPrice > maxVal.dPrice ) {
            maxVal = Quote( q.strDate, q.dPrice );
            minVal = Quote( q.strDate, q.dPrice );
        }

        std::cout << "minValue " << minVal << std::endl;
        std::cout << "maxValue " << maxVal << std::endl;

        if( abs( bestPrice.first.dPrice ) - abs( bestPrice.second.dPrice ) < abs( maxVal.dPrice ) - abs( minVal.dPrice ) )
            bestPrice = std::make_pair( maxVal, minVal );

        std::cout << "bestPrice2 " << bestPrice.first << " => " << bestPrice.second << std::endl;
    } );

    std::cout << "Buy at " << bestPrice.second << std::endl;
    std::cout << "Sell at " << bestPrice.first << std::endl;
    return 0;
}