int AfxRefreshStockContainerMinute( CStockContainer & container, LONG lStockType, int nSecondsToRead ) { container.Lock(); time_t tmTradeLatest = -1; int nCount = 0; for( int i=0; i<container.GetSize(); i++ ) { CStockInfo & info = container.ElementAt(i); if( info.GetType() != lStockType ) continue; CStock stock; stock.SetStockInfo( &info ); stock.SetDatabase( &AfxGetDB() ); AfxGetDB().LoadMinute( &stock ); info.m_minute.RemoveAll(); CMinute & minstock = stock.GetMinute(); if( -1 == tmTradeLatest && stock.GetMinute().GetSize() > 0 ) tmTradeLatest = CSPTime::GetTimeTradeLatest( minstock[0].m_time ); for( int i=0; i<minstock.GetSize(); i++ ) { if( -1 == nSecondsToRead || tmTradeLatest-minstock[i].m_time<nSecondsToRead ) info.m_minute.Add( minstock[i] ); } nCount ++; } container.UnLock(); return nCount; }
BOOL CSetKDataDlg::DeleteKData( CString strStockCode ) { if( strStockCode.GetLength() <= 0 ) return FALSE; UpdateData( ); if( m_tmDate.GetTime() == -1 ) return FALSE; CStockInfo info; CStock stock; if( !info.SetStockCode( CStock::marketUnknown, strStockCode ) ) return FALSE; stock.SetStockInfo( &info ); int nKType = m_comboKType.GetSelect(); AfxPrepareStockData( &AfxGetDB(), stock, nKType, CKData::formatOriginal, CKData::mdtypeClose, FALSE, TRUE ); CKData & kdata = stock.GetKData(nKType); CSPTime sptime = m_tmDate.GetTime(); int nIndex = kdata.GetIndexByDate( sptime.ToStockTime(CKData::IsDayOrMin(kdata.GetKType())) ); if( nIndex >= 0 && nIndex < kdata.GetSize() ) { kdata.RemoveAt(nIndex); AfxGetDB().InstallKData( kdata, TRUE ); return TRUE; } return FALSE; }
int CStock::MergeBaseText( CStock &stock ) { if( GetBaseTextLength() > 0 ) return GetBaseTextLength(); if( stock.GetBaseTextLength() > 0 ) { if( AllocBaseTextMem( stock.GetBaseTextLength() ) ) strncpy( GetBaseTextPtr(), stock.GetBaseTextPtr(), stock.GetBaseTextLength() ); return stock.GetBaseTextLength(); } return 0; }
void CSetKDataDlg::LoadKData( CString strStockCode ) { if( strStockCode.GetLength() <= 0 ) return; UpdateData(); m_strOpen.Empty(); m_strHigh.Empty(); m_strLow.Empty(); m_strClose.Empty(); m_dwVolume = 0; m_dwAmount = 0; if( m_tmDate.GetTime() == -1 ) { UpdateData( FALSE ); return; } CStockInfo info; CStock stock; if( !info.SetStockCode( CStock::marketUnknown, strStockCode ) ) return; stock.SetStockInfo( &info ); int nKType = m_comboKType.GetSelect(); AfxPrepareStockData( &AfxGetDB(), stock, nKType, CKData::formatOriginal, CKData::mdtypeClose, FALSE, TRUE ); CKData & kdata = stock.GetKData(nKType); // 价格小数位数格式串 CString strPriceFmt; strPriceFmt.Format( "%%.%df", info.DigitBit() ); CSPTime sptime = m_tmDate.GetTime(); int nIndex = kdata.GetIndexByDate( sptime.ToStockTime(CKData::IsDayOrMin(kdata.GetKType())) ); if( nIndex >= 0 && nIndex < kdata.GetSize() ) { KDATA kd = kdata.ElementAt(nIndex); m_strOpen.Format( strPriceFmt, kd.m_fOpen ); m_strHigh.Format( strPriceFmt, kd.m_fHigh ); m_strLow.Format( strPriceFmt, kd.m_fLow ); m_strClose.Format( strPriceFmt, kd.m_fClose ); m_dwVolume = (DWORD)(kd.m_fVolume/100); m_dwAmount = (DWORD)(kd.m_fAmount/1000); } UpdateData( FALSE ); }
void CFortuneItView::OnFortuneitTest1() { CStock stk; if (m_dlgStk.DoModal() == IDOK) { stk.Requery( m_dlgStk.m_strMarket + m_dlgStk.m_strLable, m_dlgStk.m_Time, m_dlgStk.m_Cycle, true, 10 ); } }
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 ); }
CStock & AfxGetStockMain( DWORD dwMarket ) { static CStock g_stockMain; if( !g_stockMain.GetStockInfo().IsValidStock() ) g_stockMain.SetStockCode( CStock::marketSHSE, STKLIB_CODE_MAIN ); if( CStock::marketSHSE == dwMarket ) return g_stockMain; else if( CStock::marketSZSE == dwMarket ) { static CStock g_stockMain2; if( !g_stockMain2.GetStockInfo().IsValidStock() ) g_stockMain2.SetStockCode( CStock::marketSZSE, STKLIB_CODE_MAINSZN ); return g_stockMain2; } else if( CStock::marketCYSE == dwMarket ) return g_stockMain; else if( CStock::marketCHNA == dwMarket ) return g_stockMain; else if( CStock::marketHKEX == dwMarket ) return g_stockMain; else if( CStock::marketTBSE == dwMarket ) return g_stockMain; else if( CStock::marketTKSE == dwMarket ) return g_stockMain; else if( CStock::marketLSE == dwMarket ) return g_stockMain; else if( CStock::marketFLKFSE == dwMarket ) return g_stockMain; else if( CStock::marketNYSE == dwMarket ) return g_stockMain; else if( CStock::marketNASDAQ == dwMarket ) return g_stockMain; else return g_stockMain; }
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; }
int CStock::MergeDRData( CStock &stock ) { if( GetDRData().GetSize() < stock.GetDRData().GetSize() ) GetDRData().Copy( stock.GetDRData() ); return GetDRData().GetSize(); }
void CFortuneItView::OnFortuneitTest2() { CStock stk; stk.Requery(_T("SZ000002"), CTimePair(COleDateTime(2007, 1, 1, 0, 0, 0), COleDateTime(2007, 5, 31, 23, 59, 59)), STKCYCLE::DAY); }
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; }
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; }