private void dataGrid_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { try { common.controls.baseDataGridView resultDataGrid = this.CurrentDataGridView; if (resultDataGrid == null) { return; } string stockCode = resultTab.SelectedTab.Name; if (resultDataGrid.CurrentRow == null) { return; } AppTypes.TimeRanges timeRange = AppTypes.TimeRangeFromCode(resultDataGrid.Columns[e.ColumnIndex].DataPropertyName); data.baseDS.stockCodeRow stockCodeRow = application.dataLibs.FindAndCache(myDataSet.stockCode, stockCode); if (stockCodeRow == null) { return; } string strategyCode = resultDataGrid.CurrentRow.Cells[0].Value.ToString(); ShowTradeTransactions(stockCodeRow, strategyCode, timeRange, cbTimeScale.myValue); } catch (Exception er) { this.ShowError(er); } }
public bool Find(string code, bool ShowSelectionIfNotFound) { try { selectedDataRow = null; investorSource.Filter = ""; code = code.Trim(); if (code != "") { investorSource.DataSource = DataAccess.Libs.GetInvestor_ByCode(code); if (investorSource.Count > 0) { selectedDataRow = (data.baseDS.stockCodeRow)(((DataRowView)investorSource.Current).Row); return true; } if (!ShowSelectionIfNotFound) return false; } LoadData(); this.ShowDialog(); return (this.selectedDataRow != null); } catch (Exception er) { this.ShowError(er); } return false; }
private void openMenuItem_Click(object sender, EventArgs e) { try { common.controls.baseDataGridView resultDataGrid = this.CurrentDataGridView; if (resultDataGrid == null) { return; } string stockCode = resultTab.SelectedTab.Name; data.baseDS.stockCodeRow stockCodeRow = application.dataLibs.FindAndCache(myDataSet.stockCode, stockCode); if (stockCodeRow != null) { return; } AppTypes.TimeRanges timeRange = AppTypes.TimeRangeFromCode(resultDataGrid.Columns[resultDataGrid.ColumnCount - 1].Name); ShowStock(stockCodeRow, timeRange, cbTimeScale.myValue); } catch (Exception er) { this.ShowError(er); } }
public bool Find(string code, bool ShowSelectionIfNotFound) { try { selectedDataRow = null; investorSource.Filter = ""; code = code.Trim(); if (code != "") { investorSource.DataSource = DataAccess.Libs.GetInvestor_ByCode(code); if (investorSource.Count > 0) { selectedDataRow = (data.baseDS.stockCodeRow)(((DataRowView)investorSource.Current).Row); return(true); } if (!ShowSelectionIfNotFound) { return(false); } } LoadData(); this.ShowDialog(); return(this.selectedDataRow != null); } catch (Exception er) { this.ShowError(er); } return(false); }
public static data.baseDS.stockCodeRow UpdateData(data.baseDS.stockCodeRow row) { data.baseDS.stockCodeDataTable tbl = new data.baseDS.stockCodeDataTable(); tbl.ImportRow(row); myClient.UpdateStock(ref tbl); row.AcceptChanges(); return(tbl[0]); }
protected override void UpdateData(DataRow row) { if (row == null) { return; } data.baseDS.stockCodeRow stockCodeRow = (myMasterSource.Current as DataRowView).Row as data.baseDS.stockCodeRow; stockCodeRow.ItemArray = DataAccess.Libs.UpdateData(row as data.baseDS.stockCodeRow).ItemArray; stockCodeRow.AcceptChanges(); }
private void ShowEstimationForm(data.baseDS.stockCodeRow stockCodeRow, data.baseDS.strategyRow strategyRow, AppTypes.TimeScale timeScale, DateTime frDate, DateTime toDate) { Data data = new Data(frDate, toDate, timeScale, stockCodeRow.code); Analysis.AnalysisResult advices = appHub.strategy.TradeAnalysis(data, strategyRow.code); if (advices != null) { myAdviceEstimateForm.Init(data, advices); myAdviceEstimateForm.ShowForm(); } }
private void selectBtn_Click(object sender, EventArgs e) { if (investorSource.Current == null) { selectedDataRow = null; } else { selectedDataRow = (data.baseDS.stockCodeRow)(((DataRowView)investorSource.Current).Row); } this.Close(); }
private void ShowChart() { if (this.myOnShowChart == null || portfolioListSource.Current == null) { return; } string stockCode = ((data.tmpDS.portfolioListRow)((DataRowView)portfolioListSource.Current).Row).stockCode.Trim(); data.baseDS.stockCodeRow stockRow = dataLibs.FindAndCache(myDataSet.stockCode, stockCode); if (stockRow == null) { return; } myOnShowChart(stockRow); }
protected override void RemoveCurrent() { this.ShowMessage(""); if (myMasterSource.Current == null) { return; } data.baseDS.stockCodeRow row = (data.baseDS.stockCodeRow)(myMasterSource.Current as DataRowView).Row; if (row.HasVersion(DataRowVersion.Original)) { DataAccess.Libs.DeleteData(row); } myMasterSource.RemoveCurrent(); this.ShowMessage(Languages.Libs.GetString("dataWasDeleted")); }
private void profitEstimateMenu_Click(object sender, EventArgs e) { try { common.controls.baseDataGridView resultDataGrid = this.CurrentDataGridView; if (resultDataGrid == null) { return; } string stockCode = resultTab.SelectedTab.Name; string strategyCode = ""; data.baseDS.stockCodeRow stockCodeRow = application.dataLibs.FindAndCache(myDataSet.stockCode, stockCode); if (stockCodeRow == null) { return; } if (resultDataGrid.SelectedRows.Count > 0) { for (int rowId = 0; rowId < resultDataGrid.SelectedRows.Count; rowId++) { strategyCode = resultDataGrid.SelectedRows[rowId].Cells[0].Value.ToString(); for (int idx = 1; idx < resultDataGrid.ColumnCount; idx++) { AppTypes.TimeRanges timeRange = AppTypes.TimeRangeFromCode(resultDataGrid.Columns[idx].DataPropertyName); ShowTradeTransactions(stockCodeRow, strategyCode, timeRange, cbTimeScale.myValue); } } } else { if (resultDataGrid.CurrentRow != null) { strategyCode = resultDataGrid.CurrentRow.Cells[0].Value.ToString(); for (int idx = 1; idx < resultDataGrid.ColumnCount; idx++) { AppTypes.TimeRanges timeRange = AppTypes.TimeRangeFromCode(resultDataGrid.Columns[idx].DataPropertyName); ShowTradeTransactions(stockCodeRow, strategyCode, timeRange, cbTimeScale.myValue); } } } } catch (Exception er) { this.ShowError(er); } }
public static data.baseDS.stockCodeRow FindAndCache(data.baseDS.stockCodeDataTable tbl, string code) { data.baseDS.stockCodeRow row = tbl.FindBycode(code); if (row != null) { return(row); } data.baseDSTableAdapters.stockCodeTA dataTA = new data.baseDSTableAdapters.stockCodeTA(); dataTA.ClearBeforeFill = false; dataTA.FillByCode(tbl, code); row = tbl.FindBycode(code); if (row != null) { return(row); } return(null); }
public override void AddNew(string code) { data.baseDS.stockCodeRow lastRow = (data.baseDS.stockCodeRow)((DataRowView)myMasterSource.Current).Row; data.baseDS.stockCodeRow row = (data.baseDS.stockCodeRow)((DataRowView)myMasterSource.AddNew()).Row; if (row == null) { return; } commonClass.AppLibs.InitData(row); row.code = code; if (lastRow != null) { row.stockExchange = lastRow.stockExchange; } int position = myMasterSource.Position; myMasterSource.Position = -1; myMasterSource.Position = position; SetFirstFocus(); }
public static void InitData(data.baseDS.stockCodeRow row) { row.code = ""; row.tickerCode = ""; row.stockExchange = ""; row.name = ""; row.address1 = ""; row.email = ""; row.website = ""; row.phone = ""; row.fax = ""; row.country = Settings.sysDefaultCountry; row.bizSectors = ""; row.regDate = DateTime.Today; row.capitalUnit = Settings.sysMainCurrency; row.workingCap = 0; row.equity = 0; row.totalDebt = 0; row.totaAssets = 0; row.noOutstandingStock = 0; row.noListedStock = 0; row.noTreasuryStock = 0; row.noForeignOwnedStock = 0; row.bookPrice = 0; row.targetPrice = 0; row.targetPriceVariant = 0; row.sales = 0; row.profit = 0; row.equity = 0; row.totalDebt = 0; row.totaAssets = 0; row.PB = 0; row.EPS = 0; row.PE = 0; row.ROA = 0; row.ROE = 0; row.BETA = 0; row.status = (byte)AppTypes.CommonStatus.Enable; }
private void dataGrid_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (testResultDataGrid.CurrentRow == null) { return; } string stockCode = testResultDataGrid.CurrentRow.Cells[0].Value.ToString(); if (e.ColumnIndex == 0) { ShowAnalysisForm(stockCode, dateRangeEd); return; } string strategyCode = strategyClb.myCheckedValues[e.ColumnIndex - 1]; data.baseDS.strategyRow strategyRow = application.dataLibs.FindAndCache(myDataSet.strategy, strategyCode); data.baseDS.stockCodeRow stockCodeRow = application.dataLibs.FindAndCache(myDataSet.stockCode, stockCode); ShowEstimationForm(stockCodeRow, strategyRow, dateRangeEd.myTimeScale, dateRangeEd.frDate, dateRangeEd.toDate); } catch (Exception er) { this.ShowError(er); } }
private void selectBtn_Click(object sender, EventArgs e) { if (investorSource.Current == null) selectedDataRow =null; else selectedDataRow = (data.baseDS.stockCodeRow)(((DataRowView)investorSource.Current).Row); this.Close(); }
public static void DeleteData(data.baseDS.stockCodeRow row) { myClient.DeleteStock(row.code); }
/// <summary> /// Estimate the profit from advices produced by analysis process. /// The function will produce a list of "transactions" assuming to be done from analysis advices. /// </summary> /// <param name="data"> Data used for analysis </param> /// <param name="tradePoints">Trade point list generated by analysis process</param> /// <param name="options">User- specific options : captital, max Buy...</param> /// <param name="returnObj">Returned object </param> /// <param name="afterEachEstimationFunc">Call-back function at the end of each tradepoind estimation</param> /// <param name="afterEstimationFunc">Call-back function at the end of estimation process</param> /// public static void EstimateTrading(AnalysisData data, TradePointInfo[] tradePoints, EstimateOptions options, object returnObj, AfterEachEstimationFunc afterEachEstimationFunc, AfterEstimationFunc afterEstimationFunc) { EstimationData myEstimationData = new EstimationData(); global::data.baseDS.stockExchangeRow marketRow = application.AppLibs.GetStockExchange(data.DataStockCode); decimal initCapAmt = options.TotalCapAmt * options.MaxBuyAmtPerc / 100; decimal priceWeight = marketRow.priceRatio; decimal feePerc = marketRow.tranFeePerc / 100; short buy2SellInterval = marketRow.minBuySellDay; data.baseDS.stockCodeRow stockCodeRow = application.SysLibs.FindAndCache_StockCode(data.DataStockCode); if (stockCodeRow == null) { return; } int adviceDataIdx, lastBuyId = -1; decimal stockQty = 0, qty; decimal maxBuyQty = (decimal)(stockCodeRow.noOutstandingStock * options.MaxBuyQtyPerc / 100); decimal stockAmt = 0, stockPrice = 0, amt, feeAmt, totalFeeAmt = 0; decimal cashAmt = initCapAmt; DateTime transDate = common.Consts.constNullDate;; for (int idx = 0; idx < tradePoints.Length; idx++) { adviceDataIdx = tradePoints[idx].DataIdx; qty = 0; amt = 0; myEstimationData.ignored = false; AppTypes.TradeActions action = tradePoints[idx].TradeAction; stockPrice = (decimal)data.Close[adviceDataIdx]; transDate = DateTime.FromOADate(data.DateTime[adviceDataIdx]); switch (action) { case AppTypes.TradeActions.Buy: //Assume that we can only buy if we have money qty = (stockPrice == 0 ? 0 : Math.Floor(cashAmt / ((stockPrice * priceWeight) * (1 + feePerc)))); if (qty > maxBuyQty) { qty = maxBuyQty; } if (qty != 0) { amt = qty * stockPrice * priceWeight; stockAmt += amt; stockQty += qty; feeAmt = Math.Round(amt * feePerc, 0); cashAmt -= amt + feeAmt; totalFeeAmt += feeAmt; lastBuyId = adviceDataIdx; } else { myEstimationData.ignored = true; } break; case AppTypes.TradeActions.Sell: //Can sell if own some stock if (stockQty <= 0) { myEstimationData.ignored = true; break; } // Not applicable to sell if (lastBuyId < 0) { myEstimationData.ignored = true; break; } // T+4 contrainst ? if (common.dateTimeLibs.DateDiffInDays(DateTime.FromOADate(data.DateTime[lastBuyId]).Date, DateTime.FromOADate(data.DateTime[adviceDataIdx]).Date) < buy2SellInterval) { // Keep inapplicable Sells ?? if (commonClass.Settings.sysKeepInApplicableSell) { int transDataIdx = -1; DateTime minAllowSellDate = DateTime.FromOADate(data.DateTime[lastBuyId]).Date.AddDays(buy2SellInterval); //If it is the last trade point, find the next applicable date if (idx >= tradePoints.Length - 1) { transDataIdx = FindDateIdx(data, tradePoints[idx].DataIdx + 1, data.DateTime.Count - 1, minAllowSellDate); } else { //If the next trade point is before or at [minAllowSellDate], ignore this if (DateTime.FromOADate(data.DateTime.Values[tradePoints[idx + 1].DataIdx]).Date <= minAllowSellDate) { myEstimationData.ignored = true; } else { //Find the next applicable date after this point and before next point transDataIdx = FindDateIdx(data, tradePoints[idx].DataIdx + 1, tradePoints[idx + 1].DataIdx - 1, minAllowSellDate); } } if (transDataIdx < 0) { myEstimationData.ignored = true; } else { stockPrice = (decimal)data.Close[transDataIdx]; transDate = DateTime.FromOADate(data.DateTime[transDataIdx]).Date; } } else { myEstimationData.ignored = true; } } //Ok, sell it if (!myEstimationData.ignored) { qty = stockQty; amt = qty * stockPrice * priceWeight; stockQty = 0; stockAmt = 0; feeAmt = Math.Round(amt * feePerc, 0); cashAmt += amt - feeAmt; totalFeeAmt += feeAmt; } break; } myEstimationData.tradeAction = action.ToString(); myEstimationData.onDate = transDate; myEstimationData.price = stockPrice; myEstimationData.qty = qty; myEstimationData.amt = amt; myEstimationData.feeAmt = totalFeeAmt; myEstimationData.ownedQty = stockQty; myEstimationData.ownedAmt = stockAmt; myEstimationData.cashAmt = cashAmt; myEstimationData.profitAmt = cashAmt + stockAmt - initCapAmt; if (afterEachEstimationFunc != null) { afterEachEstimationFunc(myEstimationData, returnObj); } } if (afterEstimationFunc != null) { afterEstimationFunc(myEstimationData, returnObj); } }