Example #1
0
        private string GetMutedLineForday(MoneyDaily day)
        {
            string d = ",";

            //string header = "Date,Closing Value, Rolling Average,One SD Below,Two SD Below,One SD Above,Two SD Above, D(x), D(D(x))";

            string result = day.Date.ToShortDateString() +
                            d + day.CurrentDowJonesData.MutedClosing +
                            d + day.CurrentDowJonesData.MutedClosingAverage +
                            d + day.CurrentDowJonesData.MutedOneStandardDeviationBelowAverage +
                            d + day.CurrentDowJonesData.MutedTwoStandardDeviationsBelowAverage +
                            d + day.CurrentDowJonesData.MutedOneStandardDeviationAboveAverage +
                            d + day.CurrentDowJonesData.MutedTwoStandardDeviationsAboveAverage +
                            d + day.CurrentDowJonesData.MutedFirstDerivativeAverage +
                            d + day.CurrentDowJonesData.MutedSecondDerivativeAverage;

            return(result);
        }
Example #2
0
        private string GetLineForday(MoneyDaily day)
        {
            string d = ",";

            string result = day.Date.ToShortDateString() +
                            d + day.CashOnHand +
                            d + day.ValueOfStockOnHand +
                            d + day.ValueOfStockBought +
                            d + day.ValueOfStockSold +
                            d + day.CurrentDowJonesData.ClosingValue +
                            d + day.CurrentDowJonesData.AverageOverLastXDays +
                            d + day.CurrentDowJonesData.OneStandardDeviationBelowAverage +
                            d + day.CurrentDowJonesData.TwoStandardDeviationsBelowAverage +
                            d + day.CurrentDowJonesData.OneStandardDeviationAboveAverage +
                            d + day.CurrentDowJonesData.TwoStandardDeviationsAboveAverage +
                            d + day.CurrentDowJonesData.FirstDerivativeAverage +
                            d + day.CurrentDowJonesData.SecondDerivativeAverage;


            return(result);
        }
Example #3
0
        public MoneyDaily(MoneyDaily previousDay, StockMarketDaily daily, decimal amountInvested, InvestmentAction investmentAction)
        {
            CashInvested = amountInvested;
            if (previousDay == null)
            {
                previousDay = new MoneyDaily(daily.Date.AddDays(-1));
            }

            // Date is equal to yesterday plus one day
            Date = previousDay.Date.AddDays(1);

            // Current dow jones data for the day
            CurrentDowJonesData = daily;

            //  The Cash on Hand is equal to
            //      The cash on hand yesterday
            //      Plus any investmented money
            //      Plus any sold money
            //      Minus money spend on buying stocks
            CashOnHand = previousDay.CashOnHand + amountInvested + previousDay.ValueOfStockSold - previousDay.ValueOfStockBought;
            CashOnHand = Math.Round(CashOnHand, 2);

            //CashInvested = Math.Round(amountInvested, 2);

            //  The value of the stocks on hand is equal to
            //      The value of the stocks on hand yesterday
            //      Plus The value of any gains in stocks yesterday
            //      Plus The value of of any stocks bought yesterday
            //      Minus the value of stock losses yesterday
            //      Minues the value of stocks sold yesterday
            ValueOfStockOnHand = previousDay.ValueOfStockOnHand + previousDay.ValuesOfStockGains + previousDay.ValueOfStockBought
                                 - previousDay.ValueOfStockSold - previousDay.ValuesOfStockLosses;

            ValueOfStockOnHand = Math.Round(ValueOfStockOnHand, 2);

            // Get Value of Stocks Bought Today
            if (investmentAction == InvestmentAction.Buy)
            {
                ValueOfStockSold   = 0;
                ValueOfStockBought = CashOnHand;
            }
            else if (investmentAction == InvestmentAction.Sell)
            {
                ValueOfStockBought = 0;
                ValueOfStockSold   = ValueOfStockOnHand;
            }
            else
            {
                ValueOfStockBought = 0;
                ValueOfStockSold   = 0;
            }

            ValueOfStockBought = Math.Round(ValueOfStockBought, 2);
            ValueOfStockSold   = Math.Round(ValueOfStockSold, 2);

            // Get value of gains and losses
            var yesterdayData = previousDay.CurrentDowJonesData;

            if (yesterdayData == null)
            {
                // stayed the same
                ValuesOfStockGains  = 0;
                ValuesOfStockLosses = 0;
            }
            else
            {
                var yesterdayValue = previousDay.CurrentDowJonesData.ClosingValue;
                var todayValue     = daily.ClosingValue;
                if (todayValue > yesterdayValue)
                {
                    // had gains
                    decimal gainsPercentage = (todayValue / yesterdayValue) - 1.0M;
                    ValuesOfStockGains = ValueOfStockOnHand * gainsPercentage;
                }
                else if (todayValue < yesterdayValue)
                {
                    // had loses
                    decimal lossPercentage = 1.000M - (todayValue / yesterdayValue);
                    ValuesOfStockLosses = ValueOfStockOnHand * lossPercentage;
                }
                else
                {
                    // stayed the same
                    ValuesOfStockGains  = 0;
                    ValuesOfStockLosses = 0;
                }

                ValuesOfStockLosses = Math.Round(ValuesOfStockLosses, 2);
                ValuesOfStockGains  = Math.Round(ValuesOfStockGains, 2);
            }
        }