public static Portfolio CalculateLinearFast(double[,] equity, double reliability, double maximumLoss, double minimumCoefficientValue) { CalculateLinearValidation(reliability, maximumLoss); double[,] deltaEquity = NumericalMethods.CalculateAbsoluteVariation(equity); double[,] sigma = Statistics.CalculateCovarianceMatrix(deltaEquity); Log.Technical("sigma = ", MathFormatProvider.InputStringFromTable(sigma)); double[] profit = Statistics.CalculateAverage(deltaEquity); Log.Technical("sigma = ", MathFormatProvider.InputStringFromData(profit)); int n = profit.Length; Portfolio result = new Portfolio(); result.Coefficients = new double[n]; result.When = double.NaN; bool[] zeros = new bool[n]; bool status = false; do { status = CalculateLinearFastInternal(result, zeros, sigma, profit, reliability, maximumLoss, minimumCoefficientValue, FastAbsoluteMinimalThreshold); } while (!status); return(result); }
public static Portfolio CalculateLinearMarginBalance(PortfolioInput input, Vector[] balance) { CalculateLinearValidation(input.Reliability, input.MaximumLoss); if (input.InitialDeposit <= input.MaximumLoss) { string st = string.Format("Initial deposit = {0} should be more than maximum loss = {1}", input.InitialDeposit, input.MaximumLoss); throw new ArgumentException(); } if (input.MarginLevelThreshold <= 0) { string st = string.Format("Margin level = {0}, but must be positive", input.MarginLevelThreshold); throw new ArgumentException(); } double marginThreshold = (input.InitialDeposit - input.MaximumLoss) / input.MarginLevelThreshold; double[,] deltaEquity = NumericalMethods.CalculateAbsoluteVariation(input.Equity); double[,] sigma = Statistics.CalculateCovarianceMatrix(deltaEquity); int count = sigma.GetLength(0); for (int i = 0; i < count; ++i) { for (int j = 1 + i; j < count; ++j) { sigma[i, j] = 0; sigma[j, i] = 0; } } double[] profit = Statistics.CalculateAverage(deltaEquity); Log.Technical("sigma = {0}", MathFormatProvider.InputStringFromTable(sigma)); Log.Technical("profit = {0}", MathFormatProvider.InputStringFromData(profit)); int n = profit.Length; double[] m = input.Margin.MaximumByRow(); Portfolio result = new Portfolio(); result.Coefficients = new double[n]; result.When = double.NaN; bool[] zeros = new bool[n]; Vector[] _balance = new Vector[balance.Length - 1]; for (int index = 1; index < balance.Length; ++index) { _balance[index - 1] = balance[index] - balance[0]; } double[] margin = input.Margin.MaximumByRow(); bool status = false; do { status = CalculateLinearMarginBalanceInternal(result, zeros, sigma, profit, margin, input, _balance); } while (!status); return(result); }
public static Portfolio CalculateLinearFast(double[,] equity, double[,] margin, double initialDeposit, double reliability, double maximumLoss, double marginLevel, double minimumCoefficientValue) { CalculateLinearValidation(reliability, maximumLoss); if (maximumLoss <= 0) { string st = string.Format("maximumLoss = {0}, but must be positive", maximumLoss); throw new ArgumentException(); } if (initialDeposit <= maximumLoss) { string st = string.Format("Initial deposit = {0} should be more than maximum loss = {1}", initialDeposit, maximumLoss); throw new ArgumentException(); } if (marginLevel <= 0) { string st = string.Format("Margin level = {0}, but must be positive", marginLevel); throw new ArgumentException(); } double marginThreshold = (initialDeposit - maximumLoss) / marginLevel; double[,] deltaEquity = NumericalMethods.CalculateAbsoluteVariation(equity); double[,] sigma = Statistics.CalculateCovarianceMatrix(deltaEquity); double[] profit = Statistics.CalculateAverage(deltaEquity); Log.Technical("sigma = {0}", MathFormatProvider.InputStringFromTable(sigma)); Log.Technical("profit = {0}", MathFormatProvider.InputStringFromData(profit)); int n = profit.Length; double[] m = margin.MaximumByRow(); Portfolio result = new Portfolio(); result.Coefficients = new double[n]; result.When = double.NaN; bool[] zeros = new bool[n]; bool status = false; do { status = CalculateLinearFastInternal(result, zeros, sigma, profit, m, reliability, maximumLoss, minimumCoefficientValue, marginThreshold); } while (!status); return(result); }
public void Add(string name, double[] values) { string st = MathFormatProvider.InputStringFromData(values); this[name] = st; }