Esempio n. 1
0
        static MarketBetStatus SortWinLoss(MarketGuess marketGuess)
        {
            if (marketGuess.MarketAction == MarketAction.buy)
            {
                if (marketGuess.FirstSellPoint == null)
                {
                    return(MarketBetStatus.failedLong);
                }
                else
                {
                    return(MarketBetStatus.soldLong);
                }
            }

            if (marketGuess.MarketAction == MarketAction.shrt)
            {
                if (marketGuess.FirstShortPoint == null)
                {
                    return(MarketBetStatus.failedShort);
                }
                else
                {
                    return(MarketBetStatus.soldShort);
                }
            }

            return(MarketBetStatus.error);
        }
Esempio n. 2
0
        public static List <MarketGuess> RunSimulation()
        {
            logDetailed.AutoFlush = true;
            logSummary.AutoFlush  = true;
            logAccuracy.AutoFlush = true;
            logWinLoss.AutoFlush  = true;
            logVolume.AutoFlush   = true;

            List <MarketDay> days = ExtractSimulationData();

            DateTime firstDay    = days[0].DateTime;
            DateTime lastDay     = days[days.Count - 1].DateTime;
            int      daysSpanned = (lastDay - firstDay).Days;

            List <MarketGuess> guesses = new List <MarketGuess>();

            for (int i = 1; i <= daysSpanned; i++)
            {
                LC($"DAY {i}");
                foreach (var marketDay in days.Where(x => x.DateTime == firstDay.AddDays(i)))
                {
                    MarketGuess guess = new MarketGuess {
                        MarketDay = marketDay
                    };

                    // Determine opening analysis
                    guess = OpeningAnalysis(guess);
                    guess.DetermineMarketAction();

                    // Determine points of 'going long' or shorthing
                    guess = LongShortSimulation(guess);

                    guesses.Add(guess);

                    SimulationLog(guess);
                }
                LC($"END OF DAY {i}");
                LC();
            }

            SimulationAccuracy(guesses);
            List <DaySummary> summaries = WinningsLosses(guesses);

            VolumeClassification(summaries);
            CreateCSV(guesses);

            return(guesses);
        }
Esempio n. 3
0
        static MarketGuess LongShortSimulation(MarketGuess guess)
        {
            foreach (MarketDataPoint marketDataPoint in guess.MarketDay.DataPoints
                     .Where(x => x.DateTime.TimeOfDay > new TimeSpan(10, 30, 0)))
            {
                if (marketDataPoint.High > guess.SellUpPrice || marketDataPoint.Low > guess.SellUpPrice || marketDataPoint.Open > guess.SellUpPrice || marketDataPoint.Close > guess.SellUpPrice)
                {
                    guess.LongPoints.Add(marketDataPoint);
                }
                if (marketDataPoint.High < guess.SellDownPrice || marketDataPoint.Low < guess.SellDownPrice || marketDataPoint.Open < guess.SellDownPrice || marketDataPoint.Close < guess.SellDownPrice)
                {
                    guess.ShortPoints.Add(marketDataPoint);
                }
            }

            return(guess);
        }
Esempio n. 4
0
        static MarketGuess OpeningAnalysis(MarketGuess guess)
        {
            //From 9:30 to 10:10
            foreach (var marketDataPoint in guess.MarketDay.DataPoints
                     .Where(x => x.DateTime.TimeOfDay <= new TimeSpan(10, 10, 0)))
            {
                guess.FirstVolume.Volume += marketDataPoint.Volume;

                if (marketDataPoint.High > guess.LocalHigh)
                {
                    guess.LocalHigh = marketDataPoint.High;
                }
                if (marketDataPoint.Low < guess.LocalLow)
                {
                    guess.LocalLow = marketDataPoint.Low;
                }
            }

            //From 10:10 to 10:30
            foreach (var marketDataPoint in guess.MarketDay.DataPoints
                     .Where(x => x.DateTime.TimeOfDay > new TimeSpan(10, 10, 0) && x.DateTime.TimeOfDay <= new TimeSpan(10, 30, 0)))
            {
                guess.SecondVolume.Volume += marketDataPoint.Volume;

                if (marketDataPoint.High > guess.LocalHigh)
                {
                    guess.LocalHigh = marketDataPoint.High;
                }
                if (marketDataPoint.Low < guess.LocalLow)
                {
                    guess.LocalLow = marketDataPoint.Low;
                }
            }

            guess.FirstVolume.Volume  /= 40;
            guess.SecondVolume.Volume /= 20;
            guess.BuyPrice             = guess.MarketDay.DataPoints?
                                         .FirstOrDefault(x => x.DateTime.TimeOfDay == new TimeSpan(10, 30, 0))?.Close ?? 0;

            return(guess);
        }
