Beispiel #1
0
        public override InvestmentAction GetActionForDay(DateTime currentDay, StockMarketHistoricalData data)
        {
            DateTime startDateOfCrystalBall = DateTime.MaxValue;

            foreach (var item in SellBuyDates)
            {
                if (item.SellDate.IsBefore(startDateOfCrystalBall))
                {
                    startDateOfCrystalBall = item.SellDate;
                }
            }

            if (currentDay.IsBefore(startDateOfCrystalBall))
            {
                return(InvestmentAction.Buy);
            }

            foreach (var item in SellBuyDates)
            {
                if (item.SellDate.IsSameDay(currentDay))
                {
                    return(InvestmentAction.Sell);
                }

                if (item.BuyDate.IsSameDay(currentDay))
                {
                    return(InvestmentAction.Buy);
                }
            }

            return(InvestmentAction.NoAction);
        }
 public override InvestmentAction GetActionForDay(DateTime currentDay, StockMarketHistoricalData data)
 {
     if (currentDay.DayOfWeek == _DayOfWeek)
     {
         return(InvestmentAction.Buy);
     }
     else
     {
         return(InvestmentAction.NoAction);
     }
 }
Beispiel #3
0
        public MethodEvaluation(BaseInvestmentStategy method, StockMarketHistoricalData data)
        {
            Method         = method;
            HistoricalData = data;
            DailyMoneyLogs = new List <MoneyDaily>();

            // computer extra data fields on Historical Data
            HistoricalData.SetCalculatedFieldsForDateRange(method.StrategyStartDate, method.StrategyEndDate, 200);
            StartDate = Method.StrategyStartDate ?? HistoricalData.DataStartDate;
            EndDate   = Method.StrategyEndDate ?? HistoricalData.DataEndDate;
        }
        public static StockMarketHistoricalData GetDowJonesHistoricalData()
        {
            if (CachedData != null)
            {
                return(CachedData);
            }

            // Read in data
            var rows = ReadInCSVFile.ReadInDowJonesFile();

            Console.WriteLine("Found " + rows.Count + " days of data");

            var data = new StockMarketHistoricalData(rows);

            CachedData = data;

            return(data);
        }
Beispiel #5
0
        public static void TestStrategy(BaseInvestmentStategy stategy, StockMarketHistoricalData data)
        {
            var startDate = stategy.StrategyStartDate;
            var endDate   = stategy.StrategyEndDate;

            data.SetCalculatedFieldsForDateRange(startDate, endDate);

            var methodEval = new MethodEvaluation(stategy, data);
            var result     = methodEval.StartEvaluation(null, 0, 0);

            result.ToCSVFile();
            result.ToMutedCSVFile();
            var lastDay = result.Data.Last();

            Console.WriteLine();
            Console.WriteLine(stategy.StrategyDescription);
            Console.WriteLine("Cash: " + lastDay.CashOnHand + " Stock: " + lastDay.ValueOfStockOnHand);
        }
        public override InvestmentAction GetActionForDay(DateTime currentDay, StockMarketHistoricalData data)
        {
            decimal recentLow  = decimal.MaxValue;
            decimal recentHigh = decimal.MinValue;

            DateTime windowDate = currentDay.AddDays(-365);

            while (windowDate.IsBefore(currentDay))
            {
                StockMarketDaily stockMarketForDay = data.GetDataForDate(windowDate);
                if (stockMarketForDay.ClosingValue < recentLow)
                {
                    recentLow = stockMarketForDay.ClosingValue;
                }

                if (stockMarketForDay.ClosingValue > recentHigh)
                {
                    recentHigh = stockMarketForDay.ClosingValue;
                }
                windowDate = windowDate.AddDays(1);
            }
            decimal buyPercentage = 10.0M / 100.0M;
            var     dayData       = data.GetDataForDate(currentDay);
            decimal minBuyRange   = recentHigh - (dayData.ClosingValue * buyPercentage);

            decimal minBuyRangeWithDerivative = recentHigh - (dayData.ClosingValue * buyPercentage * 2);

            decimal sellPercentage = 10.0M / 100.0M;

            decimal maxSellRange = recentLow + (dayData.ClosingValue * sellPercentage);

            if (dayData.ClosingValue > minBuyRange)
            {
                return(InvestmentAction.Buy);
            }
            else if (dayData.ClosingValue < maxSellRange)
            {
                return(InvestmentAction.Sell);
            }
            else
            {
                return(InvestmentAction.NoAction);
            }
        }
        public override InvestmentAction GetActionForDay(DateTime currentDay, StockMarketHistoricalData data)
        {
            decimal currentDayValue = data.GetDataForDate(currentDay).ClosingValue;

            decimal pastValue = data.GetDataForDate(currentDay.AddDays(-50)).ClosingValue;

            if (currentDayValue - pastValue > 0)
            {
                return(InvestmentAction.Buy);
            }
            else if (currentDayValue - pastValue < 0)
            {
                return(InvestmentAction.Sell);
            }
            else
            {
                return(InvestmentAction.NoAction);
            }
        }
