コード例 #1
0
ファイル: AnalysisEngine.cs プロジェクト: rfuj0927/sgt
        private void AddRegressionResult(RegressionResult resultToAdd)
        {
            var eh = AAddRegressionResult;

            if (eh != null)
            {
                eh(resultToAdd);
            }
        }
コード例 #2
0
ファイル: SgtMraForm.cs プロジェクト: rfuj0927/sgt
 public void OnAddRegressionResult(RegressionResult r)
 {
     if (this.InvokeRequired)
     {
         this.Invoke((MethodInvoker) delegate {
             // Running on the UI thread
             OnAddRegressionResult(r);
         });
     }
     else
     {
         mRegressionResults.Add(r);
         resultsDgv.Invalidate();
     }
 }
コード例 #3
0
ファイル: AnalysisEngine.cs プロジェクト: rfuj0927/sgt
        private static RegressionResult PerformOls(double[] yVal, string[] xVars, double[][] xVals)
        {
            var ols = new OrdinaryLeastSquares()
            {
                // intercept should represent the return if no impact from inputs. (mean daily return)
                // forcing to 0 as we assume that all explanation of price move should be due to independenet variables.
                // in reality there is likely an unexplainable drift. For example daily bleed (MER, funding etc).
                UseIntercept = false
            };

            MultipleLinearRegression regression = ols.Learn(xVals, yVal);

            double[] predicted = regression.Transform(xVals);

            RegressionResult r = new RegressionResult();

            r.ModelType     = "OLS";
            r.StandardError = regression.GetStandardError(xVals, yVal);
            // r.RSquared = new RSquaredLoss(xVals.Length, yVal, ).Loss(predicted);
            r.RSquared    = regression.CoefficientOfDetermination(xVals, yVal, false);
            r.AdjRSquared = regression.CoefficientOfDetermination(xVals, yVal, true);
            r.Betas       = SgtStringUtils.DoubleArrayToRoundedDelimitedString(regression.Weights);
            r.xVars       = string.Join(";", xVars);

            // TODO need to validate the below section. add p-values?
            double[] coeffStandardErrors = regression.GetStandardErrors(r.StandardError, ols.GetInformationMatrix());
            double[] coeffTScores        = DoubleDivide(regression.Weights, coeffStandardErrors);
            double[] coeffPVals          = new double[coeffTScores.Length];

            double df = xVals.Length - 1;

            for (int i = 0; i < coeffTScores.Length; i++)
            {
                TTest tTest = new TTest(coeffTScores[i], df, OneSampleHypothesis.ValueIsDifferentFromHypothesis);
                coeffPVals[i] = tTest.PValue;
            }

            r.CoeffStandardErrors = SgtStringUtils.DoubleArrayToRoundedDelimitedString(coeffStandardErrors);
            r.CoeffTScores        = SgtStringUtils.DoubleArrayToRoundedDelimitedString(coeffTScores);
            r.CoeffPVals          = SgtStringUtils.DoubleArrayToRoundedDelimitedString(coeffPVals);
            // /TODO

            r.xVarCount    = regression.NumberOfInputs;
            r.SamplesCount = yVal.Length;
            r.Mean         = regression.Intercept;

            return(r);
        }
コード例 #4
0
ファイル: AnalysisEngine.cs プロジェクト: rfuj0927/sgt
        private RegressionResult PerformUnhedged(double[] yVal)
        {
            RegressionResult r       = new RegressionResult();
            double           average = yVal.Average();

            r.Mean = average;

            double sumOfSquaresOfDifferences = yVal.Select(val => (val - average) * (val - average)).Sum();
            double sd = Math.Sqrt(sumOfSquaresOfDifferences / (yVal.Length - 1));

            r.ModelType     = "UNHEDGED";
            r.RSquared      = 0;
            r.AdjRSquared   = 0;
            r.StandardError = sd;
            r.xVarCount     = 0;
            r.SamplesCount  = yVal.Length;

            return(r);
        }