Exemplo n.º 1
0
        public static void calculateInvestmentValue(SecurityValues benchmark, SecurityValues fund)
        {
            double currentValue  = 10000.00; //value of investment
            double currentShares = 0;        //shares held of investment

            stdDev    = benchmark.getStandardDeviation();
            bmAverage = benchmark.getAverages();
            priceBm   = benchmark.getPrice();
            upper     = benchmark.getUpperBand();
            lower     = benchmark.getLowerBand();
            marketSig = benchmark.getMarketSignal();

            fundValues = fund;
            dates      = fund.getDate();
            priceFund  = fund.getPrice();

            Boolean holding     = false;
            int     lengthTotal = marketSig.Length - 20;

            for (int x = lengthTotal; x >= 0; x--)
            {
                if (marketSig[x].Equals("BUY") && holding.Equals(false))
                {
                    holding = true;
                    Console.Write("BUY amount on this day is: " + findPrice(dates[x]) + "\n");
                    currentShares = currentValue / findPrice(dates[x]);
                }
                else if (marketSig[x].Equals("SELL") && holding.Equals(true))
                {
                    Console.Write("SELL amount on this day is: " + findPrice(dates[x]) + "\n");
                    holding = false;

                    currentValue = currentShares * findPrice(dates[x]);
                }
            }

            Console.Write("Final Value: " + currentValue + "\n");
        }
Exemplo n.º 2
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            var lineOfData = new List <string>();
            int count      = 0;
            var date       = new List <DateTime>();
            var price      = new List <double>();

            Excel.Workbook xlValueList     = null;
            OpenFileDialog openFileDialog2 = new OpenFileDialog();

            Console.Write("click: ");
            openFileDialog2.Title = "Select a File";
            if (openFileDialog2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                xlValueList = xlApp.Workbooks.Open(openFileDialog2.FileName);
            }

            Excel.Worksheet xlWorksheet = xlValueList.Sheets[1];
            Excel.Range     xlRange     = xlWorksheet.UsedRange;

            int rowCount = xlRange.Rows.Count;
            int colCount = xlRange.Columns.Count;


            //iterate over the rows and columns and print to the console as it appears in the file
            //excel is not zero based
            for (int i = 1; i <= rowCount; i++)
            {
                for (int j = 1; j <= colCount; j++)
                {
                    if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null)
                    {
                        //get first value in the row, date
                        if (j == 1)
                        {
                            DateTime conv = DateTime.FromOADate(xlRange.Cells[i, j].Value2);

                            date.Add(conv);
                        }
                        //gets second value which is the actual value of the security
                        if (j == 2)
                        {
                            price.Add(xlRange.Cells[i, j].Value2);
                        }
                    }
                }
            }

            //cleanup
            GC.Collect();
            GC.WaitForPendingFinalizers();

            //close and release
            xlValueList.Close();


            //quit and release
            xlApp.Quit();


            securityPrice = new SecurityValues(date, price);


            Console.Write("security count: " + securityPrice.count());
        }