예제 #1
0
        double CalculateProfit()
        {
            double profit = 0;
            int    count  = 0;

            StatusGuesses.Values.ToList().ForEach(x => count += x.Count);

            foreach (KeyValuePair <MarketBetStatus, List <MarketGuess> > keyValuePair in StatusGuesses)
            {
                if (keyValuePair.Key == MarketBetStatus.failedShort || keyValuePair.Key == MarketBetStatus.failedLong)
                {
                    foreach (MarketGuess marketGuess in keyValuePair.Value)
                    {
                        MarketDataPoint fail = marketGuess.MarketDay.DataPoints.FirstOrDefault(x => x.DateTime.TimeOfDay >= new TimeSpan(15, 55, 0));
                        marketGuess.Profit = Math.Abs(1 - (fail.Close / marketGuess.BuyPrice)) * -1;
                        profit            += marketGuess.Profit;
                    }
                }
                if (keyValuePair.Key == MarketBetStatus.soldShort || keyValuePair.Key == MarketBetStatus.soldLong)
                {
                    foreach (MarketGuess marketGuess in keyValuePair.Value)
                    {
                        marketGuess.Profit = MarketGuess.profit;
                        profit            += marketGuess.Profit;
                    }
                }
            }

            return(profit / count);
        }
예제 #2
0
        static MarketDataPoint ExtractDataString(string s)
        {
            var data = s.Split(',');

            // Remove tab
            data[0] = data[0].Split('\t')[1];

            DateTime dt = DateTime.Parse(data[1]);

            try
            {
                MarketDataPoint dataPoint = new MarketDataPoint(
                    data[0],
                    dt,
                    double.Parse(data[2]),
                    double.Parse(data[3]),
                    double.Parse(data[4]),
                    double.Parse(data[5]),
                    int.Parse(data[6]));

                return(dataPoint);
            }
            catch (Exception e)
            {
                foreach (var s1 in data)
                {
                    Console.WriteLine(s1);
                }
            }

            return(null);
        }
예제 #3
0
        static List <MarketDay> PopulateDays(List <MarketDataPoint> marketDataPoints)
        {
            List <MarketDay> marketDays = new List <MarketDay>();

            MarketDataPoint currentDP = new MarketDataPoint("", DateTime.Now, 0, 0, 0, 0, 0);
            MarketDataPoint previousDP;

            MarketDay day = new MarketDay();

            bool firstDP = true;

            double totalCount  = marketDataPoints.Count;
            double count       = 0;
            double per         = 0;
            double previousPer = 0;

            foreach (MarketDataPoint dataPoint in marketDataPoints)
            {
                count++;
                per = count / totalCount;
                if (per > previousPer + 0.05)
                {
                    previousPer = per;
                    Console.Write("|");
                }

                if (firstDP)
                {
                    firstDP = false;

                    currentDP = dataPoint;
                    day       = new MarketDay();
                    day.AddDataPoint(currentDP);
                }
                else
                {
                    previousDP = currentDP;
                    currentDP  = dataPoint;

                    if (currentDP.Ticker == previousDP.Ticker)
                    {
                        day.AddDataPoint(currentDP);
                    }
                    else
                    {
                        marketDays.Add(day);
                        day = new MarketDay();
                        day.AddDataPoint(currentDP);
                    }
                }
            }

            return(marketDays);
        }
예제 #4
0
        static List <MarketDataPoint> ExtractData()
        {
            // Process data file
            List <MarketDataPoint> dataPoints = new List <MarketDataPoint>();
            var file = File.ReadLines("data.txt");

            double totalCount  = file.LongCount();
            double count       = 0;
            double per         = 0;
            double previousPer = 0;

            foreach (string s in file)
            {
                count++;
                per = count / totalCount;
                if (per > previousPer + 0.05)
                {
                    previousPer = per;
                    Console.Write("|");
                }

                var data = s.Split(',');

                // Remove market suffix
                data[0] = data[0].Split('.')[0];

                int year  = int.Parse(data[2].Substring(0, 4));
                int month = int.Parse(data[2].Substring(4, 2));
                int day   = int.Parse(data[2].Substring(6, 2));

                int hours   = int.Parse(data[3].Substring(0, 2));
                int minutes = int.Parse(data[3].Substring(2, 2));
                int seconds = int.Parse(data[3].Substring(4, 2));

                DateTime dt = new DateTime(year, month, day, hours, minutes, seconds);
                dt = dt.AddHours(-5);                 //Adjust timezone

                MarketDataPoint dataPoint = new MarketDataPoint(
                    data[0],
                    dt,
                    double.Parse(data[4]),
                    double.Parse(data[7]),
                    double.Parse(data[5]),
                    double.Parse(data[6]),
                    int.Parse(data[8]));

                dataPoints.Add(dataPoint);
            }

            return(dataPoints);
        }
예제 #5
0
        public void AddDataPoint(MarketDataPoint dataPoint)
        {
            if (DataPoints.Count == 0)
            {
                Ticker   = dataPoint.Ticker;
                DateTime = dataPoint.DateTime.Date;
                DataPoints.Add(dataPoint);
            }
            else if (dataPoint.DateTime.Date == DateTime.Date && dataPoint.Ticker == Ticker)
            {
                DataPoints.Add(dataPoint);
            }

            CalculateDay();
        }
예제 #6
0
        public static List <MarketDay> ExtractSimulationData()
        {
            var file = File.ReadLines("output.txt");

            List <MarketDay> days      = new List <MarketDay>();
            MarketDay        day       = new MarketDay();
            MarketDataPoint  dataPoint = new MarketDataPoint("", DateTime.Now, 0, 0, 0, 0, 0);
            bool             first     = true;

            foreach (var s in file)
            {
                if (s != "")
                {
                    if (!s.Contains("\t"))
                    {
                        if (!first)
                        {
                            days.Add(day);
                        }
                        day     = new MarketDay();
                        day.Gap = double.Parse(s.Split(',')[7]);
                        first   = false;
                    }
                    else
                    {
                        day.AddDataPoint(ExtractDataString(s));
                    }
                }
            }

            foreach (var marketDay in days)
            {
                if (marketDay.DateTime < new DateTime(2016, 10, 31))
                {
                    foreach (var marketDataPoint in marketDay.DataPoints)
                    {
                        marketDataPoint.DateTime = marketDataPoint.DateTime.AddHours(-1);
                    }
                }
            }

            return(days);
        }