static void evalueSortValueVonhoa(xVector v) { for (int i = 0; i < v.size(); i++) { Share share = (Share)v.elementAt(i); if (share.isIndex()) { share.mSortParam = 0; share.mCompareText = "0"; } else { stCompanyInfo inf = Context.getInstance().mShareManager.getCompanyInfo(share.getShareID()); stPriceboardState ps = Context.getInstance().mPriceboard.getPriceboard(share.getShareID()); if (inf != null && ps != null) { share.mSortParam = inf.volume * ps.current_price_1; double t = share.mSortParam; share.mCompareText = RowNormalShare.valueMToString(t, true); } else { share.mSortParam = 0; share.mCompareText = "0"; } } } }
static void evalueSortValuePE(xVector v) { for (int i = 0; i < v.size(); i++) { Share share = (Share)v.elementAt(i); stCompanyInfo inf = Context.getInstance().mShareManager.getCompanyInfo(share.getShareID()); if (!share.isIndex() && inf != null) { share.mSortParam = inf.PE; share.mCompareText = String.Format("{0:F1}", (inf.PE / 1000.0)); } else { share.mSortParam = 0; share.mCompareText = "0"; } } }
void showQuickInfo(int x, int y) { if (!_showQuickInfo) { return; } try { if (mToolTip == null) { mToolTip = new ToolTip(); } //mToolTip.SetToolTip(getControl(), "Abc asdad asd asd sada"); Object o = getUserData(); String code = null; if (o.GetType() == typeof(stGainloss)) { code = ((stGainloss)o).code; } else if (o.GetType() == typeof(String)) { code = (String)o; } if (code == null) { return; } stPriceboardState item = Context.getInstance().mPriceboard.getPriceboard(code); if (item == null) { return; } stCompanyInfo inf = Context.getInstance().mShareManager.getCompanyInfo(item.id); if (inf != null) { StringBuilder sb = Utils.sb2; sb.Length = 0; sb.Append(inf.company_name); sb.Append("\n"); sb.AppendFormat("EPS={0:F1} K; P/E={1:F1}", ((float)inf.EPS / 1000), ((float)inf.PE / 100)); sb.AppendFormat("; KLCP={0:F2} tr\n", (inf.volume / 1000.0f)); float price = 0; double vonhoa = 0; price = item.getCurrentPrice(); if (price == 0) { price = item.getRef(); } vonhoa = price; vonhoa = vonhoa * inf.volume; vonhoa = vonhoa / 1000; sb.AppendFormat("Vốn hóa tt={0:F2} tỉ", vonhoa); mToolTip.Show(sb.ToString(), getControl(), x, y, 3000); } } catch (Exception e) { } }
void calcChanged(int period) { stCandle c0 = new stCandle(); stCandle c1 = new stCandle(); mChanges.removeAllElements(); Utils.trace("----------------------"); bool isNhomIndex = false; for (int i = 0; i < mGroups.size(); i++) { stShareGroup g = (stShareGroup)mGroups.elementAt(i); GroupChanges gc = new GroupChanges(); gc.group = g; mChanges.addElement(gc); gc.code = g.getName(); Utils.trace(g.getName()); double firstGTGD = 0; double lastGTGD = 0; double totalGTGD0 = 0; double totalGTGD1 = 0; int today = 0; isNhomIndex = false; if (g.getType() == stShareGroup.ID_GROUP_MARKET_OVERVIEW && g.getTotal() == 1) { isNhomIndex = true; String code = g.getCodeAt(0); Share share = mContext.mShareManager.getShare(code); if (share == null) { continue; } share.loadShareFromFile(false); share.appendTodayCandle2(); int last = share.getCandleCnt() - 1; int first = (last > period)?(last - period):0; if (last < 0 || first < 0) { continue; } c0 = share.getCandle(last, c0); c1 = share.getCandle(first, c1); if (c1.close > 0) { double changed = 100 * (c0.close - c1.close) / c1.close; gc.changedPercent += changed; } continue; } for (int j = 0; j < g.getTotal(); j++) { string code = g.getCodeAt(j); Share share = Context.getInstance().mShareManager.getShare(code); int shareID = Context.getInstance().mShareManager.getShareID(code); stCompanyInfo info = Context.getInstance().mShareManager.getCompanyInfo(shareID); if (share != null && info != null) { share.loadShareFromCommonData(true); int last = share.getCandleCnt() - 1; int first = (last > period)?(last - period):0; if (last < 0 || first < 0) { continue; } share.getCandle(last, c0); share.getCandle(first, c1); double changed; if (period == 1 && c0.date < today) { // khong co giao dich hom nay changed = 0; } else { double r = (info.volume * c1.close); changed = 0;// (c0.close - c1.close) * r; changed = 100 * (c0.close - c1.close) / c1.close; changed *= r; } totalGTGD0 += (c0.close * info.volume); totalGTGD1 += (c1.close * info.volume); gc.changedPercent += changed; //String s = String.Format("Code: {0}, Price: Close0/Close1={1}/{2}, r={3} changed/totalChanged: {4}/{5}", //share.getCode(), c0.close, c1.close, r, changed, gc.changedPercent); //Utils.trace(s); } gc.changedPercent = 100 * (totalGTGD0 - totalGTGD1); gc.changedPercent /= totalGTGD1; } //Utils.trace(String.Format("Total changed: {0}", gc.changedPercent)); } // sort if (false)//isNhomIndex) { // khong sort } else { xVector marketOverView = new xVector(); for (int i = 0; i < mChanges.size() - 1; i++) { GroupChanges g = (GroupChanges)mChanges.elementAt(i); if (g.group.getType() == stShareGroup.ID_GROUP_MARKET_OVERVIEW || g.code.IndexOf('#') == 0) { marketOverView.addElement(g); } } for (int i = 0; i < marketOverView.size(); i++) { mChanges.removeElement(marketOverView.elementAt(i)); } //================================ for (int i = 0; i < mChanges.size() - 1; i++) { GroupChanges biggest = (GroupChanges)mChanges.elementAt(i); int biggestIdx = i; for (int j = i + 1; j < mChanges.size(); j++) { GroupChanges gc = (GroupChanges)mChanges.elementAt(j); if (gc.changedPercent > biggest.changedPercent) { biggest = gc; biggestIdx = j; } } if (biggestIdx != i) { mChanges.swap(i, biggestIdx); } } //======================== for (int i = 0; i < mChanges.size(); i++) { marketOverView.addElement(mChanges.elementAt(i)); } mChanges.removeAllElements(); for (int i = 0; i < marketOverView.size(); i++) { mChanges.addElement(marketOverView.elementAt(i)); } } }
public void refreshChart(int martketID) { rx = (float)(getW() - 10) / mMapW; ry = (float)(getH() - 15) / mMapH; // block data int total = 1000; int i = 0; for (i = 0; i < mUsedBlocks.size(); i++) { stBubbleBlock b = (stBubbleBlock)mUsedBlocks.elementAt(i); b.x = 0; b.y = 0; mFreeBlocks.addElement(b); } // reset mUsedBlocks.removeAllElements(); for (i = 0; i < mMapH; i++) { for (int j = 0; j < mMapW; j++) { mMap[map(i, j)] = 0; } } //-------------------------------------- //xVector v = mContext.mShareManager.getCompanyInfos(); double totalEquity = 0.0f; double totalIndexInc = 0; double totalIndexDec = 0; stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexOfMarket(martketID); int shareCount = mContext.mShareManager.getTotalShareIDCount(); // calc totalEquity int[] market = { 0 }; for (i = 0; i < shareCount; i++) { int shareID = mContext.mShareManager.getShareIDAt(i, market); stCompanyInfo inf = mContext.mShareManager.getCompanyInfo(shareID); if (inf != null && inf.floor == martketID) { stPriceboardState priceboard = mContext.mPriceboard.getPriceboard(inf.shareID); if (priceboard != null) { double ff = priceboard.getCurrentPrice(); // avoiding of overstack if (mChartType == BUBBLE_TRADE_MONEY) { totalEquity += ff * priceboard.getTotalVolume(); } else if (mChartType == BUBBLE_VOLUME_WEIGHT || mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC || mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC) { totalEquity += ((double)inf.volume * ff); } } } } // extra for (i = 0; i < shareCount; i++) { int shareID = mContext.mShareManager.getShareIDAt(i, market); stCompanyInfo inf = mContext.mShareManager.getCompanyInfo(shareID); if (inf != null && inf.floor == martketID) { stPriceboardState priceboard = mContext.mPriceboard.getPriceboard(inf.shareID); if (priceboard != null) { double ff = priceboard.getCurrentPrice(); // avoiding of overstack if (mChartType == BUBBLE_TRADE_MONEY) { } else if (mChartType == BUBBLE_VOLUME_WEIGHT || mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC || mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC) { if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC && priceboard.change > 0) { double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity); double indexChanged = priceboard.change * indexPointOfShare / priceboard.current_price_1; totalIndexInc += 1.2f * indexChanged; } else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC && priceboard.change < 0) { double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity); double indexChanged = priceboard.change * indexPointOfShare / priceboard.current_price_1; totalIndexDec += -1.2f * indexChanged; } } } } } if (totalEquity == 0.0) { return; } double squareOfCell = 1.0 / (mMapW * mMapH); double tmp = 0; // now calc blocks for (i = 0; i < shareCount; i++) { int shareID = mContext.mShareManager.getShareIDAt(i, market); stCompanyInfo inf = mContext.mShareManager.getCompanyInfo(shareID); if (inf != null && inf.floor == martketID) { stPriceboardState priceboard = mContext.mPriceboard.getPriceboard(inf.shareID);//martketID, share.mShareID); if (priceboard != null) { String code = mContext.mShareManager.getShareCode(inf.shareID); if (code != null && (code.CompareTo("MSN") == 0 || code.CompareTo("MBB") == 0)) { Utils.trace("aaa"); } double equity = 0.0f; double ff = priceboard.getCurrentPrice(); // avoiding of overstack float threshold = 0.003f; if (mChartType == BUBBLE_TRADE_MONEY) { equity = ff * priceboard.getTotalVolume(); } else if (mChartType == BUBBLE_VOLUME_WEIGHT) { equity = ((double)inf.volume * ff); } else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC) { double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity); double indexChanged = priceboard.change * indexPointOfShare / priceboard.current_price_1; equity = indexChanged; threshold = 0.00001f; } else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC) { double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity); double indexChanged = priceboard.change * indexPointOfShare / priceboard.current_price_1; equity = -indexChanged; threshold = 0.00001f; } float percent = (float)(equity / totalEquity); // <= 1 if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC || mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC) { percent = (float)(equity / (double)pi.current_point); //percent = (float)(equity/totalEquityOfUsedBlock); } if (percent >= threshold && mFreeBlocks.size() > 0) { // big enough to care float percentR = percent; if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC) { percentR = (float)(equity / totalIndexInc); } else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC) { percentR = (float)(equity / totalIndexDec); } float square = percentR * (mMapH * mMapW); float cells = square; if (cells < 1) { cells = 1; } stBubbleBlock block = (stBubbleBlock)mFreeBlocks.pop(); block.code = mContext.mShareManager.getShareCode(inf.shareID);; // w & h block.w = (short)Math.Sqrt(cells); block.h = block.w; if (block.h * block.w < cells) { block.w++; } if (block.h >= 50) { int k = 0; } // color uint color = C.COLOR_YELLOW; float price = priceboard.getCurrentPrice(); float reference = priceboard.getRef(); if (price == reference) { color = C.COLOR_YELLOW; } else if (price == priceboard.getCe()) { color = C.COLOR_MAGENTA; } else if (price == priceboard.getFloor()) { color = C.COLOR_CYAN; } else if (price < reference) { int r = (int)((reference - price) * 100 / reference); // percent if (r < 8) { r = (0xff - 150) + r * 30; } else { r = 0xff; } if (r > 0xff) { r = 0xff; } //--------------- r = 0xff; color = (uint)((0xff << 24) | (r << 16)); } else if (price > reference) { int g = (int)((price - reference) * 100 / reference); // percent if (g < 8) { g = (0xff - 150) + g * 30; } else { g = 0xff; } if (g > 0xff) { g = 0xff; } //---------------- g = 0xff; color = (uint)((0xff << 24) | (g << 8)); } block.color = color; // point block.point = (short)(percent * 1000);//(priceboard.current_price_1 - priceboard.ref)*1000/priceboard.ref; // x & y //setBlockPosition(block); // extra inf StringBuilder sb = Utils.sb; sb.Length = 0; if (mChartType == BUBBLE_TRADE_MONEY) { sb.AppendFormat("{0:F1}tỉ", (equity / 1000000)); // money unit = 100 vnd } else if (mChartType == BUBBLE_VOLUME_WEIGHT) { sb.AppendFormat("{0:F1}%", (percent * 100)); } else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC) { double r = (inf.volume * price) / totalEquity; // totalE = pi.point // vonhoa = ? // index-point of code: (r*pi.point); // price <> (r*pi.point) // changed <> ? double indexChanged = (priceboard.change * r * pi.current_point) / priceboard.current_price_1; tmp += indexChanged; sb.AppendFormat("{0:F4}", (indexChanged)); } else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC) { double r = (inf.volume * price) / totalEquity; double indexChanged = (priceboard.change * r * pi.current_point) / priceboard.current_price_1; sb.AppendFormat("{0:F4}", (indexChanged)); } block.inf = sb.ToString(); if (priceboard.getCode() == "ACB") { int k = 0; } // changed sb.Length = 0; if (reference != 0) { float changed = price - reference; if (changed > 0) { sb.AppendFormat("+{0:F2}%", (float)((changed * 100) / reference)); } else { sb.AppendFormat("{0:F2}%", (float)((changed * 100) / reference)); } } block.changed = sb.ToString(); mUsedBlocks.addElement(block); } } } }// end of for sortBlocks(); }
void createFullDesc() { Font f; xLabel l; int x = 2; int y = 8; int w = getW(); String s; stCompanyInfo inf = mContext.mShareManager.getCompanyInfo(mShareID); if (inf == null) { return; } mShowCompanyName = true; if (mShowCompanyName) { f = mContext.getFontTextB(); l = xLabel.createMultiLineLabel(inf.company_name, f, getW()); addControl(l); l.setTextColor(mFontColor); y = l.getBottom() + 10; } StringBuilder sb = Utils.sb; sb.Length = 0; f = mContext.getFontSmall();// Text(); //if (mFont != null) // f = mFont; // EPS sb.AppendFormat("EPS: {0:F1} K", (float)(inf.EPS) / 1000); l = xLabel.createSingleLabel(sb.ToString(), f, w); l.setPosition(x, y); l.setTextColor(mFontColor); addControl(l); y = l.getBottom(); // P/E sb.Length = 0; sb.AppendFormat("P/E: {0:F1}", (float)inf.PE / 100); l = xLabel.createSingleLabel(sb.ToString(), f, w); l.setPosition(x, y); l.setTextColor(mFontColor); addControl(l); y = l.getBottom(); // Beta sb.Length = 0; sb.AppendFormat("Beta: {0:F2}", (float)inf.Beta / 100); l = xLabel.createSingleLabel(sb.ToString(), f, w); l.setPosition(x, y); l.setTextColor(mFontColor); addControl(l); y = l.getBottom(); // book value sb.Length = 0; sb.AppendFormat("Giá sổ sách: {0:F1} K", (float)(inf.book_value / 10)); l = xLabel.createSingleLabel(sb.ToString(), f, w); l.setPosition(x, y); l.setTextColor(mFontColor); addControl(l); y = l.getBottom(); // KLTB 10 phien sb.Length = 0; Share share = mContext.mShareManager.getShare(mShareID); if (share == null) { return; } int cnt = share.getCandleCount(); int nums = cnt > 10 ? 10 : cnt; int total = 0; for (int i = 0; i < nums; i++) { int volume = share.getVolume(cnt - i - 1); total += volume; } if (nums == 0) { nums = 1; } total = total / nums; s = Utils.formatNumber((int)total); sb.Length = 0; sb.AppendFormat("Vol TB 10 phiên={0}", s); l = xLabel.createSingleLabel(sb.ToString(), f, w); l.setPosition(x, y); l.setTextColor(mFontColor); addControl(l); y = l.getBottom(); // KLCP luu hanh sb.Length = 0; sb.AppendFormat("KL lưu hành: {0:F2} tr; ", (inf.volume / 1000.0f)); l = xLabel.createSingleLabel(sb.ToString(), f, w); l.setPosition(x, y); l.setTextColor(mFontColor); addControl(l); y = l.getBottom(); // Von hoa tt stPriceboardState ps = mContext.mPriceboard.getPriceboard(mShareID); float price = 0; double vonhoa = 0; if (ps != null) { price = ps.getCurrentPrice(); if (price == 0) { price = ps.getRef(); } vonhoa = price; vonhoa = vonhoa * inf.volume; vonhoa = vonhoa / 1000; } else { } sb.Length = 0; sb.AppendFormat("Vốn hóa: {0:F2} tỉ", vonhoa); l = xLabel.createSingleLabel(sb.ToString(), f, w); l.setPosition(x, y); l.setTextColor(mFontColor); addControl(l); y = l.getBottom(); // ROA sb.Length = 0; sb.AppendFormat("ROA: {0:F1} %", (float)inf.ROA); l = xLabel.createSingleLabel(sb.ToString(), f, w); l.setPosition(x, y); l.setTextColor(mFontColor); addControl(l); y = l.getBottom(); // ROE sb.Length = 0; sb.AppendFormat("ROE: {0:F1} %", (float)inf.ROE); l = xLabel.createSingleLabel(sb.ToString(), f, w); l.setPosition(x, y); l.setTextColor(mFontColor); addControl(l); setSize(getW(), l.getBottom()); }
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(); }
private void refreshChart(int martketID) { // block data int total = 1000; int i = 0; if (getW() == 0 || getH() == 0) { return; } for (i = 0; i < mUsedBlocks.size(); i++) { stStatisticsBlock b = (stStatisticsBlock)mUsedBlocks.elementAt(i); mFreeBlocks.addElement(b); } // reset mUsedBlocks.removeAllElements(); //-------------------------------------- int shareCount = mContext.mShareManager.getTotalShareIDCount(); int[] market = { 0 }; double totalEquity = 0.0f; double totalIndexInc = 0; double totalIndexDec = 0; stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexOfMarket(martketID); // calc totalEquity for (i = 0; i < shareCount; i++) { int shareID = mContext.mShareManager.getShareIDAt(i, market); stCompanyInfo inf = mContext.mShareManager.getCompanyInfo(shareID); if (inf != null && inf.floor == martketID) { stPriceboardState priceboard = mContext.mPriceboard.getPriceboard(inf.shareID); if (priceboard != null) { double ff = priceboard.getCurrentPrice(); // avoiding of overstack if (mChartType == BUBBLE_TRADE_MONEY) { totalEquity += ff * priceboard.getTotalVolume(); } else if (mChartType == BUBBLE_VOLUME_WEIGHT || mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC || mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC) { totalEquity += ((double)inf.volume * ff); } } } } // extra for (i = 0; i < shareCount; i++) { int shareID = mContext.mShareManager.getShareIDAt(i, market); stCompanyInfo inf = mContext.mShareManager.getCompanyInfo(shareID); if (inf != null && inf.floor == martketID) { stPriceboardState priceboard = mContext.mPriceboard.getPriceboard(inf.shareID); if (priceboard != null) { double ff = priceboard.getCurrentPrice(); // avoiding of overstack if (mChartType == BUBBLE_TRADE_MONEY) { } else if (mChartType == BUBBLE_VOLUME_WEIGHT || mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC || mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC) { if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC && priceboard.change > 0) { double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity); double indexChanged = priceboard.change * indexPointOfShare / priceboard.current_price_1; totalIndexInc += 1.2f * indexChanged; } else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC && priceboard.change < 0) { double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity); double indexChanged = priceboard.change * indexPointOfShare / priceboard.current_price_1; totalIndexDec += -1.2f * indexChanged; } } } } } if (totalEquity == 0.0) { return; } double tmp = 0; StringBuilder sb = new StringBuilder(); // now calc blocks for (i = 0; i < shareCount; i++) { int shareID = mContext.mShareManager.getShareIDAt(i, market); stCompanyInfo inf = mContext.mShareManager.getCompanyInfo(shareID); if (inf != null && inf.floor == martketID) { stPriceboardState priceboard = mContext.mPriceboard.getPriceboard(inf.shareID);//martketID, share.mShareID); if (priceboard != null) { String code = mContext.mShareManager.getShareCode(inf.shareID); //if (code != null && (code.CompareTo("MSN") == 0 || code.CompareTo("AAM") == 0)) //{ //Utils.trace("aaa"); //} double modifierValue = 0.0f; double ff = priceboard.getCurrentPrice(); // avoiding of overstack //String log = String.Format("{0}, {1}, {2}, {3}", code, priceboard.current_price_1, inf.volume, totalEquity); //Utils.trace(log); float threshold = 0.003f; if (mChartType == BUBBLE_TRADE_MONEY) { modifierValue = ff * priceboard.getTotalVolume(); } else if (mChartType == BUBBLE_VOLUME_WEIGHT) { modifierValue = ((double)inf.volume * ff); } else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC) { double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity); double indexChanged = priceboard.change * indexPointOfShare / priceboard.current_price_1; modifierValue = indexChanged; threshold = 0.000001f; } else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC) { double indexPointOfShare = pi.current_point * ((inf.volume * ff) / totalEquity); double indexChanged = priceboard.change * indexPointOfShare / priceboard.current_price_1; modifierValue = -indexChanged; threshold = 0.000001f; } float percent = (float)(modifierValue / totalEquity); // <= 1 if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC || mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC) { percent = (float)(modifierValue / (double)pi.current_point); } //String log = String.Format("{0}, {1}, {2}, {3}, {4}, {5}", code, priceboard.current_price_1, inf.volume //, totalEquity, modifierValue, pi.current_point); //Utils.trace(log); if (percent >= threshold && mFreeBlocks.size() > 0) { // big enough to care float value = percent; if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC) { percent *= 100;// (float)(equity / totalIndexInc); } else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC) { percent *= 100;// (float)(equity / totalIndexDec); } stStatisticsBlock block = (stStatisticsBlock)mFreeBlocks.pop(); block.code = mContext.mShareManager.getShareCode(inf.shareID);; // w & h //block.w = (short)Math.Sqrt(cells); //block.h = block.w; //if (block.h * block.w < cells) block.w++; //if (block.h >= 50) //{ //int k = 0; //} // color uint color = C.COLOR_YELLOW; float price = priceboard.getCurrentPrice(); float reference = priceboard.getRef(); if (price == reference) { color = C.COLOR_YELLOW; } else if (price == priceboard.getCe()) { color = C.COLOR_MAGENTA; } else if (price == priceboard.getFloor()) { color = C.COLOR_CYAN; } else if (price < reference) { int r = (int)((reference - price) * 100 / reference); // percent if (r < 8) { r = (0xff - 150) + r * 30; } else { r = 0xff; } if (r > 0xff) { r = 0xff; } //--------------- r = 0xff; color = (uint)((0xff << 24) | (r << 16)); } else if (price > reference) { int g = (int)((price - reference) * 100 / reference); // percent if (g < 8) { g = (0xff - 150) + g * 30; } else { g = 0xff; } if (g > 0xff) { g = 0xff; } //---------------- g = 0xff; color = (uint)((0xff << 24) | (g << 8)); } block.color = color; // point block.point = (short)(percent * 1000);//(priceboard.current_price_1 - priceboard.ref)*1000/priceboard.ref; // x & y //setBlockPosition(block); // extra inf sb.Length = 0; if (mChartType == BUBBLE_TRADE_MONEY) { sb.AppendFormat("{0:F1}tỉ", (modifierValue / 1000000)); // money unit = 100 vnd } else if (mChartType == BUBBLE_VOLUME_WEIGHT) { sb.AppendFormat("{0:F1}%", (percent * 100)); } else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_INC) { double r = (inf.volume * price) / totalEquity; // totalE = pi.point // vonhoa = ? // index-point of code: (r*pi.point); // price <> (r*pi.point) // changed <> ? double indexChanged = (priceboard.change * r * pi.current_point) / priceboard.current_price_1; tmp += indexChanged; sb.AppendFormat("{0:F4}", (indexChanged)); } else if (mChartType == BUBBLE_INDEX_WEIGHT_RATIO_DEC) { double r = (inf.volume * price) / totalEquity; double indexChanged = (priceboard.change * r * pi.current_point) / priceboard.current_price_1; sb.AppendFormat("{0:F4}", (indexChanged)); } block.inf = sb.ToString(); if (priceboard.getCode() == "GAS") { int k = 0; } // changed sb.Length = 0; if (reference != 0) { float changed = price - reference; if (changed > 0) { sb.AppendFormat("({0:F2}; +{1:F2}%)", price, (float)((changed * 100) / reference)); } else { sb.AppendFormat("({0:F2}; {1:F2}%)", price, (float)((changed * 100) / reference)); } } block.changed = sb.ToString(); //String log = String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}", code, priceboard.current_price_1, inf.volume //, totalEquity, modifierValue, pi.current_point, mUsedBlocks.size()); //Utils.trace(log); mUsedBlocks.addElement(block); } } } }// end of for sortBlocks(); }
static public void _exportGroupToCSV(xVector v, String sortedColumn, String filepath) { String cols = "Market, Symbol, Close, Open, Hi, Lo, Volume, Gia tri GD(vnd), EPS(K), PE, RSI, MFI, KL Niem yet(mil), Von Hoa(bil), Company\n"; //if (sortedColumn != null) //{ //cols = String.Format("Market, Symbol, Close, Open, Hi, Lo, Volume, Gia tri GD, EPS, PE, RSI, MFI, KL Niem yet, Von Hoa, Company", sortedColumn); //} //xFileManager.removeFile(filepath); try{ Encoding encoding = Encoding.GetEncoding("UTF-8"); System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Create); System.IO.StreamWriter writer = new System.IO.StreamWriter(fs, encoding); writer.Write(cols); for (int i = 0; i < v.size(); i++) { Share share = (Share)v.elementAt(i); if (share != null) { stPriceboardState ps = Context.getInstance().mPriceboard.getPriceboard(share.getCode()); if (ps != null & share != null) { share.loadShareFromCommonData(true); if (share.getCandleCnt() < 3) { continue; } if (share.mCode.CompareTo("HPG") == 0) { int t = 0; } String market = "-"; if (ps.getMarketID() == 1) { market = "HSX"; } else if (ps.getMarketID() == 2) { market = "HNX"; } else if (ps.getMarketID() == 3) { market = "UPC"; } share.selectCandle(share.getCandleCnt() - 1); String price = String.Format("{0:F2}", share.getClose()); String open = String.Format("{0:F2}", share.getOpen()); String hi = String.Format("{0:F2}", share.getHighest()); String lo = String.Format("{0:F2}", share.getLowest()); stCompanyInfo inf = Context.getInstance().mShareManager.getCompanyInfo(ps.id); String company = ""; String vonhoa = "0"; if (inf != null) { company = inf.company_name; vonhoa = "" + inf.vontt; } share.calcRSI(0); share.calcMFI(0); double giatriGD = ps.current_price_1 * ps.total_volume; giatriGD *= 1000; // to vnd double vontt = 0; // inf.vontt; if (vontt == 0) { vontt = inf.volume * ps.current_price_1; } vontt /= 1000; // to ti vnd String line = ""; if (false)//sortedColumn != null) { line = String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6:D},{7},{8}\n", market, ps.code, // 0, 1 price, open, hi, lo, // 2, 3, 4, 5 share.getVolume(), share.mCompareText, company ); } else { // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 //Market, Symbol, Close, Open, Hi, Lo, Volume, Gia tri GD, EPS, PE, RSI, MFI, KL Niem yet, Von Hoa, Company line = String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6:D},{7},{8:F2},{9:F2},{10:F1},{11:F1},{12:F1},{13:F1},{14}\n", market, ps.code, // 0, 1 price, open, hi, lo, // 2, 3, 4, 5 share.getVolume(), // 6 giatriGD, // 7 gia tri GD inf.EPS / 1000.0f, // 8: EPS inf.PE / 1000.0f, // 9: PE share.pRSI[share.getCandleCnt() - 1], // 10: RSI share.pMFI[share.getCandleCnt() - 1], // 11: MFI ((double)inf.volume / 1000), // 12: KL niem yet vontt, // 13: von thi truong company ); } writer.Write(line); } } } writer.Close(); } catch (Exception e) { } }