static void processListIndices(VTDictionary dict) { int code = dict.getValueInt(kErrorCode); ArrayList arr = dict.getArray(kArray); stShareGroup g = Context.getInstance().vnIndicesGroup; if (g == null) { g = new stShareGroup(); Context.getInstance().vnIndicesGroup = g; g.setType(stShareGroup.ID_GROUP_INDICES); } if (code == 0 & arr != null) { for (int i = 0; i < arr.Count; i++) { VTDictionary d = (VTDictionary)arr[i]; int id = d.getValueInt("id"); String symbol = d.getValueString(kSymbol); float price = d.getValueFloat(kPoint) / 1000.0f; float change = d.getValueFloat(kChanged) / 1000.0f; long vol = d.getValueLong(kVolume); float hi = d.getValueFloat(kHighest) / 1000.0f; float lo = d.getValueFloat(kLowest) / 1000.0f; float reference = d.getValueFloat(kRef) / 1000.0f; stPriceboardState ps = GlobalData.getPriceboardStateOfIndexWithSymbol(symbol); if (ps == null) { ps = new stPriceboardState(); GlobalData.addPriceboardStateOfIndex(ps); } ps.id = id; ps.code = symbol; ps.current_price_1 = price; ps.total_volume = Convert.ToInt32(vol); ps.max = hi; ps.min = lo; ps.change = change; ps.reference = reference; g.addCode(symbol); } } }
void refreshChart2() { if (group == null) { group = new stShareGroup(); group.setType(stShareGroup.ID_GROUP_DEFAULT); } group.clear(); currentSelected = null; Share index = mContext.mShareManager.getShare(mShareID); stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexOfMarket(index.getMarketID()); if (index == null || pi == null) { return; } if (mContext.mShareManager.getVnindexCnt() == 0) { return; } _isProcessing = true; index.loadShareFromFile(false); stCandle cIndex = new stCandle(); index.getCandleByDate(startDate, 0, cIndex); //=============================================== double totalEquity = 0.0; totalIndexInc = 0; totalIndexDec = 0; int cnt = mContext.mShareManager.getVnindexCnt(); double[] indexOfShares = new double[cnt]; double[] changedPercents = new double[cnt]; float[] prices = new float[cnt]; stCandle _c0 = new stCandle(); stCandle _c1 = new stCandle(); // tinh total equity for (int i = 0; i < cnt; i++) { Share share = mContext.mShareManager.getVnindexShareAt(i); if (share.getShareID() == 223) { indexOfShares[i] = 1; } indexOfShares[i] = 0; if (share.getMarketID() == index.getMarketID() && !share.isIndex()) { stCompanyInfo inf = mContext.mShareManager.getCompanyInfo(share.getShareID()); if (inf != null) { share.loadShareFromCommonData(false); share.appendTodayCandle2(); // use last price if today is not trade stCandle c0 = share.getCandleByDate(startDate, 0, _c0); stCandle c1 = share.getCandleByDate(endDate, startDate, _c1); if (c0 == null || c1 == null) { continue; } if (c0.close == 0 || c1.close == 0) { continue; } totalEquity += (inf.volume * c0.close); double changedPercent = (c1.close - c0.close) / c0.close; if (changedPercent < 0) { //changedPercent = changedPercent; } indexOfShares[i] = cIndex.close * (inf.volume * c0.close) * changedPercent; if (changedPercent > 0) { totalIndexInc += changedPercent; } else { totalIndexDec += changedPercent; } //--------- changedPercents[i] = (c1.close - c0.close) * 100 / c0.close; prices[i] = c1.close; } } } // cleanup vChangeDec.removeAllElements(); vChangeInc.removeAllElements(); //==================================== totalIndexInc /= totalEquity; totalIndexDec /= totalEquity; totalIndexInc = 0; totalIndexDec = 0; for (int i = 0; i < cnt; i++) { Share share = mContext.mShareManager.getVnindexShareAt(i); //if (strcmp(share.mCode, "VIC") == 0){ // /i = i; //} double indexChanged = indexOfShares[i] / totalEquity; ChangeIndexItem item; if (indexChanged > 0) { item = new ChangeIndexItem(); item.modifiedValue = (float)indexChanged; totalIndexInc += item.modifiedValue; item.shareID = share.getShareID(); vChangeInc.addElement(item); } else { item = new ChangeIndexItem(); item.modifiedValue = (float)(-indexChanged); totalIndexDec += item.modifiedValue; item.shareID = share.getShareID(); vChangeDec.addElement(item); } item.price = prices[i]; item.modifiedPercent = (float)changedPercents[i]; } // end of calc sortChanges(vChangeInc); sortChanges(vChangeDec); while (vChangeInc.size() > 200) { vChangeInc.removeElementAt(vChangeInc.size() - 1); } while (vChangeDec.size() > 200) { vChangeDec.removeElementAt(vChangeDec.size() - 1); } //--------------- // ChangeIndexItem xVector[] vv = { vChangeInc, vChangeDec }; for (int j = 0; j < 2; j++) { for (int i = 0; i < vv[j].size(); i++) { ChangeIndexItem item = (ChangeIndexItem)vv[j].elementAt(i); Share share = mContext.mShareManager.getShare(item.shareID); if (share != null && share.getCode() != null) { group.addCode(share.getCode()); } } } invalidate(); }