Beispiel #1
0
 public frmStockTransactions(StockAnalysis stockAnalysis)
 {
     InitializeComponent();
     setTranslateMessage();
     this.stockAnalysis = stockAnalysis;
     Text = $"{stockAnalysis.StockCode} - {Translate.GetMessage("stock-transactions")}";
 }
        public List <StockItemPoco> GetStockData(double?weightRoic, double?weightEquity, double?weightEPS, double?weightRevenue, double?weightPERatio, double?weightDebtToEquity, double?weightAssetsToLiabilities)
        {
            var dao = new CompanyDataAccessObject();
            var companiesDataPoco = dao.GetCompaniesInfo();
            var count             = 1;
            var list = new List <StockItemPoco>();

            foreach (var companyDataPoco in companiesDataPoco)
            {
                var stockAnalysis = new StockAnalysis(companyDataPoco);
                var stockFitness  = new StockFitness(stockAnalysis);
                stockFitness.WeightNumberRoic                = weightRoic;
                stockFitness.WeightNumberEquity              = weightEquity;
                stockFitness.WeightNumberEPS                 = weightEPS;
                stockFitness.WeightNumberRevenue             = weightRevenue;
                stockFitness.WeightNumberPERatio             = weightPERatio;
                stockFitness.WeightNumberDebtToEquity        = weightDebtToEquity;
                stockFitness.WeightNumberAssetsToLiabilities = weightAssetsToLiabilities;

                var total = stockFitness.RoicFitness * weightRoic + stockFitness.EquityFitness * weightEquity + stockFitness.EPSFitness * weightEPS + stockFitness.RevenueFitness * weightRevenue + stockFitness.PERatioFitness * weightPERatio + stockFitness.DebtToEquityFitness * weightDebtToEquity + stockFitness.AssetsToLiabilitiesFitness * weightAssetsToLiabilities;

                if (total != null)
                {
                    list.Add(new StockItemPoco
                    {
                        StockFitness    = stockFitness,
                        CompanyDataPoco = companyDataPoco,
                        Fitness         = total,
                        StockPrice      = companyDataPoco.Company.StockPrice,
                        Marketcap       = stockAnalysis.MarketCapSlopeInfo.NominalValues,
                        StockAnalysis   = stockAnalysis
                    });;
                    count++;
                }
            }

            var rank = 1;

            foreach (var item in list.OrderByDescending(l => l.Fitness))
            {
                item.MarketAnalyzerRank = rank;
                rank++;
            }
            return(list);
        }
        public List <StockItemPoco> GetStockData()
        {
            var dao = new CompanyDataAccessObject();
            var companiesDataPoco = dao.GetCompaniesInfo();
            var count             = 1;
            var list = new List <StockItemPoco>();

            foreach (var companyDataPoco in companiesDataPoco)
            {
                var stockAnalysis = new StockAnalysis(companyDataPoco);
                var stockFitness  = new StockFitness(stockAnalysis);

                var total = stockFitness.TotalFitness;

                if (total != null)
                {
                    list.Add(new StockItemPoco
                    {
                        StockFitness    = stockFitness,
                        CompanyDataPoco = companyDataPoco,
                        Fitness         = total,
                        StockPrice      = companyDataPoco.Company.StockPrice,
                        Marketcap       = stockAnalysis.MarketCapSlopeInfo.NominalValues,
                        StockAnalysis   = stockAnalysis
                    });;
                    count++;
                }
            }

            var rank = 1;

            foreach (var item in list.OrderByDescending(l => l.Fitness))
            {
                item.MarketAnalyzerRank = rank;
                rank++;
            }
            return(list);
        }
