Exemplo n.º 1
0
        public static void Detrend(DataHolder dataHolder)
        {
            var length = dataHolder.Candles.Count;

            double firstLogValue = Math.Log(dataHolder.Candles[0].Close);
            double lastLogValue  = Math.Log(dataHolder.Candles[length - 1].Close);

            double difference = (lastLogValue - firstLogValue) / length;

            for (int i = 0; i < length; i++)
            {
                dataHolder.DetrenedValues.Add(new DetrendedValue()
                {
                    Date  = dataHolder.Candles[i].Date,
                    Value = Math.Exp(Math.Log(dataHolder.Candles[i].Close) - i * difference)
                });
            }
        }
Exemplo n.º 2
0
        internal static void LoadData(string dataFilePath, DataHolder dataHolder)
        {
            string line;
            var    isFirstLine = true;

            using (var sr = new StreamReader(dataFilePath))
            {
                while ((line = sr.ReadLine()) != null)
                {
                    if (isFirstLine)
                    {
                        isFirstLine = false; continue;
                    }

                    var candle = ProcessLine(line);

                    dataHolder.Candles.Add(candle);
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //TestLinearRegression tr = new TestLinearRegression();

            //return;
            var vtbDataFilePath = @"AppData\ICE.BRN_090803_140803.txt";
            var sbrDataFilePath = @"AppData\SBER_100526_101231.txt";

            var vtbDataHolder = new DataHolder();
            var sbrDataHolder = new DataHolder();

            DataLoader.LoadData(vtbDataFilePath, vtbDataHolder);
            DataLoader.LoadData(sbrDataFilePath, sbrDataHolder);

            LinearDetrender.Detrend(vtbDataHolder);
            LinearDetrender.Detrend(sbrDataHolder);

            var dataWriter = new DetrendedValueResultGenerator();

            dataWriter.WriteData(sbrDataHolder);
        }
        internal void WriteData(DataHolder result)
        {
            var directoryPath  = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\R\Data";
            var resultDataPath = directoryPath + "\\" + "Result.txt";

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            using (var fileStream = new FileStream(resultDataPath, FileMode.Create))
            {
                using (var writer = new StreamWriter(fileStream))
                {
                    writer.WriteLine("V DV");

                    for (int i = 0; i < result.Candles.Count; i++)
                    {
                        writer.WriteLine("{0} {1}", result.Candles[i].Close, result.DetrenedValues[i].Value);
                    }
                }
            }
        }
Exemplo n.º 5
0
 public MonthlyDistributionRule(DataHolder usdrubDataHolder)
 {
     this._usdrubDataHolder = usdrubDataHolder;
 }
Exemplo n.º 6
0
 public void Calculate(LogScaleDetrendedChangesValuator logScaleDetrendedChangesValuator, DataHolder dataHolder)
 {
     dataHolder.Changes = logScaleDetrendedChangesValuator.Valuate(dataHolder.Candles);
 }