Esempio n. 5
0
        static void SetConsoleColorAction(MarketGuess guess)
        {
            // Set console color for pretty text
            switch (guess.MarketAction)
            {
            case MarketAction.buy:
                Console.ForegroundColor = buyColor;
                break;

            case MarketAction.shrt:
                Console.ForegroundColor = shortColor;
                break;

            case MarketAction.doNotTouch:
                Console.ForegroundColor = dontColor;
                break;

            case MarketAction.outOfBounds:
                Console.ForegroundColor = dontPriceColor;
                break;
            }
        }
Esempio n. 6
0
        static void SimulationLog(MarketGuess guess)
        {
            List <MarketDataPoint> LongShortList = new List <MarketDataPoint>();

            LongShortList.AddRange(guess.LongPoints);
            LongShortList.AddRange(guess.ShortPoints);

            Console.ForegroundColor = standardColor;

            SetConsoleColorAction(guess);

            LC(guess.MarketDay.ToStringNice(false));
            LC(
                $"||{guess.MarketAction} {guess.BoundsMarketAction}||   1stVol: {guess.FirstVolume.Volume} {guess.FirstVolume.VolumeClass} 2ndVol: {guess.SecondVolume.Volume} {guess.SecondVolume.VolumeClass} Low&High: {guess.LocalLow} - {guess.LocalHigh} bounds: {guess.LowBound} - {guess.HighBound} BuyPrice: {guess.BuyPrice}");
            logSummary.WriteLine(guess.MarketDay.ToStringNice(false));
            logSummary.WriteLine(
                $"||{guess.MarketAction} {guess.BoundsMarketAction}||   1stVol: {guess.FirstVolume.Volume} {guess.FirstVolume.VolumeClass} 2ndVol: {guess.SecondVolume.Volume} {guess.SecondVolume.VolumeClass} Low&High: {guess.LocalLow} - {guess.LocalHigh} bounds: {guess.LowBound} - {guess.HighBound} BuyPrice: {guess.BuyPrice}");

            Console.ForegroundColor = standardColor;

            foreach (var point in LongShortList.OrderBy(x => x.DateTime))
            {
                if (point.High > guess.SellUpPrice)
                {
                    LC(
                        $"\t||buy||   Bought: {guess.BuyPrice} Sold: {guess.SellUpPrice} At: {point.DateTime.TimeOfDay} High: {point.High} Percentage: {(point.High / guess.BuyPrice) - 1}",
                        true,
                        buyColor);
                }

                if (point.Low < guess.SellDownPrice)
                {
                    LC(
                        $"\t||short||   Bought: {guess.BuyPrice} Sold: {guess.SellDownPrice} At: {point.DateTime.TimeOfDay} Low: {point.Low} Percentage: {1 - (point.Low / guess.BuyPrice)}",
                        true,
                        shortColor);
                }
            }

            if (guess.HighestSellPoint != null)
            {
                logSummary.WriteLine($"\tbuyCount: {guess.LongPoints.Count} shortCount: {guess.ShortPoints.Count}");
                logSummary.WriteLine(
                    $"\tHighest: {guess.HighestSellPoint.DateTime.TimeOfDay} High: {guess.HighestSellPoint.High} Percentage: {guess.HighestSellPercentage}");
                logSummary.WriteLine(
                    $"\tLowest: {guess.LowestShortPoint.DateTime.TimeOfDay} Low: {guess.LowestShortPoint.Low} Percentage: {guess.LowestShortPercentage}");
                logSummary.WriteLine();

                LC();
                LC(
                    $"\tHighest: {guess.HighestSellPoint.DateTime.TimeOfDay} High: {guess.HighestSellPoint.High} Percentage: {(guess.HighestSellPoint.High / guess.BuyPrice) - 1}",
                    true,
                    buyColor);
                LC(
                    $"\tLowest: {guess.LowestShortPoint.DateTime.TimeOfDay} Low: {guess.LowestShortPoint.Low} Percentage: {1 - (guess.LowestShortPoint.Low / guess.BuyPrice)}",
                    true,
                    shortColor);
                LC();
                LC("\t---DETAILS---");
                LC($"\t{guess.MarketDay.ToStringNice()}");
            }
            LC();
        }