Beispiel #4
0
        /* ***************************************************************************************************************************************************************
         * Funny thing, the text box on a form doesn't seem to have a setting to allow for numbers only.
         * So I found a routine to check the keypress on the text label to keep out anything non-numeric but it does allow you to enter two decimal spots.
         * Before you start any analysis call this routine to make sure the percentage entered is actually a number.
         * *************************************************************************************************************************************************************** */

        private bool Check_on_pct(StockAnalysis cop_Look)
        {
            bool   alliswell = true;
            double cop_pct   = 0.0;

            try
            {
                cop_pct = Convert.ToDouble(Text_Box_Pct.Text);
            }

            catch
            {
                alliswell = false;
                MessageBox.Show("Check your number again.  It doesn't look right.", "OOPS");
                cop_pct = 0.0;
            }

            finally
            {
                cop_Look.SetPct(cop_pct);
            }

            return(alliswell);
        }
Beispiel #5
0
        /* ***************************************************************************************************************************************************************
         * 1. Confirm the informaiton needed (Drop Percent) has been entered.
         * 2. Clear the last set of data.
         * 3. Collect the symbol information based on the percent entered.
         * *************************************************************************************************************************************************************** */

        private void button1_Click(object sender, EventArgs e)
        {
            String ls_CurSymbol   = "";
            String ls_RecSymbol   = "";
            double ld_TodaysPrice = 0.0;

            int li_stockday = 0;


            int i = 0;

            StockAnalysis b1c_Look = new StockAnalysis();

            b1c_Look.ClearBounces();

            Form_BounceinProgress = Check_on_pct(b1c_Look);

            if (Form_BounceinProgress && b1c_Look.sa_pct > 0.0)
            {
                // Initialize the query
                BounceBack.BounceData2DataSetTableAdapters.DailyQuoteTableAdapter BBQTA;
                BBQTA = new BounceData2DataSetTableAdapters.DailyQuoteTableAdapter();

                BounceData2DataSet.DailyQuoteDataTable List_BounceHistory;
                List_BounceHistory = BBQTA.GetData();

                dataGridVBounce.Rows.Clear();


                /* So the plan here is to run through the stock history and collect the times the stock fell by the percent entered in a single day.
                 * From that day count how many days it took to get back to the price before the fall or the bounceback.
                 * Then display the number of times that drop happened and the average days back.
                 */

                for (i = 0; i < List_BounceHistory.Rows.Count; i++)
                {
                    DataRow BounceRow = List_BounceHistory.Rows[i];
                    ls_RecSymbol   = BounceRow.Field <string>("Symbol");
                    ld_TodaysPrice = BounceRow.Field <double>("open");
                    li_stockday    = BounceRow.Field <int>("TickerID");


                    // Are you the first record of a new stock?
                    if (ls_RecSymbol != ls_CurSymbol)
                    {
                        // If you're not the first stock add the details of the current stock.
                        if (i > 0)
                        {
                            dataGridVBounce.Rows.Add(ls_CurSymbol, $"{b1c_Look.sa_PriceBounces}", $"{b1c_Look.find_median()}");
                        }

                        // Set the variables to start a new stock.
                        b1c_Look.ClearBounces();

                        ls_CurSymbol = ls_RecSymbol;
                        //MessageBox.Show("New stock", ls_CurSymbol);
                    }

                    // all the work happens here.
                    b1c_Look.SetPricePoint(1, ld_TodaysPrice, "NoDate");
                }

                // The for loop does not add the last stock.  Do that here.

                dataGridVBounce.Rows.Add(ls_CurSymbol, $"{b1c_Look.sa_PriceBounces}", $"{b1c_Look.sa_AvgBounce}");

                // RML - This highlights the first row.
                // I'm thinking when this is fleshed out the first row will be one of the exchanges
                // so you won't have to worry about there not being a row to select.
                dataGridVBounce.Rows[0].Selected = true;

                Form_BounceinProgress = false;
            }
        }
