Stock.cpp
上传用户:zhanglf88
上传日期:2013-11-19
资源大小:6036k
文件大小:41k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. /*
  2. Cross Platform Core Code.
  3. Copyright(R) 2001-2002 Balang Software.
  4. All rights reserved.
  5. Using:
  6. class CStock;
  7. */
  8. #include "StdAfx.h"
  9. #include "../Include/Stock.h"
  10. #include "../Include/Database.h"
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #endif
  18. #ifndef _SP_ENABLE_INLINES
  19. #define _STOCK_INLINE
  20. #include "../Include/Stock.inl"
  21. #undef _STOCK_INLINE
  22. #endif //_SP_ENABLE_INLINES
  23. //////////////////////////////////////////////////////////////////////
  24. // class CStockInfo
  25. CStockInfo::CStockInfo()
  26. {
  27. Clear();
  28. }
  29. CStockInfo::CStockInfo(const CStockInfo &src)
  30. {
  31. Clear();
  32. *this = src;
  33. }
  34. void CStockInfo::Clear()
  35. {
  36. m_dwMarket = CStock::marketUnknown;
  37. memset(m_szCode, 0, sizeof(m_szCode));
  38. m_type = CStock::typeNone;
  39. memset(m_szName, 0, sizeof(m_szName));
  40. memset(m_szNameEnu, 0, sizeof(m_szNameEnu));
  41. memset(m_szShortname, 0, sizeof(m_szShortname));
  42. memset(m_szDomain, 0, sizeof(m_szDomain));
  43. memset(m_szProvince, 0, sizeof(m_szProvince));
  44. m_kdata.RemoveAll();
  45. m_kdata.SetKType(CKData::ktypeDay);
  46. m_basedata.RemoveAll();
  47. m_minute.RemoveAll();
  48. memset(&m_reportLatest, 0, sizeof(m_reportLatest));
  49. m_datetech = 0;
  50. m_fLast = 0;
  51. m_fOpen = 0;
  52. m_fHigh = 0;
  53. m_fLow = 0;
  54. m_fClose = 0;
  55. m_fVolume = 0;
  56. m_fAmount = 0;
  57. m_dwAdvance = 0;
  58. m_dwDecline = 0;
  59. memset(m_fBuyPrice, 0, sizeof(m_fBuyPrice));
  60. memset(m_fBuyVolume, 0, sizeof(m_fBuyVolume));
  61. memset(m_fSellPrice, 0, sizeof(m_fSellPrice));
  62. memset(m_fSellVolume, 0, sizeof(m_fSellVolume));
  63. // base data
  64. m_datebase = 0;
  65. m_reporttype = 0;
  66. m_fErate_dollar = (float)8.27;
  67. m_fErate_hkdollar = (float)1.06;
  68. m_fRatio_liquidity = 0;
  69. m_fRatio_quick = 0;
  70. m_fVelocity_receivables = 0;
  71. m_fVelocity_merchandise = 0;
  72. m_fMain_income = 0;
  73. m_fCash_ps = 0;
  74. m_fProfit_margin = 0;
  75. m_fNetasset_yield = 0;
  76. m_datebegin = 0;
  77. m_fShare_count_total = 0;
  78. m_fShare_count_a = 0;
  79. m_fShare_count_b = 0;
  80. m_fShare_count_h = 0;
  81. m_fShare_count_national = 0;
  82. m_fShare_count_corp = 0;
  83. m_fProfit_psud = 0;
  84. m_fAsset = 0;
  85. m_fRatio_holderright = 0;
  86. m_fRatio_longdebt = 0;
  87. m_fRatio_debt = 0;
  88. m_fNetasset_ps = 0;
  89. m_fNetasset_ps_regulate = 0;
  90. m_fEps = 0;
  91. m_fEps_deduct = 0;
  92. m_fNet_profit = 0;
  93. m_fMain_profit = 0;
  94. m_fTotal_profit = 0;
  95. m_fProfit_inc = 0;
  96. m_fIncome_inc = 0;
  97. m_fAsset_inc = 0;
  98. m_fYield_average = (float) STKLIB_DATA_INVALID;
  99. m_fYield_stddev = (float) STKLIB_DATA_INVALID;
  100. m_fBeite = (float) STKLIB_DATA_INVALID;
  101. }
  102. CStockInfo &CStockInfo::operator = (const CStockInfo & si)
  103. {
  104. m_dwMarket = si.m_dwMarket;
  105. memcpy(m_szCode, si.m_szCode, sizeof(m_szCode));
  106. m_type = si.m_type;
  107. memcpy(m_szName, si.m_szName, sizeof(m_szName));
  108. memcpy(m_szNameEnu, si.m_szNameEnu, sizeof(m_szNameEnu));
  109. memcpy(m_szShortname, si.m_szShortname, sizeof(m_szShortname));
  110. memcpy(m_szDomain, si.m_szDomain, sizeof(m_szDomain));
  111. memcpy(m_szProvince, si.m_szProvince, sizeof(m_szProvince));
  112. m_kdata = si.m_kdata;
  113. m_basedata = si.m_basedata;
  114. m_minute = si.m_minute;
  115. m_reportLatest = si.m_reportLatest;
  116. m_datetech = si.m_datetech;
  117. m_fLast = si.m_fLast;
  118. m_fOpen = si.m_fOpen;
  119. m_fHigh = si.m_fHigh;
  120. m_fLow = si.m_fLow;
  121. m_fClose = si.m_fClose;
  122. m_fVolume = si.m_fVolume;
  123. m_fAmount = si.m_fAmount;
  124. m_dwAdvance = si.m_dwAdvance;
  125. m_dwDecline = si.m_dwDecline;
  126. memcpy(m_fBuyPrice, si.m_fBuyPrice, sizeof(m_fBuyPrice));
  127. memcpy(m_fBuyVolume, si.m_fBuyVolume, sizeof(m_fBuyVolume));
  128. memcpy(m_fSellPrice, si.m_fSellPrice, sizeof(m_fSellPrice));
  129. memcpy(m_fSellVolume, si.m_fSellVolume, sizeof(m_fSellVolume));
  130. // base data
  131. m_datebase = si.m_datebase;
  132. m_reporttype = si.m_reporttype;
  133. m_fErate_dollar = si.m_fErate_dollar;
  134. m_fErate_hkdollar = si.m_fErate_hkdollar;
  135. m_fRatio_liquidity = si.m_fRatio_liquidity;
  136. m_fRatio_quick = si.m_fRatio_quick;
  137. m_fVelocity_receivables = si.m_fVelocity_receivables;
  138. m_fVelocity_merchandise = si.m_fVelocity_merchandise;
  139. m_fMain_income = si.m_fMain_income;
  140. m_fCash_ps = si.m_fCash_ps;
  141. m_fProfit_margin = si.m_fProfit_margin;
  142. m_fNetasset_yield = si.m_fNetasset_yield;
  143. m_datebegin = si.m_datebegin;
  144. m_fShare_count_total = si.m_fShare_count_total;
  145. m_fShare_count_a = si.m_fShare_count_a;
  146. m_fShare_count_b = si.m_fShare_count_b;
  147. m_fShare_count_h = si.m_fShare_count_h;
  148. m_fShare_count_national = si.m_fShare_count_national;
  149. m_fShare_count_corp = si.m_fShare_count_corp;
  150. m_fProfit_psud = si.m_fProfit_psud;
  151. m_fAsset = si.m_fAsset;
  152. m_fRatio_holderright = si.m_fRatio_holderright;
  153. m_fRatio_longdebt = si.m_fRatio_longdebt;
  154. m_fRatio_debt = si.m_fRatio_debt;
  155. m_fNetasset_ps = si.m_fNetasset_ps;
  156. m_fNetasset_ps_regulate = si.m_fNetasset_ps_regulate;
  157. m_fEps = si.m_fEps;
  158. m_fEps_deduct = si.m_fEps_deduct;
  159. m_fNet_profit = si.m_fNet_profit;
  160. m_fMain_profit = si.m_fMain_profit;
  161. m_fTotal_profit = si.m_fTotal_profit;
  162. m_fProfit_inc = si.m_fProfit_inc;
  163. m_fIncome_inc = si.m_fIncome_inc;
  164. m_fAsset_inc = si.m_fAsset_inc;
  165. m_fYield_average = si.m_fYield_average;
  166. m_fYield_stddev = si.m_fYield_stddev;
  167. m_fBeite = si.m_fBeite;
  168. return *this;
  169. }
  170. BOOL CStockInfo::IsEqualTo(DWORD dwMarket, const char * szCode)
  171. {
  172. if(m_dwMarket == dwMarket
  173. || CStock::marketUnknown == dwMarket || CStock::marketUnknown == m_dwMarket
  174. || 0 == dwMarket || 0 == m_dwMarket)
  175. {
  176. if(szCode && 0 == strcmp(szCode,m_szCode))
  177. return TRUE;
  178. }
  179. if(CStock::marketCHNA == m_dwMarket
  180. && (CStock::marketCHNA == dwMarket || CStock::marketSHSE == dwMarket || CStock::marketSZSE == dwMarket || CStock::marketCYSE == dwMarket))
  181. {
  182. if(szCode && 0 == strcmp(szCode,m_szCode))
  183. return TRUE;
  184. }
  185. if(CStock::marketCHNA == dwMarket
  186. && (CStock::marketCHNA == m_dwMarket || CStock::marketSHSE == m_dwMarket || CStock::marketSZSE == m_dwMarket || CStock::marketCYSE == m_dwMarket))
  187. {
  188. if(szCode && 0 == strcmp(szCode,m_szCode))
  189. return TRUE;
  190. }
  191. return FALSE;
  192. }
  193. DWORD CStockInfo::GetMarket()
  194. {
  195. return m_dwMarket;
  196. }
  197. void CStockInfo::SetMarket(DWORD dwMarket)
  198. {
  199. m_dwMarket = dwMarket;
  200. if(CStock::marketSHSE == dwMarket)
  201. m_type |= CStock::markShanghai;
  202. if(CStock::marketSZSE == dwMarket)
  203. m_type |= CStock::markShenzhen;
  204. }
  205. void CStockInfo::ResolveTypeAndMarket()
  206. {
  207. CStockInfo info;
  208. if(AfxGetStockContainer().GetStockInfo(m_szCode, &info)
  209. && CStock::typeNone != info.GetType()
  210. && CStock::marketUnknown != info.GetMarket())
  211. {
  212. if(CStock::typeNone == m_type)
  213. m_type = info.GetType();
  214. if(CStock::marketUnknown == m_dwMarket)
  215. m_dwMarket = info.GetMarket();
  216. return;
  217. }
  218. long type = CStock::typeNone;
  219. DWORD dwMarket = CStock::marketUnknown;
  220. if(strlen(m_szCode) > 0)
  221. {
  222. if(strcmp(m_szCode,"000001") >= 0 && strcmp(m_szCode,"000999") <= 0) // 深圳A股
  223. { type = CStock::typeszA; dwMarket = CStock::marketSZSE; }
  224. else if(strcmp(m_szCode,"002001") >= 0 && strcmp(m_szCode,"002999") <= 0) // 深圳A股(中小企业)
  225. { type = CStock::typeszA; dwMarket = CStock::marketSZSE; }
  226. else if(strcmp(m_szCode,"200001") >= 0 && strcmp(m_szCode,"200999") <= 0) // 深圳B股
  227. { type = CStock::typeszB; dwMarket = CStock::marketSZSE; }
  228. else if(strncmp(m_szCode,"600",3) == 0) // 上海A股
  229. { type = CStock::typeshA; dwMarket = CStock::marketSHSE; }
  230. else if(strncmp(m_szCode,"500",3) == 0) // 上海基金
  231. { type = CStock::typeshA; dwMarket = CStock::marketSHSE; }
  232. else if(strncmp(m_szCode,"900",3) == 0) // 上海B股
  233. { type = CStock::typeshB; dwMarket = CStock::marketSHSE; }
  234. else if(strcmp(m_szCode,"001001") >= 0 && strcmp(m_szCode,"001199") <= 0) // 深圳企业债券
  235. { type = CStock::typeszBond; dwMarket = CStock::marketSZSE; }
  236. else if(strcmp(m_szCode,"001200") >= 0 && strcmp(m_szCode,"001899") <= 0) // 深圳国债回购
  237. { type = CStock::typeszBond; dwMarket = CStock::marketSZSE; }
  238. else if(strcmp(m_szCode,"001900") >= 0 && strcmp(m_szCode,"001999") <= 0) // 深圳国债现货
  239. { type = CStock::typeszBond; dwMarket = CStock::marketSZSE; }
  240. else if(strcmp(m_szCode,"030000") >= 0 && strcmp(m_szCode,"038999") <= 0) // 深圳A股权证
  241. { type = CStock::typeszRight; dwMarket = CStock::marketSZSE; }
  242. else if(strcmp(m_szCode,"003001") >= 0 && strcmp(m_szCode,"003999") <= 0) // 深圳转配认购
  243. { type = CStock::typeszAdmeasure; dwMarket = CStock::marketSZSE; }
  244. else if(strcmp(m_szCode,"009001") >= 0 && strcmp(m_szCode,"009999") <= 0) // 深圳新股配售
  245. { type = CStock::typeszAdmeasure; dwMarket = CStock::marketSZSE; }
  246. else if(strcmp(m_szCode,"005001") >= 0 && strcmp(m_szCode,"005999") <= 0) // 深圳可转换债券
  247. { type = CStock::typeszBond; dwMarket = CStock::marketSZSE; }
  248. else if(strcmp(m_szCode,"006001") >= 0 && strcmp(m_szCode,"006999") <= 0) // 深圳国债期货
  249. { type = CStock::typeszBond; dwMarket = CStock::marketSZSE; }
  250. else if(strcmp(m_szCode,"004601") >= 0 && strcmp(m_szCode,"004699") <= 0) // 深圳证券投资基金
  251. { type = CStock::typeszA; dwMarket = CStock::marketSZSE; }
  252. else if(strcmp(m_szCode,"008001") >= 0 && strcmp(m_szCode,"008999") <= 0) // 深圳配股认购
  253. { type = CStock::typeszAdmeasure; dwMarket = CStock::marketSZSE; }
  254. else if(strncmp(m_szCode,"001",3) == 0) // 上海国债现货
  255. { type = CStock::typeshBond; dwMarket = CStock::marketSHSE; }
  256. else if(strncmp(m_szCode,"110",3) == 0 || strncmp(m_szCode,"120",3) == 0) // 上海企业债券
  257. { type = CStock::typeshBond; dwMarket = CStock::marketSHSE; }
  258. else if(strncmp(m_szCode,"310",3) == 0) // 上海国债期货
  259. { type = CStock::typeshBond; dwMarket = CStock::marketSHSE; }
  260. else if(strncmp(m_szCode,"580",3) == 0) // 上海权证
  261. { type = CStock::typeshRight; dwMarket = CStock::marketSHSE; }
  262. else if(strncmp(m_szCode,"710",3) == 0) // 上海转配股
  263. { type = CStock::typeshAdmeasure; dwMarket = CStock::marketSHSE; }
  264. else if(strncmp(m_szCode,"711",3) == 0) // 上海转配股再转配股
  265. { type = CStock::typeshAdmeasure; dwMarket = CStock::marketSHSE; }
  266. else if(strncmp(m_szCode,"730",3) == 0) // 上海新股申购
  267. { type = CStock::typeshAdmeasure; dwMarket = CStock::marketSHSE; }
  268. else if(strncmp(m_szCode,"737",3) == 0) // 上海新股配售
  269. { type = CStock::typeshAdmeasure; dwMarket = CStock::marketSHSE; }
  270. else if(strncmp(m_szCode,"201",3) == 0) // 上海国债回购
  271. { type = CStock::typeshBond; dwMarket = CStock::marketSHSE; }
  272. else if(strncmp(m_szCode,"129",3) == 0 || strncmp(m_szCode,"100",3) == 0) // 上海可转换债券
  273. { type = CStock::typeshBond; dwMarket = CStock::marketSHSE; }
  274. else if(strncmp(m_szCode,"700",3) == 0) // 上海配股
  275. { type = CStock::typeshAdmeasure; dwMarket = CStock::marketSHSE; }
  276. else if(strncmp(m_szCode,"701",3) == 0) // 上海转配股再配股
  277. { type = CStock::typeshAdmeasure; dwMarket = CStock::marketSHSE; }
  278. else if(strncmp(m_szCode,"720",3) == 0) // 上海红利
  279. { type = CStock::typeshBonus; dwMarket = CStock::marketSHSE; }
  280. else if(strncmp(m_szCode,"735",3) == 0) // 上海新基金申购
  281. { type = CStock::typeshAdmeasure; dwMarket = CStock::marketSHSE; }
  282. }
  283. if(CStock::typeNone == m_type)
  284. m_type = type;
  285. if(CStock::marketUnknown == m_dwMarket)
  286. m_dwMarket = dwMarket;
  287. }
  288. const char * CStockInfo::GetStockCode()
  289. {
  290. return m_szCode;
  291. }
  292. BOOL CStockInfo::SetStockCode(DWORD dwMarket, const char * szCode)
  293. {
  294. if(NULL == szCode || strlen(szCode) <= 0)
  295. {
  296. Clear();
  297. return FALSE;
  298. }
  299. if(IsEqualTo(dwMarket, szCode))
  300. {
  301. if(dwMarket != CStock::marketUnknown)
  302. m_dwMarket = dwMarket;
  303. return IsValidStock();
  304. }
  305. Clear();
  306. m_dwMarket = dwMarket;
  307. memset(m_szCode, 0, sizeof(m_szCode));
  308. strncpy(m_szCode, szCode, min(sizeof(m_szCode)-1,strlen(szCode)));
  309. ResolveTypeAndMarket();
  310. return IsValidStock();
  311. }
  312. LONG CStockInfo::GetType()
  313. {
  314. return m_type;
  315. }
  316. void CStockInfo::SetType(LONG t)
  317. {
  318. m_type = t;
  319. if(CStock::marketUnknown == m_dwMarket)
  320. {
  321. if(IsShenZhen())
  322. m_dwMarket = CStock::marketSZSE;
  323. if(IsShangHai())
  324. m_dwMarket = CStock::marketSHSE;
  325. }
  326. }
  327. const char * CStockInfo::GetStockName()
  328. {
  329. #ifdef CLKLAN_ENGLISH_US
  330. if(strlen(m_szNameEnu) > 0)
  331. return m_szNameEnu;
  332. if(strlen(m_szName) > 0)
  333. {
  334. if(AfxIsEnglish(m_szName,sizeof(m_szName)))
  335. return m_szName;
  336. else
  337. {
  338. CSPString sTemp = AfxFaintlyChsToEnu(m_szName);
  339. sTemp = AfxMakeSpellCode(sTemp);
  340. strncpy(m_szNameEnu, sTemp, min(sizeof(m_szNameEnu)-1,sTemp.GetLength()));
  341. return m_szNameEnu;
  342. }
  343. }
  344. if(strlen(m_szShortname) > 0 && AfxIsEnglish(m_szShortname,sizeof(m_szShortname))
  345. && sizeof(m_szNameEnu) > strlen(m_szCode)+strlen(m_szShortname)+1)
  346. {
  347. sprintf(m_szNameEnu, "%s-%s", m_szCode, m_szShortname);
  348. return m_szNameEnu;
  349. }
  350. return m_szCode;
  351. #else
  352. return m_szName;
  353. #endif
  354. }
  355. void CStockInfo::SetStockName(const char * szName)
  356. {
  357. memset(m_szName, 0, sizeof(m_szName));
  358. if(NULL == szName)
  359. return;
  360. strncpy(m_szName, szName, min(sizeof(m_szName)-1,strlen(szName)));
  361. }
  362. const char * CStockInfo::GetStockNameEnu()
  363. {
  364. return m_szNameEnu;
  365. }
  366. void CStockInfo::SetStockNameEnu(const char *szNameEnu)
  367. {
  368. memset(m_szNameEnu, 0, sizeof(m_szNameEnu));
  369. if(NULL == szNameEnu)
  370. return;
  371. strncpy(m_szNameEnu, szNameEnu, min(sizeof(m_szNameEnu)-1,strlen(szNameEnu)));
  372. }
  373. const char * CStockInfo::GetStockNameChs()
  374. {
  375. return m_szName;
  376. }
  377. void CStockInfo::SetStockNameChs(const char *szName)
  378. {
  379. memset(m_szName, 0, sizeof(m_szName));
  380. if(NULL == szName)
  381. return;
  382. strncpy(m_szName, szName, min(sizeof(m_szName)-1,strlen(szName)));
  383. }
  384. const char * CStockInfo::GetStockShortName()
  385. {
  386. if(strlen(m_szShortname) <= 0)
  387. {
  388. CSPString sName = m_szName;
  389. CSPString sTemp = AfxMakeSpellCode(sName, 0x0);
  390. strncpy(m_szShortname, sTemp, min(sizeof(m_szShortname)-1,sTemp.GetLength()));
  391. }
  392. return m_szShortname;
  393. }
  394. void CStockInfo::SetStockShortName(const char *szShortName)
  395. {
  396. memset(m_szShortname, 0, sizeof(m_szShortname));
  397. if(NULL == szShortName)
  398. return;
  399. strncpy(m_szShortname, szShortName, min(sizeof(m_szShortname)-1,strlen(szShortName)));
  400. }
  401. const char * CStockInfo::GetStockDomain()
  402. {
  403. #ifdef CLKLAN_ENGLISH_US
  404. if(!AfxIsEnglish(m_szDomain,sizeof(m_szDomain)))
  405. {
  406. CSPString sTemp = AfxFaintlyChsToEnu(m_szDomain);
  407. memset(m_szDomain, 0, sizeof(m_szDomain));
  408. if(AfxIsEnglish(sTemp,sTemp.GetLength()))
  409. strncpy(m_szDomain, sTemp, min(sizeof(m_szDomain)-1,sTemp.GetLength()));
  410. }
  411. return m_szDomain;
  412. #else
  413. return m_szDomain;
  414. #endif
  415. }
  416. void CStockInfo::SetStockDomain(const char * szDomain)
  417. {
  418. memset(m_szDomain, 0, sizeof(m_szDomain));
  419. if(NULL == szDomain)
  420. return;
  421. strncpy(m_szDomain, szDomain, min(sizeof(m_szDomain)-1,strlen(szDomain)));
  422. }
  423. const char * CStockInfo::GetStockProvince()
  424. {
  425. #ifdef CLKLAN_ENGLISH_US
  426. if(!AfxIsEnglish(m_szProvince,sizeof(m_szProvince)))
  427. {
  428. CSPString sTemp = AfxFaintlyChsToEnu(m_szProvince);
  429. sTemp = AfxMakeSpellCode(sTemp);
  430. memset(m_szProvince, 0, sizeof(m_szProvince));
  431. strncpy(m_szProvince, sTemp, min(sizeof(m_szProvince)-1,sTemp.GetLength()));
  432. }
  433. return m_szProvince;
  434. #else
  435. return m_szProvince;
  436. #endif
  437. }
  438. void CStockInfo::SetStockProvince(const char * szProvince)
  439. {
  440. memset(m_szProvince, 0, sizeof(m_szProvince));
  441. if(NULL == szProvince)
  442. return;
  443. strncpy(m_szProvince, szProvince, min(sizeof(m_szProvince)-1,strlen(szProvince)));
  444. }
  445. BOOL CStockInfo::StatTechIndex(DWORD dwDate)
  446. {
  447. SP_ASSERT(0 != dwDate);
  448. if(m_kdata.GetSize() == 0)
  449. return FALSE;
  450. int nIndex = -1;
  451. if(-1 == dwDate)
  452. nIndex = m_kdata.GetSize() - 1;
  453. else
  454. nIndex = m_kdata.GetIndexByDate(dwDate);
  455. if(-1 == nIndex)
  456. {
  457. m_datetech = 0;
  458. m_fLast = 0;
  459. m_fOpen = 0;
  460. m_fHigh = 0;
  461. m_fLow = 0;
  462. m_fClose = 0;
  463. m_fAmount = 0;
  464. m_fVolume = 0;
  465. m_dwAdvance = 0;
  466. m_dwDecline = 0;
  467. return FALSE;
  468. }
  469. else
  470. {
  471. KDATA & kd = m_kdata.ElementAt(nIndex);
  472. m_datetech = kd.m_date;
  473. if(nIndex > 0)
  474. m_fLast = m_kdata.ElementAt(nIndex-1).m_fClose;
  475. else
  476. m_fLast = kd.m_fOpen;
  477. m_fOpen = kd.m_fOpen;
  478. m_fHigh = kd.m_fHigh;
  479. m_fLow = kd.m_fLow;
  480. m_fClose = kd.m_fClose;
  481. m_fAmount = kd.m_fAmount;
  482. m_fVolume = kd.m_fVolume;
  483. m_dwAdvance = kd.m_dwAdvance;
  484. m_dwDecline = kd.m_dwDecline;
  485. return TRUE;
  486. }
  487. }
  488. BOOL CStockInfo::StatBaseIndex(DWORD dwDate)
  489. {
  490. SP_ASSERT(0 != dwDate);
  491. if(m_basedata.GetSize() == 0)
  492. return FALSE;
  493. int nIndex = m_basedata.GetSize()-1;
  494. for(int i=m_basedata.GetSize()-1; i>=0; i--)
  495. {
  496. if(m_basedata.ElementAt(i).m_date <= dwDate)
  497. {
  498. nIndex = i;
  499. break;
  500. }
  501. }
  502. BASEDATA & block = m_basedata.ElementAt(nIndex);
  503. strncpy(m_szDomain, block.m_szDomain, min(sizeof(m_szDomain),sizeof(block.m_szDomain)));
  504. strncpy(m_szProvince, block.m_szProvince, min(sizeof(m_szProvince),sizeof(block.m_szProvince)));
  505. m_datebase = block.m_date;
  506. m_reporttype = block.m_reporttype;
  507. if(block.m_fErate_dollar > 1e-6)
  508. m_fErate_dollar = block.m_fErate_dollar;
  509. if(block.m_fErate_hkdollar > 1e-6)
  510. m_fErate_hkdollar = block.m_fErate_hkdollar;
  511. m_fRatio_liquidity = block.m_fRatio_liquidity;
  512. m_fRatio_quick = block.m_fRatio_quick;
  513. m_fVelocity_receivables = block.m_fVelocity_receivables;
  514. m_fVelocity_merchandise = block.m_fVelocity_merchandise;
  515. m_fMain_income = block.m_fMain_income;
  516. m_fCash_ps = block.m_fCash_ps;
  517. m_fProfit_margin = block.m_fProfit_margin;
  518. m_fNetasset_yield = block.m_fNetasset_yield;
  519. m_datebegin = block.m_datebegin;
  520. m_fShare_count_total = block.m_fShare_count_total;
  521. m_fShare_count_a = block.m_fShare_count_a;
  522. m_fShare_count_b = block.m_fShare_count_b;
  523. m_fShare_count_h = block.m_fShare_count_h;
  524. m_fShare_count_national = block.m_fShare_count_national;
  525. m_fShare_count_corp = block.m_fShare_count_corp;
  526. m_fProfit_psud = block.m_fProfit_psud;
  527. m_fAsset = block.m_fAsset;
  528. m_fRatio_holderright = block.m_fRatio_holderright;
  529. m_fRatio_longdebt = block.m_fRatio_longdebt;
  530. m_fRatio_debt = block.m_fRatio_debt;
  531. m_fNetasset_ps = block.m_fNetasset_ps;
  532. m_fNetasset_ps_regulate = block.m_fNetasset_ps_regulate;
  533. m_fEps = block.m_fEps;
  534. m_fEps_deduct = block.m_fEps_deduct;
  535. m_fNet_profit = block.m_fNet_profit;
  536. m_fMain_profit = block.m_fMain_profit;
  537. m_fTotal_profit = block.m_fTotal_profit;
  538. m_fProfit_inc = block.m_fProfit_inc;
  539. m_fIncome_inc = block.m_fIncome_inc;
  540. m_fAsset_inc = block.m_fAsset_inc;
  541. /* 以下统计值永远只取最近一期数值
  542. // ★技术数据统计值
  543. LONG m_fYield_average; // 平均收益率% 0.001
  544. LONG m_fYield_stddev; // 收益标准差% 0.001
  545. LONG m_fBeite; // β值 0.001
  546. */
  547. BASEDATA & blkLatest = m_basedata.ElementAt(m_basedata.GetSize()-1);
  548. m_fYield_average = blkLatest.m_fYield_average;
  549. m_fYield_stddev = blkLatest.m_fYield_stddev;
  550. m_fBeite = blkLatest.m_fBeite;
  551. /*** stat
  552. m_fProfit_inc = 0;
  553. m_fIncome_inc = 0;
  554. LONG nProfitCount = 0;
  555. LONG nIncomeCount = 0;
  556. float fProfitLast = 0, fProfitSum = 0;
  557. float fIncomeLast = 0, fIncomeSum = 0;
  558. for(int i=0; i<m_basedata.GetSize(); i++)
  559. {
  560. BASEDATA & base = m_basedata.ElementAt(i);
  561. if(fabs(fProfitLast) > 1e-4)
  562. {
  563. nProfitCount ++;
  564. fProfitSum += (float) ((base.m_fNet_profit)/nProfitLast - 1);
  565. }
  566. if(fabs(fIncomeLast) > 1e-4)
  567. {
  568. nIncomeCount ++;
  569. fIncomeSum += (float)((base.m_fMain_income)/nIncomeLast - 1);
  570. }
  571. fProfitLast = base.m_fNet_profit;
  572. fIncomeLast = base.m_fMain_income;
  573. }
  574. if(nProfitCount > 0)
  575. m_fProfit_inc = (float)(((double)fProfitSum)/nProfitCount);
  576. if(nIncomeCount > 0)
  577. m_fIncome_inc = (float)(((double)fIncomeSum)/nIncomeCount);
  578. */
  579. return TRUE;
  580. }
  581. BOOL CStockInfo::IsValidStock()
  582. {
  583. return (strlen(m_szCode) > 0);
  584. }
  585. BOOL CStockInfo::IsShangHai()
  586. {
  587. if(CStock::marketSHSE == m_dwMarket)
  588. return TRUE;
  589. return (m_type & CStock::markShanghai);
  590. }
  591. BOOL CStockInfo::IsShenZhen()
  592. {
  593. if(CStock::marketSZSE == m_dwMarket)
  594. return TRUE;
  595. return (m_type & CStock::markShenzhen);
  596. }
  597. BOOL CStockInfo::IsIndex()
  598. {
  599. return (CStock::typeshIndex == m_type || CStock::typeszIndex == m_type);
  600. }
  601. BOOL CStockInfo::IsBond()
  602. {
  603. if(CStock::typeshBond == m_type || CStock::typeszBond == m_type)
  604. return TRUE;
  605. return (0 == strncmp(m_szName, sz_stockname_bond, min(sizeof(m_szName),strlen(sz_stockname_bond))));
  606. }
  607. BOOL CStockInfo::IsBondIndex()
  608. {
  609. return (0 == strncmp(m_szName, sz_stockname_bondindex, min(sizeof(m_szName),strlen(sz_stockname_bondindex)))
  610. || 0 == strncmp(m_szName, sz_stockname_bondindexcorp, min(sizeof(m_szName),strlen(sz_stockname_bondindexcorp))));
  611. }
  612. BOOL CStockInfo::IsFund()
  613. {
  614. return (0 == strncmp(m_szName, sz_stockname_fund, min(sizeof(m_szName),strlen(sz_stockname_fund))));
  615. }
  616. BOOL CStockInfo::IsRight()
  617. {
  618. return (CStock::typeshRight == m_type || CStock::typeszRight == m_type);
  619. }
  620. int CStockInfo::DigitBit()
  621. {
  622. if(IsFund() || IsRight() || CStock::typeshB == m_type)
  623. return 3;
  624. return 2;
  625. }
  626. BOOL CStockInfo::GetAverage(double *pValue)
  627. {
  628. if(CStock::typeshIndex == m_type || CStock::typeszIndex == m_type)
  629. return FALSE;
  630. if(m_fVolume > 1e-4)
  631. {
  632. int nCount = 0;
  633. double average = ((double)(m_fAmount)) / m_fVolume;
  634. while(average < m_fLow && nCount < 10) { average *= 10; nCount ++; }
  635. while(average > m_fHigh && nCount < 20) { average /= 10; nCount ++; }
  636. if(average < m_fLow) // 说明是指数
  637. average = (m_fOpen+m_fHigh+m_fLow+m_fClose)/4;
  638. if(pValue)
  639. *pValue = average;
  640. return TRUE;
  641. }
  642. return FALSE;
  643. }
  644. BOOL CStockInfo::GetDiff(double *pValue, DWORD dateCur, int nDays)
  645. {
  646. if(1 == nDays && m_datetech == dateCur)
  647. {
  648. if(m_fLast <= 1e-4 || m_fClose < 1e-4)
  649. return FALSE;
  650. if(pValue)
  651. *pValue = m_fClose - m_fLast;
  652. return TRUE;
  653. }
  654. return m_kdata.GetDiff(pValue, dateCur, nDays);
  655. }
  656. BOOL CStockInfo::GetDiffPercent(double *pValue, DWORD dateCur, int nDays)
  657. {
  658. if(1 == nDays && m_datetech == dateCur)
  659. {
  660. if(m_fLast <= 1e-4 || m_fClose < 1e-4)
  661. return FALSE;
  662. if(pValue)
  663. *pValue = 100. * m_fClose / m_fLast - 100;
  664. return TRUE;
  665. }
  666. return m_kdata.GetDiffPercent(pValue, dateCur, nDays);
  667. }
  668. BOOL CStockInfo::GetScope(double *pValue, DWORD dateCur, int nDays)
  669. {
  670. if(1 == nDays && m_datetech == dateCur)
  671. {
  672. if(m_fLast <= 1e-4 || m_fHigh <= 1e-4 || m_fLow <= 1e-4)
  673. return FALSE;
  674. if(pValue)
  675. *pValue = 100. * (m_fHigh-m_fLow)/m_fLast;
  676. return TRUE;
  677. }
  678. return m_kdata.GetScope(pValue, dateCur, nDays);
  679. }
  680. BOOL CStockInfo::GetDiffPercentMin5(double *pValue)
  681. {
  682. return m_minute.GetDiffPercentMin5(pValue);
  683. }
  684. BOOL CStockInfo::GetPE(double * pValue)
  685. {
  686. double factor = CStock::GetReportFactor(m_reporttype);
  687. if(fabs(m_fEps) > 1e-4 && m_fClose > 1e-4)
  688. {
  689. double close_price_rmb = m_fClose;
  690. if(CStock::typeshB == m_type)
  691. close_price_rmb = /*m_fErate_dollar * */m_fClose; // 备注,从通达信得到的基本资料数据是经过汇率换算的.
  692. else if(CStock::typeszB == m_type)
  693. close_price_rmb = /*m_fErate_hkdollar * */m_fClose;
  694. if(pValue)
  695. *pValue = close_price_rmb / (m_fEps * factor);
  696. return TRUE;
  697. }
  698. return FALSE;
  699. }
  700. BOOL CStockInfo::GetPNetAsset(double *pValue)
  701. {
  702. if(fabs(m_fNetasset_ps) > 1e-4 && m_fClose > 1e-4)
  703. {
  704. double close_price_rmb = m_fClose;
  705. if(CStock::typeshB == m_type)
  706. close_price_rmb = /*m_fErate_dollar * */m_fClose; // 备注,从通达信得到的基本资料数据是经过汇率换算的.
  707. else if(CStock::typeszB == m_type)
  708. close_price_rmb = /*m_fErate_hkdollar * */m_fClose;
  709. if(pValue)
  710. *pValue = close_price_rmb / m_fNetasset_ps;
  711. return TRUE;
  712. }
  713. return FALSE;
  714. }
  715. BOOL CStockInfo::GetPMainIncome(double * pValue)
  716. {
  717. double factor = CStock::GetReportFactor(m_reporttype);
  718. if(fabs(m_fMain_income) > 1e-4 && m_fClose > 1e-4)
  719. {
  720. double close_price_rmb = m_fClose;
  721. if(CStock::typeshB == m_type)
  722. close_price_rmb = /*m_fErate_dollar * */m_fClose; // 备注,从通达信得到的基本资料数据是经过汇率换算的.
  723. else if(CStock::typeszB == m_type)
  724. close_price_rmb = /*m_fErate_hkdollar * */m_fClose;
  725. if(pValue)
  726. *pValue = close_price_rmb * m_fShare_count_total / (m_fMain_income*factor);
  727. return TRUE;
  728. }
  729. return FALSE;
  730. }
  731. BOOL CStockInfo::GetRatioPCash(double * pValue)
  732. {
  733. if(CStock::typeshA != m_type && CStock::typeszA != m_type
  734. && CStock::typeshB != m_type && CStock::typeszB != m_type)
  735. return FALSE;
  736. double factor = CStock::GetReportFactor(m_reporttype);
  737. if(fabs(m_fCash_ps) > 1e-4 && m_fClose > 1e-4)
  738. {
  739. double close_price_rmb = m_fClose;
  740. if(CStock::typeshB == m_type)
  741. close_price_rmb = /*m_fErate_dollar * */m_fClose; // 备注,从通达信得到的基本资料数据是经过汇率换算的.
  742. else if(CStock::typeszB == m_type)
  743. close_price_rmb = /*m_fErate_hkdollar * */m_fClose;
  744. if(pValue)
  745. *pValue = close_price_rmb / (m_fCash_ps*factor);
  746. return TRUE;
  747. }
  748. return FALSE;
  749. }
  750. BOOL CStockInfo::GetShareCurrency(double * pValue)
  751. {
  752. if(CStock::typeshA != m_type && CStock::typeszA != m_type
  753. && CStock::typeshB != m_type && CStock::typeszB != m_type)
  754. return FALSE;
  755. if(CStock::typeshA == m_type || CStock::typeszA == m_type)
  756. {
  757. *pValue = (double)m_fShare_count_a;
  758. return TRUE;
  759. }
  760. if(CStock::typeshB == m_type || CStock::typeszB == m_type)
  761. {
  762. *pValue = (double)m_fShare_count_b;
  763. return TRUE;
  764. }
  765. return FALSE;
  766. }
  767. BOOL CStockInfo::GetRatioCurrency(double * pValue)
  768. {
  769. if(CStock::typeshA != m_type && CStock::typeszA != m_type
  770. && CStock::typeshB != m_type && CStock::typeszB != m_type)
  771. return FALSE;
  772. if(m_fShare_count_total > 1e-4)
  773. {
  774. if(CStock::typeshA == m_type || CStock::typeszA == m_type)
  775. {
  776. *pValue = (100. * (double)m_fShare_count_a) / m_fShare_count_total;
  777. return TRUE;
  778. }
  779. if(CStock::typeshB == m_type || CStock::typeszB == m_type)
  780. {
  781. *pValue = (100. * (double)m_fShare_count_b) / m_fShare_count_total;
  782. return TRUE;
  783. }
  784. }
  785. return FALSE;
  786. }
  787. BOOL CStockInfo::GetRatioChangeHand(double * pValue, double dVolume)
  788. {
  789. if(CStock::typeshA != m_type && CStock::typeszA != m_type
  790. && CStock::typeshB != m_type && CStock::typeszB != m_type)
  791. return FALSE;
  792. // get share currency
  793. double dShareCurrency = 0.;
  794. if(!GetShareCurrency(&dShareCurrency))
  795. return FALSE;
  796. if(fabs(dShareCurrency) < 1e-4)
  797. return FALSE;
  798. if(pValue)
  799. *pValue = 100. * dVolume / dShareCurrency;
  800. return TRUE;
  801. }
  802. BOOL CStockInfo::GetRatioChangeHand(CKData &kdata, double * pValue, DWORD dateCur, int nDays)
  803. {
  804. double dVolume = 0;
  805. if(!kdata.GetVolumeSum(&dVolume, dateCur, nDays))
  806. return FALSE;
  807. return GetRatioChangeHand(pValue, dVolume);
  808. }
  809. BOOL CStockInfo::GetRatioChangeHand(double * pValue, DWORD dateCur, int nDays)
  810. {
  811. return GetRatioChangeHand(m_kdata, pValue, dateCur, nDays);
  812. }
  813. BOOL CStockInfo::GetRatioVolume(double * pValue, DWORD dateCur, int nDays)
  814. {
  815. return m_kdata.GetRatioVolume(pValue, dateCur, nDays);
  816. }
  817. BOOL CStockInfo::GetRS(double * pValue, DWORD dateCur, int nDays)
  818. {
  819. return m_kdata.GetRS(pValue, dateCur, nDays);
  820. }
  821. BOOL CStockInfo::GetSellBuyRatio(double *pdRatio, double *pdDiff)
  822. {
  823. double dBuyVolume = m_fBuyVolume[0];
  824. dBuyVolume += m_fBuyVolume[1];
  825. dBuyVolume += m_fBuyVolume[2];
  826. dBuyVolume += m_fBuyVolume[3];
  827. double dSellVolume = m_fSellVolume[0];
  828. dSellVolume += m_fSellVolume[1];
  829. dSellVolume += m_fSellVolume[2];
  830. dSellVolume += m_fSellVolume[3];
  831. double dRatio = 0;
  832. if(dBuyVolume + dSellVolume > 1e-4)
  833. dRatio = 200*dBuyVolume/(dBuyVolume+dSellVolume)-100;
  834. double dDiff = dBuyVolume - dSellVolume;
  835. if(pdRatio)
  836. *pdRatio = dRatio;
  837. if(pdDiff)
  838. *pdDiff = dDiff;
  839. return TRUE;
  840. }
  841. BOOL CStockInfo::GetMarketValue(double * pValue)
  842. {
  843. if(CStock::typeshA != m_type && CStock::typeszA != m_type
  844. && CStock::typeshB != m_type && CStock::typeszB != m_type)
  845. return FALSE;
  846. if(m_fClose > 1e-4 && m_fShare_count_total > 1e-4)
  847. {
  848. if(pValue)
  849. *pValue = m_fClose * m_fShare_count_total;
  850. return TRUE;
  851. }
  852. return FALSE;
  853. }
  854. BOOL CStockInfo::GetMarketValueA(double * pValue)
  855. {
  856. if(m_fClose > 1e-4 && m_fShare_count_a > 1e-4
  857. && (CStock::typeshA == m_type || CStock::typeszA == m_type))
  858. {
  859. if(pValue)
  860. *pValue = m_fClose * m_fShare_count_a;
  861. return TRUE;
  862. }
  863. return FALSE;
  864. }
  865. BOOL CStockInfo::GetMarketValueB(double * pValue)
  866. {
  867. if(m_fClose > 1e-4 && m_fShare_count_b > 1e-4
  868. && (CStock::typeshB == m_type || CStock::typeszB == m_type))
  869. {
  870. if(pValue)
  871. *pValue = m_fClose * m_fShare_count_b;
  872. return TRUE;
  873. }
  874. return FALSE;
  875. }
  876. BOOL CStockInfo::GetXiapu(double * pValue)
  877. {
  878. if(fabs(STKLIB_DATA_INVALID - m_fYield_average) > 1e-4
  879. && fabs(STKLIB_DATA_INVALID - m_fYield_stddev) > 1e-4 && fabs(m_fYield_stddev) > 1e-4)
  880. {
  881. if(pValue)
  882. *pValue = 100. * (m_fYield_average-3) / m_fYield_stddev;
  883. //                                       ^^^^ 市场无风险利率3%
  884. return TRUE;
  885. }
  886. return FALSE;
  887. }
  888. //////////////////////////////////////////////////////////////////////
  889. // class CStock
  890. double CStock::GetReportFactor(int nReportType)
  891. {
  892. double factor = 1;
  893. if(CStock::reportQuarter == nReportType)
  894. factor = 4;
  895. else if(CStock::reportMid == nReportType)
  896. factor = 2;
  897. else if(CStock::reportQuarter3 == nReportType)
  898. factor = 1.333333;
  899. return factor;
  900. }
  901. CStock::CStock()
  902. {
  903. m_nBaseTextLen = 0;
  904. m_pBaseText = NULL;
  905. m_pDatabase = NULL;
  906. SetKDataTypes();
  907. }
  908. CStock::CStock(CStDatabase * pDatabase)
  909. {
  910. m_nBaseTextLen = 0;
  911. m_pBaseText = NULL;
  912. SP_ASSERT(pDatabase);
  913. m_pDatabase = pDatabase;
  914. SetKDataTypes();
  915. }
  916. CStock::CStock(CStDatabase * pDatabase, DWORD dwMarket, const char * code)
  917. {
  918. m_nBaseTextLen = 0;
  919. m_pBaseText = NULL;
  920. SP_ASSERT(pDatabase);
  921. m_pDatabase = pDatabase;
  922. m_stockinfo.SetStockCode(dwMarket, code);
  923. SetKDataTypes();
  924. }
  925. CStock::~CStock()
  926. {
  927. Clear();
  928. }
  929. void CStock::SetKDataTypes()
  930. {
  931. m_kdMonth.SetKType(CKData::ktypeMonth);
  932. m_kdWeek.SetKType(CKData::ktypeWeek);
  933. m_kdDay.SetKType(CKData::ktypeDay);
  934. m_kdMin60.SetKType(CKData::ktypeMin60);
  935. m_kdMin30.SetKType(CKData::ktypeMin30);
  936. m_kdMin15.SetKType(CKData::ktypeMin15);
  937. m_kdMin5.SetKType(CKData::ktypeMin5);
  938. }
  939. void CStock::SetDatabase(CStDatabase * pDatabase)
  940. {
  941. m_pDatabase = pDatabase;
  942. }
  943. CStDatabase * CStock::GetDatabase()
  944. {
  945. return m_pDatabase;
  946. }
  947. void CStock::SetStockCode(DWORD dwMarket, const char *szCode)
  948. {
  949. if(m_stockinfo.IsEqualTo(dwMarket, szCode))
  950. return;
  951. Clear();
  952. m_stockinfo.SetStockCode(dwMarket,szCode);
  953. }
  954. const char * CStock::GetStockCode()
  955. {
  956. return m_stockinfo.GetStockCode();
  957. }
  958. BOOL CStock::SetStockInfo(CStockInfo * pInfo)
  959. {
  960. if(NULL == pInfo)
  961. {
  962. Clear();
  963. return FALSE;
  964. }
  965. if(m_stockinfo.IsEqualTo(pInfo->GetMarket(), pInfo->GetStockCode()))
  966. {
  967. m_stockinfo = *pInfo;
  968. return m_stockinfo.IsValidStock();
  969. }
  970. Clear();
  971. m_stockinfo = *pInfo;
  972. return m_stockinfo.IsValidStock();
  973. }
  974. CStockInfo & CStock::GetStockInfo() { return m_stockinfo; }
  975. CKData & CStock::GetKData(int ktype)
  976. {
  977. switch(ktype)
  978. {
  979. case CKData::ktypeMonth:
  980. return GetKDataMonth();
  981. case CKData::ktypeWeek:
  982. return GetKDataWeek();
  983. case CKData::ktypeDay:
  984. return GetKDataDay();
  985. case CKData::ktypeMin60:
  986. return GetKDataMin60();
  987. case CKData::ktypeMin30:
  988. return GetKDataMin30();
  989. case CKData::ktypeMin15:
  990. return GetKDataMin15();
  991. case CKData::ktypeMin5:
  992. return GetKDataMin5();
  993. default:
  994. SP_ASSERT(FALSE);
  995. return GetKDataDay();
  996. }
  997. }
  998. CKData & CStock::GetKDataMonth() { return m_kdMonth; }
  999. CKData & CStock::GetKDataWeek() { return m_kdWeek; }
  1000. CKData & CStock::GetKDataDay() { return m_kdDay; }
  1001. CKData & CStock::GetKDataMin60() { return m_kdMin60; }
  1002. CKData & CStock::GetKDataMin30() { return m_kdMin30; }
  1003. CKData & CStock::GetKDataMin15() { return m_kdMin15; }
  1004. CKData & CStock::GetKDataMin5() { return m_kdMin5; }
  1005. CDRData & CStock::GetDRData() { return m_drData; }
  1006. CReport & CStock::GetReport() { return m_report; }
  1007. CMinute & CStock::GetMinute() { return m_minute; }
  1008. COutline & CStock::GetOutline() { return m_outline; }
  1009. char * CStock::GetBaseTextPtr() { return m_pBaseText; }
  1010. int CStock::GetBaseTextLength() { return m_nBaseTextLen; }
  1011. BOOL CStock::AllocBaseTextMem(int nNewLength)
  1012. {
  1013. SP_ASSERT(nNewLength <= 0x200000);
  1014. if(nNewLength > 0x200000) return FALSE;
  1015. if(m_pBaseText)
  1016. {
  1017. delete m_pBaseText;
  1018. m_nBaseTextLen = 0;
  1019. }
  1020. m_pBaseText = new CHAR[nNewLength+1];
  1021. if(m_pBaseText)
  1022. {
  1023. memset(m_pBaseText, 0, nNewLength+1);
  1024. m_nBaseTextLen = nNewLength;
  1025. return TRUE;
  1026. }
  1027. return FALSE;
  1028. }
  1029. int CStock::PrepareData(int type, int period, BOOL bReload)
  1030. {
  1031. SP_ASSERT(m_pDatabase);
  1032. if(! m_pDatabase) return 0;
  1033. switch(type)
  1034. {
  1035. case dataInfo:
  1036. return AfxGetStockContainer().GetStockInfo(m_stockinfo.GetStockCode(), &m_stockinfo);
  1037. case dataK:
  1038. {
  1039. switch(period)
  1040. {
  1041. case CKData::ktypeMonth:
  1042. if(bReload || GetKDataMonth().GetSize() == 0)
  1043. m_pDatabase->LoadKData(this, CKData::ktypeMonth);
  1044. break;
  1045. case CKData::ktypeWeek:
  1046. if(bReload || GetKDataWeek().GetSize() == 0)
  1047. m_pDatabase->LoadKData(this, CKData::ktypeWeek);
  1048. break;
  1049. case CKData::ktypeDay:
  1050. if(bReload || GetKDataDay().GetSize() == 0)
  1051. m_pDatabase->LoadKData(this, CKData::ktypeDay);
  1052. break; // month, week, and day willnot extract from min60,min30...
  1053. case CKData::ktypeMin60:
  1054. if(bReload || GetKDataMin60().GetSize() == 0)
  1055. m_pDatabase->LoadKData(this, CKData::ktypeMin60);
  1056. break;
  1057. case CKData::ktypeMin30:
  1058. if(bReload || GetKDataMin30().GetSize() == 0)
  1059. m_pDatabase->LoadKData(this, CKData::ktypeMin30);
  1060. break;
  1061. case CKData::ktypeMin15:
  1062. if(bReload || GetKDataMin15().GetSize() == 0)
  1063. m_pDatabase->LoadKData(this, CKData::ktypeMin15);
  1064. break;
  1065. case CKData::ktypeMin5:
  1066. if(bReload || GetKDataMin5().GetSize() == 0)
  1067. m_pDatabase->LoadKData(this, CKData::ktypeMin5);
  1068. break;
  1069. default:
  1070. SP_ASSERT(FALSE);
  1071. return 0;
  1072. }
  1073. return ExtractKData(period, FALSE);
  1074. }
  1075. case dataDR:
  1076. if(bReload || GetDRData().GetSize() == 0)
  1077. return m_pDatabase->LoadDRData(this);
  1078. else
  1079. return GetDRData().GetSize();
  1080. case dataBasetable:
  1081. return AfxGetStockContainer().GetStockInfo(m_stockinfo.GetStockCode(), &m_stockinfo);
  1082. case dataBasetext:
  1083. if(bReload || !GetBaseTextPtr())
  1084. return m_pDatabase->LoadBaseText(this);
  1085. else
  1086. return GetBaseTextLength();
  1087. case dataReport:
  1088. if(bReload || GetReport().GetSize() == 0)
  1089. return m_pDatabase->LoadReport(this);
  1090. else
  1091. return GetReport().GetSize();
  1092. case dataMinute:
  1093. if(bReload || GetMinute().GetSize() == 0)
  1094. return m_pDatabase->LoadMinute(this);
  1095. else
  1096. return GetMinute().GetSize();
  1097. case dataOutline:
  1098. if(bReload || GetOutline().GetSize() == 0)
  1099. return m_pDatabase->LoadOutline(this);
  1100. else
  1101. return GetOutline().GetSize();
  1102. default:
  1103. SP_ASSERT(FALSE);
  1104. return 0;
  1105. }
  1106. }
  1107. int CStock::PrepareBaseInfo(BOOL bReload)
  1108. {
  1109. // Load From File
  1110. PrepareData(CStock::dataBasetext, 0, bReload);
  1111. // Save To pText
  1112. int nTextLen = m_nBaseTextLen;
  1113. char* pText = NULL;
  1114. if (m_pBaseText && nTextLen > 0)
  1115. {
  1116. pText = new CHAR[nTextLen+1];
  1117. if (pText) memcpy(pText, m_pBaseText, nTextLen);
  1118. if (pText) pText[nTextLen] = 0;
  1119. }
  1120. int nIntroLen = SLH_MAX * 80;
  1121. if (!AllocBaseTextMem(nIntroLen + m_nBaseTextLen + 10))
  1122. return 0;
  1123. int nCount = 0;
  1124. //for (int nVariantID = SLH_MIN; nVariantID <= SLH_MAX; nVariantID++)
  1125. //{
  1126. // CSPString strTemp = AfxGetVariantName(nVariantID, TRUE);
  1127. // strTemp += ": t";
  1128. // strTemp += (LPCTSTR)AfxGetVariantDispString(nVariantID, m_stockinfo, NULL);
  1129. // strTemp += STRING_CRLF;
  1130. // SP_ASSERT(nCount + strTemp.GetLength() < nIntroLen);
  1131. // if (nCount + strTemp.GetLength() < nIntroLen)
  1132. // {
  1133. // nCount += strTemp.GetLength();
  1134. // strcat(m_pBaseText, (LPCTSTR)strTemp);
  1135. // }
  1136. //}
  1137. nCount += strlen(STRING_CRLF);
  1138. strcat(m_pBaseText, STRING_CRLF);
  1139. nCount += strlen(STRING_CRLF);
  1140. strcat(m_pBaseText, STRING_CRLF);
  1141. if (pText && nCount + nTextLen < m_nBaseTextLen)
  1142. {
  1143. nCount += nTextLen;
  1144. strcat(m_pBaseText, pText);
  1145. }
  1146. if (pText)
  1147. delete[] pText;
  1148. return nCount;
  1149. }
  1150. int CStock::ExtractKData(int period, BOOL bForced)
  1151. {
  1152. switch(period)
  1153. {
  1154. case CKData::ktypeMonth:
  1155. {
  1156. if(bForced)
  1157. return CKData::DayToMonth(GetKDataDay(), GetKDataMonth());
  1158. int compare = GetKDataMonth().CompareLatestDate(GetKDataDay());
  1159. if(-1 == compare)
  1160. return CKData::DayToMonth(GetKDataDay(), GetKDataMonth());
  1161. else if(1 == compare)
  1162. return GetKDataMonth().GetSize();
  1163. else if(GetKDataMonth().GetSize() * 18 < GetKDataDay().GetSize())
  1164. return CKData::DayToMonth(GetKDataDay(), GetKDataMonth());
  1165. else
  1166. return GetKDataMonth().GetSize();
  1167. }
  1168. break;
  1169. case CKData::ktypeWeek:
  1170. {
  1171. if(bForced)
  1172. return CKData::DayToWeek(GetKDataDay(), GetKDataWeek());
  1173. int compare = GetKDataWeek().CompareLatestDate(GetKDataDay());
  1174. if(-1 == compare)
  1175. return CKData::DayToWeek(GetKDataDay(), GetKDataWeek());
  1176. else if(1 == compare)
  1177. return GetKDataWeek().GetSize();
  1178. else if(GetKDataWeek().GetSize() * 5 < GetKDataDay().GetSize())
  1179. return CKData::DayToWeek(GetKDataDay(), GetKDataWeek());
  1180. else
  1181. return GetKDataWeek().GetSize();
  1182. }
  1183. break;
  1184. case CKData::ktypeDay:
  1185. return GetKDataDay().GetSize();
  1186. case CKData::ktypeMin60:
  1187. {
  1188. if(bForced)
  1189. return CKData::Min5ToMin60(GetKDataMin5(), GetKDataMin60());
  1190. int compare = GetKDataMin60().CompareLatestDate(GetKDataMin5());
  1191. if(-1 == compare)
  1192. return CKData::Min5ToMin60(GetKDataMin5(), GetKDataMin60());
  1193. else if(1 == compare)
  1194. return GetKDataMin60().GetSize();
  1195. else if(GetKDataMin60().GetSize() * 12 < GetKDataMin5().GetSize())
  1196. return CKData::Min5ToMin60(GetKDataMin5(), GetKDataMin60());
  1197. else
  1198. return GetKDataMin60().GetSize();
  1199. }
  1200. break;
  1201. case CKData::ktypeMin30:
  1202. {
  1203. if(bForced)
  1204. return CKData::Min5ToMin30(GetKDataMin5(), GetKDataMin30());
  1205. int compare = GetKDataMin30().CompareLatestDate(GetKDataMin5());
  1206. if(-1 == compare)
  1207. return CKData::Min5ToMin30(GetKDataMin5(), GetKDataMin30());
  1208. else if(1 == compare)
  1209. return GetKDataMin30().GetSize();
  1210. else if(GetKDataMin30().GetSize() * 6 < GetKDataMin5().GetSize())
  1211. return CKData::Min5ToMin30(GetKDataMin5(), GetKDataMin30());
  1212. else
  1213. return GetKDataMin30().GetSize();
  1214. }
  1215. break;
  1216. case CKData::ktypeMin15:
  1217. {
  1218. if(bForced)
  1219. return CKData::Min5ToMin15(GetKDataMin5(), GetKDataMin15());
  1220. int compare = GetKDataMin15().CompareLatestDate(GetKDataMin5());
  1221. if(-1 == compare)
  1222. return CKData::Min5ToMin15(GetKDataMin5(), GetKDataMin15());
  1223. else if(1 == compare)
  1224. return GetKDataMin15().GetSize();
  1225. else if(GetKDataMin15().GetSize() * 3 < GetKDataMin5().GetSize())
  1226. return CKData::Min5ToMin15(GetKDataMin5(), GetKDataMin15());
  1227. else
  1228. return GetKDataMin15().GetSize();
  1229. }
  1230. break;
  1231. case CKData::ktypeMin5:
  1232. return GetKDataMin5().GetSize();
  1233. default:
  1234. SP_ASSERT(FALSE);
  1235. return 0;
  1236. }
  1237. }
  1238. int CStock::MergeBaseText(CStock &stock)
  1239. {
  1240. if(GetBaseTextLength() > 0)
  1241. return GetBaseTextLength();
  1242. if(stock.GetBaseTextLength() > 0)
  1243. {
  1244. if(AllocBaseTextMem(stock.GetBaseTextLength()))
  1245. strncpy(GetBaseTextPtr(), stock.GetBaseTextPtr(), stock.GetBaseTextLength());
  1246. return stock.GetBaseTextLength();
  1247. }
  1248. return 0;
  1249. }
  1250. int CStock::MergeKData(CStock &stock, int period)
  1251. {
  1252. CKData * pkdata = NULL;
  1253. CKData * pkdata2 = NULL;
  1254. switch(period)
  1255. {
  1256. case CKData::ktypeMonth:
  1257. pkdata = &(GetKDataMonth());
  1258. pkdata2 = &(stock.GetKDataMonth());
  1259. break;
  1260. case CKData::ktypeWeek:
  1261. pkdata = &(GetKDataWeek());
  1262. pkdata2 = &(stock.GetKDataWeek());
  1263. break;
  1264. case CKData::ktypeDay:
  1265. pkdata = &(GetKDataDay());
  1266. pkdata2 = &(stock.GetKDataDay());
  1267. break;
  1268. case CKData::ktypeMin60:
  1269. pkdata = &(GetKDataMin60());
  1270. pkdata2 = &(stock.GetKDataMin60());
  1271. break;
  1272. case CKData::ktypeMin30:
  1273. pkdata = &(GetKDataMin30());
  1274. pkdata2 = &(stock.GetKDataMin30());
  1275. break;
  1276. case CKData::ktypeMin15:
  1277. pkdata = &(GetKDataMin15());
  1278. pkdata2 = &(stock.GetKDataMin15());
  1279. break;
  1280. case CKData::ktypeMin5:
  1281. pkdata = &(GetKDataMin5());
  1282. pkdata2 = &(stock.GetKDataMin5());
  1283. break;
  1284. default:
  1285. SP_ASSERT(FALSE);
  1286. return 0;
  1287. }
  1288. return pkdata->MergeKData(pkdata2);
  1289. }
  1290. int CStock::MergeDRData(CStock &stock)
  1291. {
  1292. if(GetDRData().GetSize() < stock.GetDRData().GetSize())
  1293. GetDRData().Copy(stock.GetDRData());
  1294. return GetDRData().GetSize();
  1295. }
  1296. int CStock::StoreDRData()
  1297. {
  1298. if(m_pDatabase)
  1299. return m_pDatabase->StoreDRData(this);
  1300. return 0;
  1301. }
  1302. void CStock::Clear()
  1303. {
  1304. m_stockinfo.Clear();
  1305. if(m_pBaseText)
  1306. delete [] (CHAR*)m_pBaseText;
  1307. m_nBaseTextLen = 0;
  1308. m_pBaseText = NULL;
  1309. m_kdMonth.Clear();
  1310. m_kdWeek.Clear();
  1311. m_kdDay.Clear();
  1312. m_kdMin60.Clear();
  1313. m_kdMin30.Clear();
  1314. m_kdMin15.Clear();
  1315. m_kdMin5.Clear();
  1316. m_drData.SetSize(0);
  1317. m_report.SetSize(0);
  1318. m_minute.SetSize(0);
  1319. m_outline.SetSize(0);
  1320. SetKDataTypes();
  1321. }
  1322. // 投资家万能引擎证券市场
  1323. /*
  1324. #define  SH_MARKET_EX   'HS'  // 上海证券
  1325. #define  SZ_MARKET_EX   'ZS'  // 深圳证券
  1326. #define  CZ_MARKET_EX   'ZC'  // 郑州商品
  1327. #define  DL_MARKET_EX   'LD'  // 大连商品
  1328. #define  SF_MARKET_EX   'FS'  // 上海商品
  1329. #define  SM_MARKET_EX   'MS'  // 上海金属
  1330. #define  CE_MARKET_EX   'EC'  // 亚洲指数
  1331. #define  CB_MARKET_EX   'BC'  // CBOT
  1332. #define  CC_MARKET_EX   'CC'  // 软商品
  1333. #define  MC_MARKET_EX   'CM'  // C M X
  1334. #define  IM_MARKET_EX   'MI'  // 外汇期货
  1335. #define  LM_MARKET_EX   'ML'  // L M E
  1336. #define  NY_MARKET_EX   'YN'  // NYSE
  1337. #define  AI_MARKET_EX   'IA'  // 亚洲期指
  1338. #define  WH_MARKET_EX   'HW'  // 外汇交易
  1339. #define  XH_MARKET_EX   'HX'  // 欧美指数
  1340. #define  CM_MARKET_EX   'MC'  // C M E
  1341. #define  NF_MARKET_EX   'FN'  // 欧美期指
  1342. #define  NM_MARKET_EX   'MN'  // 石油产品
  1343. #define  LC_MARKET_EX   'CL'  // 巴黎油籽
  1344. #define  LI_MARKET_EX   'IL'  // 马来西亚
  1345. #define  SI_MARKET_EX   'IS'  // 温尼伯格
  1346. #define  HS_MARKET_EX   'SH'  // H S I
  1347. #define  HK_MARKET_EX   'HK'  // 香港股票
  1348. #define  ZJ_MARKET_EX   'JZ'  // ZJFE
  1349. */