BOOL AfxPrepareStockData( CStDatabase * pDatabase, CStock &stock, int nKType, int nKFormat, int nMaindataType, BOOL bFullFill, BOOL bReload ) { CStockInfo info; if( !AfxGetStockContainer().GetStockInfo( stock.GetStockCode(), &info ) ) info = stock.GetStockInfo( ); stock.SetDatabase( pDatabase ); stock.PrepareData( CStock::dataK, CKData::ktypeDay, bReload ); stock.PrepareData( CStock::dataK, CKData::ktypeMin5, bReload ); stock.PrepareData( CStock::dataDR, CKData::ktypeDay, bReload ); if( bReload || stock.GetKDataDay().GetCurFormat() == CKData::formatOriginal ) stock.GetKDataDay().MergeKData( &(info.m_kdata) ); CKData & kday = stock.GetKData(CKData::ktypeDay); CKData & kdata = stock.GetKData( nKType ); kdata.SetDRData( stock.GetDRData() ); kday.SetDRData( stock.GetDRData() ); if( bFullFill ) kday.FullFillKData( AfxGetStockMain().GetKDataDay(), FALSE ); kday.ChangeCurFormat( nKFormat, AfxGetProfile().GetAutoResumeDRBegin(), AfxGetProfile().GetAutoResumeDRLimit() ); if( CKData::ktypeWeek == nKType || CKData::ktypeMonth == nKType ) { // 周线和月线不能ChangeCurFormat(...) if( CKData::formatOriginal == nKFormat ) stock.PrepareData( CStock::dataK, nKType, bReload ); else stock.ExtractKData( nKType, TRUE ); } else if( CKData::ktypeDay != nKType ) { stock.PrepareData( CStock::dataK, nKType, bReload ); kdata.ChangeCurFormat( nKFormat, AfxGetProfile().GetAutoResumeDRBegin(), AfxGetProfile().GetAutoResumeDRLimit() ); } kdata.SetMaindataType( nMaindataType ); return TRUE; }
int CStock::MergeKData( CStock &stock, int period ) { CKData * pkdata = NULL; CKData * pkdata2 = NULL; switch( period ) { case CKData::ktypeMonth: pkdata = &(GetKDataMonth()); pkdata2 = &(stock.GetKDataMonth()); break; case CKData::ktypeWeek: pkdata = &(GetKDataWeek()); pkdata2 = &(stock.GetKDataWeek()); break; case CKData::ktypeDay: pkdata = &(GetKDataDay()); pkdata2 = &(stock.GetKDataDay()); break; case CKData::ktypeMin60: pkdata = &(GetKDataMin60()); pkdata2 = &(stock.GetKDataMin60()); break; case CKData::ktypeMin30: pkdata = &(GetKDataMin30()); pkdata2 = &(stock.GetKDataMin30()); break; case CKData::ktypeMin15: pkdata = &(GetKDataMin15()); pkdata2 = &(stock.GetKDataMin15()); break; case CKData::ktypeMin5: pkdata = &(GetKDataMin5()); pkdata2 = &(stock.GetKDataMin5()); break; case CKData::ktypeMin1: pkdata = &(GetKDataMin1()); pkdata2 = &(stock.GetKDataMin1()); break; default: SP_ASSERT( FALSE ); return 0; } return pkdata->MergeKData( pkdata2 ); }
BOOL AfxReloadStock( CStock & stock ) { CStockInfo info = stock.GetStockInfo(); // Reload AfxGetStockMain() AfxGetStockContainer().GetStockInfo( info.GetStockCode(), &info ); stock.Clear( ); stock.SetStockInfo( &info ); stock.SetDatabase( &AfxGetDB() ); stock.PrepareData( CStock::dataK, CKData::ktypeDay ); // Merge New stock.GetKDataDay().MergeKData( &(info.m_kdata) ); stock.PrepareData( CStock::dataK, CKData::ktypeWeek ); stock.PrepareData( CStock::dataK, CKData::ktypeMonth ); stock.PrepareData( CStock::dataK, CKData::ktypeMin5 ); stock.PrepareData( CStock::dataK, CKData::ktypeMin15 ); stock.PrepareData( CStock::dataK, CKData::ktypeMin30 ); stock.PrepareData( CStock::dataK, CKData::ktypeMin60 ); return TRUE; }
UINT AfxRecalculateYield( int nDays, BOOL bReport ) { // 计算市场年平均收益率 double market_yield_average = 0.0, market_yield_d = 0.0; double market_dayyield_average = 0.0, market_dayyield_d = 0.0; CKData & kdayMain = AfxGetStockMain().GetKDataDay(); if( kdayMain.GetSize() <= nDays ) { if( bReport ) AfxMessageBox( IDS_RECALYIELD_NOSZZS, MB_OK | MB_ICONINFORMATION ); return 0; } BOOL bmarket_yield_ok = CalculateYieldYear( kdayMain, &market_yield_average, &market_yield_d, nDays ); BOOL bmarket_dayyield_ok = CalculateYieldDay( kdayMain, &market_dayyield_average, &market_dayyield_d, nDays ); if( !bmarket_yield_ok && !bmarket_dayyield_ok ) { if( bReport ) AfxMessageBox( IDS_RECALYIELD_NOSZZS, MB_OK | MB_ICONINFORMATION ); } // 开始生成结果数据 CStockContainer & container = AfxGetStockContainer(); int nCount = 0; // 等待对话框 CWaitDlg * pWait = NULL; if( bReport ) { pWait = new CWaitDlg( AfxGetMainWnd() ); pWait->SetProgressRange( 0, container.GetSize()-1 ); } for( int i=0; i<container.GetSize(); i++ ) { if( pWait ) { pWait->SetProgress( i ); if( pWait->WaitForCancel( ) ) break; } CStockInfo & info = container.ElementAt(i); LONG stocktype = info.GetType(); if( CStock::typeshIndex != stocktype && CStock::typeshA != stocktype && CStock::typeshB != stocktype && CStock::typeszIndex != stocktype && CStock::typeszA != stocktype && CStock::typeszB != stocktype ) continue; CStock stock; stock.SetStockInfo( &info ); AfxPrepareStockData(&AfxGetDB(),stock,CKData::ktypeDay,CKData::formatXDRup,CKData::mdtypeClose,TRUE,TRUE); CKData & kday = stock.GetKDataDay(); info.m_fYield_average = (float)STKLIB_DATA_INVALID; info.m_fYield_stddev = (float)STKLIB_DATA_INVALID; info.m_fBeite = (float)STKLIB_DATA_INVALID; double yield_average = 0., yield_d = 0., beite = 0. ; if( CalculateYieldYear( kday, &yield_average, &yield_d, nDays ) ) { info.m_fYield_average = (float)( 100. * yield_average ); info.m_fYield_stddev = (float)( 100. * yield_d ); if( bmarket_yield_ok && CalculateBeiteYear( kday, kdayMain, market_yield_average, market_yield_d, &beite, nDays ) ) info.m_fBeite = (float)( beite ); else if( bmarket_dayyield_ok && CalculateBeiteDay( kday, kdayMain, market_dayyield_average, market_dayyield_d, &beite, nDays ) ) info.m_fBeite = (float)( beite ); } else if( CalculateYieldDay( kday, &yield_average, &yield_d, nDays ) ) { info.m_fYield_average = (float)( 100. * (pow(1+yield_average,STKLIB_DAYS_INONEYEAR)-1) ); info.m_fYield_stddev = (float)( 100. * sqrt((double)STKLIB_DAYS_INONEYEAR) * yield_d ); if( bmarket_dayyield_ok && CalculateBeiteDay( kday, kdayMain, market_dayyield_average, market_dayyield_d, &beite, nDays ) ) info.m_fBeite = (float)( beite ); } nCount ++; } // 保存到硬盘文件 AfxGetDB().StoreBasetable( container ); // 关闭等待对话框和目标文件 if( pWait ) { pWait->DestroyWindow(); delete pWait; } return nCount; }