Beispiel #6
0
        /* ***************************************************************************************************************************************************************
         *  This is the best routine I found to identify when a user picks a symbol from the list of symbols.
         *  It will display the stock activity for that ticker in the line chart on the bottom right of the form
         *  and the times that stock dropped below the percent entered in a single day with the days it took to recover as
         *  the bar chart amount.
         * *************************************************************************************************************************************************************** */

        private void dataGridVBounce_CellRowEnter(object sender, DataGridViewCellEventArgs e)
        {
            // Interesting thing happens here.  The first selection you make after a grid reset doesn't catch here?
            // It acts like you have to double click the first row to take an action?
            string dgr_symbol = "xxx";

            bool DummyFlag = false;

            int bri = e.RowIndex;

            double gvb_TodaysPrice = 0.0;
            int    gvb_Tickerid    = 0;
            string gvb_Date;
            int    gvb_counter = 0;

            StockAnalysis gvb_Look = new StockAnalysis();

            gvb_Look.ClearBounces();

            DummyFlag = Check_on_pct(gvb_Look);



            if (!Form_BounceinProgress)
            {
                // OK so I'm changing things up here a bit.  Instead of adding XY elements to bouncegraph I'm going to fill a datatable bound to the graph in the stock analyis routines.
                // This section will be respobsible for clearing the table and setting the global row value.

                //BounceinProgress = true;

                dgr_symbol = dataGridVBounce.Rows[bri].Cells[0].Value.ToString();

                DataRow dr;

                // Initialize the query


                BounceBack.BounceData2DataSetTableAdapters.DailyQuoteTableAdapter BBDGQ;
                BBDGQ = new BounceData2DataSetTableAdapters.DailyQuoteTableAdapter();

                BounceData2DataSet.DailyQuoteDataTable List_BouncePoints;
                List_BouncePoints = BBDGQ.GetDataBySymbol(dgr_symbol);


                BounceChart.Series[0].Points.Clear();

                BounceChart.Series[0].Name = dgr_symbol;

                //BounceGraph.Series[0].Points.Clear();
                Form_BounceGraph_DT.Clear();



                for (int i = 1; i < List_BouncePoints.Rows.Count; i++)
                {
                    gvb_TodaysPrice = List_BouncePoints.Rows[i].Field <double>("open");
                    gvb_Tickerid    = List_BouncePoints.Rows[i].Field <int>("TickerID");
                    gvb_Date        = List_BouncePoints.Rows[i].Field <string>("date");
                    BounceChart.Series[0].Points.AddXY(i, gvb_TodaysPrice);

                    // Here I want to run through the same logic the bounce process did when looking up all symbols.
                    // Then display the bounced days in the Bouncegraph chart.
                    gvb_Look.SetPricePoint(gvb_Tickerid, gvb_TodaysPrice, gvb_Date);

                    // Check to see if a bounce was recorded.
                    if (gvb_Look.sa_PriceBounces > gvb_counter)
                    {
                        gvb_counter = gvb_Look.sa_PriceBounces;

                        dr                = Form_BounceGraph_DT.NewRow();
                        dr["DropDate"]    = gvb_Look.sa_DropDate;
                        dr["GraphDays"]   = Convert.ToString(Math.Min(BG_Detail.i_gmax, gvb_Look.sa_BounceDay[gvb_counter]));
                        dr["RecoverDays"] = Convert.ToString(gvb_Look.sa_BounceDay[gvb_counter]);
                        dr["Price"]       = Convert.ToString(gvb_Look.sa_PricePoint);
                        dr["DropPct"]     = gvb_Look.sa_DropPct;
                        dr["TickerID"]    = Convert.ToString(gvb_Tickerid);


                        Form_BounceGraph_DT.Rows.Add(dr);
                    }
                }


                // Set the row after everything is full.
                BG_Detail.i_Rows = gvb_Look.sa_PriceBounces;
                BG_Detail.Set_Boundary();

                BounceGraph.DataSource = Form_BounceGraph_DT;
                BounceGraph.Series["Days"].XValueMember  = "DropDate";
                BounceGraph.Series["Days"].YValueMembers = "GraphDays";



                BounceGraph.DataBind();
            }
        }
