public App()
        {
            int i       = 3;
            var RawData = DataPreparer.Splicer(i);

            Constants.Item    item = Constants.Item.GetItem(RawData, 4000);
            Constants.RawData raw  = Constants.Item.GetRawData();
            //series.InitializeComponent();
            MainWindow window = new MainWindow();

            window.InitializeComponent();
        }
Пример #2
0
        private static double StrdErrorSolver(List <double> Quant, List <double> Prediction)
        {
            double        Err    = 0;
            List <double> deStrd = DataPreparer.DeStrd(Prediction);

            for (int i = 0; i < Quant.Count(); i++)
            {
                var PredErr = Quant.ElementAt(i) - deStrd.ElementAt(i);
                Err += Math.Pow(PredErr, 2);
            }
            return(Err);
        }
Пример #3
0
        public static void Main(string[] args)
        {
            int i = 3;

            Console.WriteLine("Operation on dataset: Item ({0})...", Constants.id[i]);
            //get initial data from files
            var RawData = DataPreparer.Splicer(i);

            Console.WriteLine("Getting data from files");
            //subset length, total set size is 4*n (buy/sell quant, buy/sell price)
            //trim dataset to n before singleton implemented!
            int n = 4000;

            Console.WriteLine("trimmng datset...");
            DataPreparer.Trimmer(RawData, n);
            //get item specific data for raw dataset as a singleton class
            Console.WriteLine("Getting item...");
            Constants.Item    item = Constants.Item.GetItem(RawData, n);
            Constants.RawData Data = Constants.Item.GetRawData();
            //standardised dataset as well as weighted and standardised weighted data
            Console.WriteLine("Standardising dataset");
            Constants.StrdData strdData = DataPreparer.Z_Score(Data);
            //LSR fitting solutions to each set (standardised & non-standardised)
            Console.WriteLine("Fitting function parameters");
            double[,] FitEq     = FittingFunctions.FitLin(Data, n);
            double[,] StrdFitEq = FittingFunctions.StrdFitLin(strdData, n);
            Constants.DataInfo Info = DataPreparer.DataInfo();
            Console.WriteLine("Getting model information");
            double[] Corrs = ModelInfo.CorrCoeff(Data, Info);
            //Get prediction lists and convert to List<int> for StrdDev function
            var        _DemPreds = FittingFunctions.Predictor(Data.BuyPrice, FitEq[0, 0], FitEq[1, 0]);
            List <int> DemPreds  = _DemPreds.Select(x => (int)x).ToList();
            var        _SupPreds = FittingFunctions.Predictor(Data.SellPrice, FitEq[0, 1], FitEq[1, 1]);
            List <int> SupPreds  = _SupPreds.Select(x => (int)x).ToList();

            //Standard deviations of data, standard deviations of predicted data & correlations
            double[] FitData =
            {
                ModelInfo.StrdDev(Data.SellQuantity, Info.SellQuantInfo, n),
                ModelInfo.StrdDev(Data.BuyQuantity,  Info.BuyQuantInfo,  n),
                ModelInfo.StrdDev(DemPreds,          Info.BuyQuantInfo,  n),
                ModelInfo.StrdDev(SupPreds,          Info.BuyQuantInfo,  n),
                ModelInfo.RMSE(FitEq[2,                              0], n),ModelInfo.RMSE(FitEq[2,1], n),
                Corrs[0],                            Corrs[1]
            };
            Console.WriteLine("Printing results to files...");
            DataWriter.FileMaker(Info, i, FitEq, StrdFitEq, FitData);
            Console.Write("Check the desktop!");
            Console.ReadLine();
        }
Пример #4
0
        public TimeSeries()
        {
            InitializeComponent();
            Constants.RawData data = Constants.Item.GetRawData();
            int n    = Constants.Item.GetCount();
            var Ewma = DataPreparer.Weighter(data, 0.5);

            YFormatter = value => value.ToString("C");

            List <double> BuyQ  = data.BuyQuantity.Select <int, double>(i => i).ToList();
            List <double> BuyP  = data.BuyPrice.Select <int, double>(i => i).ToList();
            List <double> SellQ = data.SellQuantity.Select <int, double>(i => i).ToList();
            List <double> SellP = data.SellPrice.Select <int, double>(i => i).ToList();

            for (int i = 0; i < BuyQ.Count(); i++)
            {
                EWMAPrice.Add(new ObservablePoint(i, Ewma._strdBuyPrice.ElementAt(i)));
                Price.Add(new ObservablePoint(i, BuyP.ElementAt(i)));
            }
            DataContext = this;
        }
