C# Blog


Step 1

Download historical price data of your favorite stock symbol and save that as HistoricalData.csv file.

Note: I have downloaded about 8 months worth of data for stock symbol (UNH) - United Healthcare.

Historical data

Step 2

  • Create C# Console Application and create a folder HistoricalData.
  • Copy HistoricalData.csv file in HistoricalData folder

C-Sharp Console App

Step 3

Write a code to Import .csv file.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm
    class Program
        static void Main(string[] args)
            var historicalData = File.ReadAllLines(@"..\..\HistoricalData\HistoricalData.csv");

            var priceList = from historyPrice in historicalData
                        let data = historyPrice.Split(',')
                        select new
                            Symbol = data[0],
                            Date = data[1],
                            Open = data[2],
                            High = data[3],
                            Low = data[4],
                            Close =data[5],
                            Volume = data[6]

            foreach (var price in priceList)
                Console.WriteLine(price.Symbol + "|" + price.Open + "|" + price.High + "|" + price.Low + "|" + price.Close);

            Console.WriteLine("Press any key to exit");


While debugging

Linq response of csv import

Console Output

Historical Data Excel Imported Console Csharp

Didn't find what you were looking for? Find more on Write a code to Import .csv file using C# Console Application