Example #1
0
 protected override void UpdateData(DataRow row)
 {
     if (row == null)
     {
         return;
     }
     databases.baseDS.stockCodeRow stockCodeRow = (myMasterSource.Current as DataRowView).Row as databases.baseDS.stockCodeRow;
     stockCodeRow.ItemArray = DataAccess.Libs.UpdateData(row as databases.baseDS.stockCodeRow).ItemArray;
     stockCodeRow.AcceptChanges();
 }
Example #2
0
 protected override void RemoveCurrent()
 {
     this.ShowMessage("");
     if (myMasterSource.Current == null)
     {
         return;
     }
     databases.baseDS.stockCodeRow row = (databases.baseDS.stockCodeRow)(myMasterSource.Current as DataRowView).Row;
     if (row.HasVersion(DataRowVersion.Original))
     {
         DataAccess.Libs.DeleteData(row);
     }
     base.RemoveCurrent();
 }
Example #3
0
 public static databases.baseDS.stockCodeRow FindAndCache_StockCode(string code)
 {
     databases.baseDS.stockCodeRow row = myCachedDS.stockCode.FindBycode(code);
     if (row != null)
     {
         return(row);
     }
     databases.baseDSTableAdapters.stockCodeTA dataTA = new databases.baseDSTableAdapters.stockCodeTA();
     dataTA.ClearBeforeFill = false;
     dataTA.FillByCode(myCachedDS.stockCode, code);
     row = myCachedDS.stockCode.FindBycode(code);
     if (row != null)
     {
         return(row);
     }
     return(null);
 }
Example #4
0
        public override void AddNew(string code)
        {
            databases.baseDS.stockCodeRow lastRow = (databases.baseDS.stockCodeRow)((DataRowView)myMasterSource.Current).Row;
            databases.baseDS.stockCodeRow row     = (databases.baseDS.stockCodeRow)((DataRowView)myMasterSource.AddNew()).Row;
            if (row == null)
            {
                return;
            }
            databases.AppLibs.InitData(row);
            row.code = code;
            if (lastRow != null)
            {
                row.stockExchange = lastRow.stockExchange;
            }
            int position = myMasterSource.Position;

            myMasterSource.Position = -1;
            myMasterSource.Position = position;
            SetFirstFocus();
        }
Example #5
0
        public static void InitData(databases.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  = 1000000;
            row.noListedStock       = 1000000;
            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;
        }
Example #6
0
        /// <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::databases.baseDS.stockExchangeRow marketRow = databases.DbAccess.GetStockExchange(data.DataStockCode);
            decimal initCapAmt       = options.TotalCapAmt * options.MaxBuyAmtPerc / 100;
            decimal priceWeight      = marketRow.priceRatio;
            decimal feePerc          = marketRow.tranFeePerc / 100;
            short   buy2SellInterval = marketRow.minBuySellDay;

            databases.baseDS.stockCodeRow stockCodeRow = application.SysLibs.FindAndCache_StockCode(data.DataStockCode);
            if (stockCodeRow == null)
            {
                return;
            }

            int     transDataIdx, 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++)
            {
                transDataIdx             = tradePoints[idx].DataIdx;
                qty                      = 0; amt = 0;
                myEstimationData.ignored = false;

                stockPrice = (decimal)data.Close[transDataIdx];
                switch (tradePoints[idx].TradeAction)
                {
                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    = transDataIdx;
                    }
                    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;
                    }
                    //==========================
                    // Check T+4 contrainst
                    //==========================
                    int minAllowSellPointIdx = lastBuyId + buy2SellInterval;

                    // [minAllowSellPoint] is out of data bound , ignore it.
                    if (minAllowSellPointIdx >= data.DateTime.Count)
                    {
                        myEstimationData.ignored = true;
                    }

                    // Violate T4 contrainst ?
                    if (!myEstimationData.ignored && tradePoints[idx].DataIdx < minAllowSellPointIdx)
                    {
                        // Keep inapplicable Sells ??
                        if (Settings.sysKeepInApplicableSell)
                        {
                            //If it is the last trade point, make transaction (sell) at [minAllowSellPoint]
                            if (idx >= tradePoints.Length - 1)
                            {
                                transDataIdx = minAllowSellPointIdx;
                            }
                            else
                            {
                                //If there is some trade point between it and [minAllowSellPoint], ignore it
                                if (tradePoints[idx + 1].DataIdx < minAllowSellPointIdx)
                                {
                                    myEstimationData.ignored = true;
                                }
                                else
                                {
                                    transDataIdx = minAllowSellPointIdx;
                                }
                            }
                        }
                        else
                        {
                            myEstimationData.ignored = true;
                        }
                    }
                    //Ok, sell it
                    if (myEstimationData.ignored != true)
                    {
                        stockPrice   = (decimal)data.Close[transDataIdx];
                        qty          = stockQty;
                        amt          = qty * stockPrice * priceWeight;
                        stockQty     = 0; stockAmt = 0;
                        feeAmt       = Math.Round(amt * feePerc, 0);
                        cashAmt     += amt - feeAmt;
                        totalFeeAmt += feeAmt;

                        //Adjust trade point to refresh chages by T4 constrainst
                        tradePoints[idx].DataIdx = transDataIdx;
                    }
                    else
                    {
                        tradePoints[idx].isValid = false;
                    }
                    break;
                }
                myEstimationData.tradeAction = tradePoints[idx].TradeAction;
                myEstimationData.onDate      = DateTime.FromOADate(data.DateTime[transDataIdx]);
                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);
            }
        }