Exemplo n.º 1
0
        public static DailyStockValues FromCsv(string csvLineAsString)
        {
            DailyStockValues values = null;

            try {
                string [] parsed = csvLineAsString.Split(',');
                values = new DailyStockValues(parsed [0], parsed [1], parsed [2], parsed [3], parsed [4], parsed [5], parsed [6]);
            }
            catch (Exception ex) {
                Utils.WriteToConsole(Utils.ExToString(ex), true, "DailyStockValues.FromCsv");
            }
            return(values);
        }
Exemplo n.º 2
0
        private static List <DailyStockValues> ReadStockFile(this PathInfo pi)
        {
            List <DailyStockValues> values = null;

            try {
                values = File.ReadAllLines(pi.FullPath)
                         .Skip(1)
                         .Select(v => DailyStockValues.FromCsv(v))
                         .ToList();
            }
            catch (Exception ex) {
                Utils.WriteToConsole($"{Utils.ExToString (ex)} { currentTicker}", true, "ReadStockFile");
            }
            return(values);
        }
Exemplo n.º 3
0
        private static DailyFloatValues CalculateFloat(this List <DailyStockValues> values, long flt, int idx)
        {
            DailyFloatValues fv = null;

            try {
                var              cnt       = values.Count;
                long             vol       = 0;
                decimal          high      = 0;
                decimal          low       = 0;
                DateTime?        endDate   = null;
                DateTime?        startDate = null;
                DailyStockValues today     = null;

                for (var i = idx; i >= 0; i--)
                {
                    today = values [i];
                    if (!endDate.HasValue)
                    {
                        endDate = today.Date;
                    }
                    if (high < today.High)
                    {
                        high = today.High;
                    }
                    if (low == 0 || low > today.Low)
                    {
                        low = today.Low;
                    }
                    vol += today.Volume;
                    if (vol >= flt)
                    {
                        startDate = today.Date;
                        break;
                    }
                }

                fv = new DailyFloatValues {
                    EndDate   = endDate.Value,
                    High      = high,
                    Low       = low,
                    Signal    = (vol < flt) ? FloatSignal.Unknown : FloatSignal.Neutral,
                    StartDate = (vol < flt) ? today.Date : startDate.Value
                };

                if (vol >= flt && idx > 0)
                {
                    today = values [idx];
                    var yesterday = values [idx - 1];
                    if (today.High == high && yesterday.High < high)
                    {
                        fv.Signal = FloatSignal.Buy;
                    }
                    else if (today.Low == low && yesterday.Low > low)
                    {
                        fv.Signal = FloatSignal.Sell;
                    }
                }
            }
            catch (Exception ex) {
                Utils.WriteToConsole($"{Utils.ExToString (ex)} { currentTicker}", true, "CalculateFloat");
            }
            return(fv);
        }