Beispiel #7
0
        public List <StockAnalysis> RefreshList()
        {
            List <Stock> stocks = new List <Stock>();

            if (request.StockCodes.Count == 0)
            {
                stocks = Session.Entities.GetStocks();
            }
            else
            {
                foreach (var stockCode in request.StockCodes)
                {
                    var stock = Session.Entities.GetStock(stockCode);
                    if (stock != null)
                    {
                        stocks.Add(stock);
                    }
                }
            }
            StockAnalyses = new List <StockAnalysis>();
            StockAnalysis           stockAnalysis     = new StockAnalysis();
            List <StockTransaction> stockTransactions = new List <StockTransaction>();

            stockTransactions = Session.Entities.GetStockTransactions().Where(c => c.Date >= request.Period.StartDate && c.Date <= request.Period.EndDate && stocks.Select(s => s.StockCode).Contains(c.StockCode)).ToList();

            #region Last Period Stock Transaction
            {
                var lastPeriodStockTransaciton = from st in Session.Entities.GetStockTransactions().DeepCopy()
                                                 where st.Date < request.Period.StartDate &&
                                                 stocks.Select(c => c.StockCode).Contains(st.StockCode)
                                                 group st by st.StockCode into StockTransaction
                                                 select new { StockCode = StockTransaction.Key, StockTransaction };

                foreach (var stock in lastPeriodStockTransaciton)
                {
                    StockTransaction previousTransaction = null;
                    foreach (var stockTransaction in stock.StockTransaction)
                    {
                        if (previousTransaction != null && previousTransaction.TransactionType == stockTransaction.TransactionType)
                        {
                            stockTransaction.Amount       += previousTransaction.Amount;
                            stockTransaction.TotalPrice   += previousTransaction.TotalPrice;
                            previousTransaction.Amount     = 0;
                            previousTransaction.TotalPrice = 0;
                            previousTransaction.UnitPrice  = 0;
                            stockTransaction.UnitPrice     = stockTransaction.TotalPrice / stockTransaction.Amount;
                        }
                        previousTransaction = stockTransaction;
                    }
                }

                foreach (var stock in lastPeriodStockTransaciton)
                {
                    if (stock.StockTransaction.Where(c => c.Amount > 0).Sum(c => c.Amount * (c.TransactionType == TransactionType.Sell ? -1 : 1)) > 0)
                    {
                        foreach (var stockTransaction in stock.StockTransaction.OrderBy(c => c.Date).Where(c => c.TransactionType == TransactionType.Sell && c.Amount > 0))
                        {
                            decimal sellAmount = stockTransaction.Amount;

                            while (sellAmount > 0)
                            {
                                var buyTransaction = stock.StockTransaction.OrderBy(c => c.Date).FirstOrDefault(c => c.TransactionType == TransactionType.Buy && c.Amount > 0);
                                if (sellAmount > buyTransaction.Amount)
                                {
                                    sellAmount           -= buyTransaction.Amount;
                                    buyTransaction.Amount = 0;
                                }
                                else
                                {
                                    buyTransaction.Amount -= sellAmount;
                                    sellAmount             = 0;
                                }
                            }
                        }

                        decimal  sumBuyAmount       = stock.StockTransaction.Where(c => c.TransactionType == TransactionType.Buy && c.Amount > 0).Sum(c => c.Amount);
                        decimal  sumBuyPrice        = stock.StockTransaction.Where(c => c.TransactionType == TransactionType.Buy && c.Amount > 0).Sum(c => c.UnitPrice * c.Amount);
                        DateTime buyDate            = stock.StockTransaction.Where(c => c.TransactionType == TransactionType.Buy && c.Amount > 0).Min(c => c.Date);
                        int      stockTransactionId = stock.StockTransaction.OrderBy(c => c.Date).FirstOrDefault(c => c.TransactionType == TransactionType.Buy && c.Amount > 0).StockTransactionId;
                        stockTransactions.Add(new StockTransaction
                        {
                            Amount             = sumBuyAmount,
                            UnitPrice          = sumBuyPrice / sumBuyAmount,
                            TotalPrice         = sumBuyPrice,
                            StockCode          = stock.StockCode,
                            Date               = buyDate,
                            TransactionType    = TransactionType.Buy,
                            StockTransactionId = stockTransactionId,
                        });
                    }
                }
            }
            #endregion

            #region Process
            var result = from st in stockTransactions
                         join s in Session.Entities.GetStocks() on st.StockCode equals s.StockCode
                         join s1 in stocks.Distinct() on s.StockCode equals s1.StockCode
                         where s1 != null
                         orderby st.Date
                         group st by s into StockTransactions
                         select new { Stock = StockTransactions.Key, StockTransactions };

            foreach (var item in result.Where(c => c.StockTransactions.Sum(t => t.Amount * (t.TransactionType == TransactionType.Sell ? -1 : 1)) > 0))
            {
                Session.Entities.GetStockService(item.Stock.StockCode);
            }

            foreach (var stock in result)
            {
                stockAnalysis = new StockAnalysis();
                foreach (var stockTransaction in stock.StockTransactions)
                {
                    stockAnalysis.StockCode = stock.Stock.StockCode;
                    stockAnalysis.StockTransactions.Add(new StockAnalysisTransaction
                    {
                        Amount             = stockTransaction.Amount,
                        Date               = stockTransaction.Date,
                        StockTransactionId = stockTransaction.StockTransactionId,
                        TransactionType    = stockTransaction.TransactionType,
                        UnitPrice          = stockTransaction.UnitPrice,
                        StockCode          = stockTransaction.StockCode,
                        Const              = stockTransaction.Const
                    });

                    if (stockAnalysis.TotalAmount == 0)
                    {
                        StockAnalyses.Add(stockAnalysis);
                        stockAnalysis = new StockAnalysis();
                    }
                }

                if (stockAnalysis.StockTransactions.Count > 0)
                {
                    var partialStockAnalysis = new StockAnalysis();
                    partialStockAnalysis.StockCode = stockAnalysis.StockCode;
                    decimal diffarenceAmount = stockAnalysis.StockTransactions.Sum(c => c.Amount * (c.TransactionType == TransactionType.Sell ? -1 : 1));
                    bool    isPartial        = diffarenceAmount > 0 && stockAnalysis.StockTransactions.Any(c => c.TransactionType == TransactionType.Sell);
                    if (isPartial)
                    {
                        foreach (var stockTransaction in stockAnalysis.StockTransactions.Where(c => c.TransactionType == TransactionType.Buy).OrderByDescending(c => c.Date))
                        {
                            var partialStockTransaction = new StockAnalysisTransaction()
                            {
                                Amount             = 0,
                                Date               = stockTransaction.Date,
                                StockTransactionId = stockTransaction.StockTransactionId,
                                TransactionType    = stockTransaction.TransactionType,
                                UnitPrice          = stockTransaction.UnitPrice,
                                StockCode          = stockTransaction.StockCode,
                                Const              = 0
                            };
                            if (stockTransaction.Amount >= diffarenceAmount)
                            {
                                stockTransaction.Amount       -= diffarenceAmount;
                                partialStockTransaction.Const  = stockTransaction.Const;
                                stockTransaction.Const         = 0;
                                partialStockTransaction.Amount = diffarenceAmount;
                                partialStockAnalysis.StockTransactions.Add(partialStockTransaction);
                                break;
                            }
                            else
                            {
                                diffarenceAmount -= stockTransaction.Amount;
                                partialStockTransaction.Amount = stockTransaction.Amount;
                                partialStockAnalysis.StockTransactions.Add(partialStockTransaction);
                                stockTransaction.Amount = 0;
                            }
                        }
                        stockAnalysis.StockTransactions.RemoveAll(c => c.Amount == 0);
                    }

                    StockAnalyses.Add(stockAnalysis);
                    if (isPartial)
                    {
                        StockAnalyses.Add(partialStockAnalysis);
                    }
                }
            }
            #endregion

            calculate();

            return(StockAnalyses.OrderBy(c => c.LastTransactionDate).ToList());
        }