Beispiel #8
0
        private void _GetDataBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            StockMarketHistoricalData data = e.Result as StockMarketHistoricalData;

            if (data != null)
            {
                HistoricalData = data;
            }

            //now that we have the data - do the analysis
            MethodEvaluation cashEvaluation = new MethodEvaluation(new NoActionStrategy(SelectedSchedule, this.StartDateTimePicker.Value, this.EndDateTimePicker.Value), HistoricalData);

            MethodEvaluation standardEvaluation = new MethodEvaluation(new AlwaysBuyStrategy(SelectedSchedule, this.StartDateTimePicker.Value, this.EndDateTimePicker.Value), HistoricalData);

            MethodEvaluation experiment = new MethodEvaluation(SelectedStrategy, HistoricalData);

            var evaluators = new MethodEvaluators(cashEvaluation, standardEvaluation, experiment);

            _DoAnalysisBackgroundWorker.RunWorkerAsync(evaluators);
        }
Beispiel #9
0
 private void _GetDataBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         StockMarketHistoricalData result = null;
         string stockMarketSymbol         = e.Argument.ToString().ToLower();
         if (stockMarketSymbol.Contains("dow"))
         {
             result = DowJonesHistoricalDataCreator.GetDowJonesHistoricalData();
         }
         else
         {
             result = StockDataRetriever.GetStockData(stockMarketSymbol);
         }
         e.Result = result;
     }
     catch (Exception ex)
     {
         e.Result = null;
     }
 }
Beispiel #10
0
        static void Main(string[] args)
        {
            // Read in data
            var rows = ReadInCSVFile.ReadInDowJonesFile();

            Console.WriteLine("Found " + rows.Count + " days of data");

            var data = new StockMarketHistoricalData(rows);

            //TestStrategy(new NoActionStrategy(), data);

            TestStrategy(new AlwaysBuyStrategy(new StandardInvestmentSchedule()), data);

            //TestStrategy(new AlwaysBuyStrategy(new InitialInvestmentOnly(1)), data);

            //foreach (DayOfWeek day in (DayOfWeek[])Enum.GetValues(typeof(DayOfWeek)))
            //{
            //    TestStrategy(new AlwaysBuyBasedOnWeekDay(new StandardInvestmentSchedule(), day), data);
            //}

            Console.ReadKey();
        }
Beispiel #11
0
        private void StartAnalysisButton_Click(object sender, EventArgs e)
        {
            ExecuteOnOwningThread(analysisProgressLabel, () =>
            {
                analysisProgressLabel.Visible = true;
                analysisProgressBar.Visible   = true;

                analysisProgressLabel.Visible = true;
                analysisProgressBar.Value     = 0;
                analysisProgressLabel.Text    = "0 % - Getting Data";
            });

            string selectedValue = this.stockSymbolTextBox.Text.ToString().ToLower();

            if (string.IsNullOrWhiteSpace(selectedValue))
            {
                HistoricalData = null;
            }
            else
            {
                _GetDataBackgroundWorker = new BackgroundWorker();
                _GetDataBackgroundWorker.WorkerSupportsCancellation = true;
                _GetDataBackgroundWorker.RunWorkerCompleted        += _GetDataBackgroundWorker_RunWorkerCompleted;
                _GetDataBackgroundWorker.DoWork += _GetDataBackgroundWorker_DoWork;
                _GetDataBackgroundWorker.RunWorkerAsync(this.stockSymbolTextBox.Text);

                if (_DoAnalysisBackgroundWorker != null && _DoAnalysisBackgroundWorker.IsBusy)
                {
                    _DoAnalysisBackgroundWorker.CancelAsync();
                }

                _DoAnalysisBackgroundWorker = new BackgroundWorker();
                _DoAnalysisBackgroundWorker.WorkerSupportsCancellation = true;
                _DoAnalysisBackgroundWorker.ProgressChanged           += _DoAnalysisBackgroundWorker_ProgressChanged;
                _DoAnalysisBackgroundWorker.RunWorkerCompleted        += _DoAnalysisBackgroundWorker_RunWorkerCompleted;
                _DoAnalysisBackgroundWorker.DoWork += _DoAnalysisBackgroundWorker_DoWork;
            }
        }
Beispiel #12
0
 public override InvestmentAction GetActionForDay(DateTime currentDay, StockMarketHistoricalData data)
 {
     if (currentDay.Month == 6 && currentDay.Day == 30)
     {
         return(InvestmentAction.Sell);
     }
     else if (currentDay.Month == 7)
     {
         return(InvestmentAction.NoAction);
     }
     else if (currentDay.Month == 8 && currentDay.Day <= 15)
     {
         return(InvestmentAction.NoAction);
     }
     else if (currentDay.Month == 8 && currentDay.Day > 15)
     {
         return(InvestmentAction.Buy);
     }
     else
     {
         return(InvestmentAction.Buy);
     }
 }
Beispiel #13
0
 public override InvestmentAction GetActionForDay(DateTime currentDay, StockMarketHistoricalData data)
 {
     return(InvestmentAction.NoAction);
 }
Beispiel #14
0
 public abstract InvestmentAction GetActionForDay(DateTime currentDay, StockMarketHistoricalData data);