Пример #5
0
        /// <summary>
        /// Fits a line in a univariate analysis to data
        /// </summary>
        /// <param name="data">Input</param>
        /// <param name="n">Range of Input</param>
        /// <returns>Fit Param's, first column is gradients</returns>
        public static double[,] FitLin(Constants.RawData data, int n)
        {
            //S(p)=BuyQuantity = b + m*SellPrice
            //D(p)=SellQuantity = b - m*BuyPrice
            double[,] Params = new double[3, 2];
            var BQuant = data.BuyQuantity;
            var BPrice = data.BuyPrice;
            var SQuant = data.SellQuantity;
            var SPrice = data.SellPrice;

            //array location 0, 0 is mean value
            var InfoObject = DataPreparer.DataInfo();
            var BPMean     = (double)InfoObject.BuyPriceInfo[0, 0];
            var BQMean     = (double)InfoObject.BuyQuantInfo[0, 0];
            var SPMean     = (double)InfoObject.SellPriceInfo[0, 0];
            var SQMean     = (double)InfoObject.SellQuantInfo[0, 0];

            //return B1/Grad for demand and supply
            var GradDem = GradSolver(BPrice, SQuant, n, BPMean, SQMean);
            var GradSup = GradSolver(SPrice, BQuant, n, SPMean, BQMean);
            //return B0/intercept for demand and supply
            var DemInt = IntSolver(GradDem, SQMean, BPMean);
            var SupInt = IntSolver(GradSup, BQMean, SPMean);
            //create predictions of data and add to predictions lists
            var PredDem = Predictor(BPrice, GradDem, DemInt);
            var PredSup = Predictor(SPrice, GradSup, SupInt);
            //return error on predicitons
            var DemErr = ErrorSolver(SQuant, PredDem);
            var SupErr = ErrorSolver(BQuant, PredSup);

            //add to Params and return
            Params[0, 0] = Math.Round(GradDem);
            Params[0, 1] = Math.Round(GradSup);
            Params[1, 0] = Math.Round(DemInt);
            Params[1, 1] = Math.Round(SupInt);
            Params[2, 0] = Math.Round(DemErr);
            Params[2, 1] = Math.Round(SupErr);
            Console.WriteLine(Params[2, 1]);
            return(Params);
        }
Пример #6
0
        /// <summary>
        /// Fit to a standardised data set then return de-standardized values
        /// </summary>
        /// <param name="strdData"></param>
        /// <param name="n">Dataset length</param>
        /// <returns></returns>
        public static double[,] StrdFitLin(Constants.StrdData strdData, int n)
        {
            //S(p)=SellQuantity = b + m*BuyPrice
            //D(p)=BuyQuantity = b + m*SellPrice
            double[,] Params = new double[3, 2];
            var BQuant = strdData._strdBuyQuant;
            var BPrice = strdData._strdBuyPrice;
            var SQuant = strdData._strdSellQuant;
            var SPrice = strdData._strdSellPrice;

            var InfoObject = DataPreparer.StrdDataInfo(strdData);
            //array location 0, 0 is mean value
            var BPMean = (double)InfoObject.BuyPriceInfo[0, 0];
            var BQMean = (double)InfoObject.BuyQuantInfo[0, 0];
            var SPMean = (double)InfoObject.SellPriceInfo[0, 0];
            var SQMean = (double)InfoObject.SellQuantInfo[0, 0];

            //return B1/Grad for demand and supply
            var GradDem = StrdGradSolver(SPrice, BQuant, n, SPMean, BQMean);
            var GradSup = StrdGradSolver(BPrice, SQuant, n, BPMean, SQMean);
            //return B0/intercept for demand and supply
            var DemInt = IntSolver(GradDem, BQMean, SPMean);
            var SupInt = IntSolver(GradSup, SQMean, BPMean);
            //create predictions of data and add to predictions lists
            var PredDem = StrdPredictor(SPrice, GradSup, SupInt);
            var PredSup = StrdPredictor(BPrice, GradDem, DemInt);
            //return error on predicitons
            var DemErr = StrdErrorSolver(BQuant, PredDem);
            var SupErr = StrdErrorSolver(SQuant, PredSup);

            //add to Params and return
            Params[0, 0] = GradDem;
            Params[0, 1] = GradSup;
            Params[1, 0] = DemInt;
            Params[1, 1] = SupInt;
            Params[2, 0] = DemErr;
            Params[2, 1] = SupErr;
            return(Params);
        }