public static Double findPrice(DateTime date) { double securityValue = fundValues.count() - 1; //value of security to be bought and sold for (int x = 0; x < fundValues.count(); x++) { if (date.AddDays(1) == dates[x]) { securityValue = priceFund[x]; } else if (date.AddDays(2) == dates[x]) { securityValue = priceFund[x]; } else if (date.AddDays(3) == dates[x]) { securityValue = priceFund[x]; } else if (date.AddDays(4) == dates[x]) { securityValue = priceFund[x]; } else if (x == 0) { securityValue = priceFund[x]; } } return(securityValue); }
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()); }