public static double[] ActivePremium(timeSeries portfolio, timeSeries benchmark, int scale = 252) { Initialize(); var expr = Engine.CallFunction("ActivePremium", portfolio.Expression, benchmark.Expression, Engine.RNumeric(scale)); return(expr.AsNumeric().ToArray()); }
/// <summary> /// /// </summary> /// <param name="asset"></param> /// <param name="riskfree"></param> /// <returns></returns> public static double[] RiskPremium(timeSeries asset, double riskfree) { Initialize(); var expr = Engine.CallFunction("CAPM.RiskPremium", asset.Expression, Engine.RNumeric(riskfree)); return(expr.AsNumeric().ToArray()); }
/// <summary> /// /// </summary> /// <param name="portfolio"></param> /// <returns></returns> public static double[] AnnualisedStdDev(timeSeries portfolio) { Initialize(); var expr = Engine.CallFunction("sd.annualized", portfolio.Expression); return(expr.AsNumeric().ToArray()); }
/// <summary> /// /// </summary> /// <param name="portfolio"></param> /// <param name="benchmark"></param> /// <param name="riskfree"></param> /// <returns></returns> public static double[] Alpha(timeSeries portfolio, timeSeries benchmark, double riskfree) { Initialize(); var expr = Engine.CallFunction("CAPM.alpha", portfolio.Expression, benchmark.Expression, Engine.RNumeric(riskfree)); return(expr.AsNumeric().ToArray()); }
/// <summary> /// /// </summary> /// <param name="benchmark"></param> /// <param name="riskfree"></param> /// <returns></returns> public static double[] CMLSlope(timeSeries benchmark, double riskfree) { Initialize(); var expr = Engine.CallFunction("CAPM.CML.slope", benchmark.Expression, Engine.RNumeric(riskfree)); return(expr.AsNumeric().ToArray()); }
/// <summary> /// /// </summary> /// <param name="portfolio"></param> /// <param name="minreturn"></param> /// <returns></returns> public static double[] SortinoRatio(timeSeries portfolio, timeSeries minreturn) { Initialize(); var expr = Engine.CallFunction("SortinoRatio", portfolio.Expression, minreturn.Expression); return(expr.AsNumeric().ToArray()); }
/// <summary> /// /// </summary> /// <param name="portfolio"></param> /// <param name="benchmark"></param> /// <param name="riskfree"></param> /// <returns></returns> public static double[] InformationRatio(timeSeries portfolio, timeSeries benchmark) { Initialize(); var expr = Engine.CallFunction("InformationRatio", portfolio.Expression, benchmark.Expression); return(expr.AsNumeric().ToArray()); }
public static double[] AnnualisedReturn(timeSeries portfolio, bool geometric = false) { Initialize(); var expr = Engine.CallFunction("Return.annualized", new Tuple <string, SymbolicExpression>("R", portfolio.Expression), new Tuple <string, SymbolicExpression>("geometric", Engine.RBool(geometric))); return(expr.AsNumeric().ToArray()); }
/// <summary> /// /// </summary> /// <param name="portfolio"></param> /// <param name="p"></param> /// <returns></returns> public static double[] HistoricalVaR(timeSeries portfolio, double p) { Initialize(); var expr = Engine.CallFunction("VaR", new Tuple <string, SymbolicExpression>("R", portfolio.Expression), new Tuple <string, SymbolicExpression>("p", Engine.RNumeric(p)), new Tuple <string, SymbolicExpression>("method", Engine.RString("historical"))); return(expr.AsNumeric().ToArray()); }
public void CreateFromTimeSeriesTest() { timeSeries ts = null; /* * Assert.DoesNotThrow(() => * { * ts = timeSeries.Create(TimeSeriesFactory<double>.SampleData.Gaussian.Create(0.01, 0.02, numseries: 10, freq: DataFrequency.Monthly)); * }); */ Engine.Print(ts.Expression); }
/// <summary> /// /// </summary> /// <param name="portfolio"></param> /// <param name="p"></param> /// <returns></returns> public static double[] ConditionalVaR(timeSeries portfolio, double p) { Initialize(); throw new NotImplementedException(); }
public static timeSeries ResidualRisk(timeSeries asset, timeSeries benchmark, double riskfree) { Initialize(); throw new NotImplementedException(); }
public static double[] Kurtosis(timeSeries portfolio) { Initialize(); throw new NotImplementedException(); }
public static double[] SemiVariance(timeSeries portfolio) { Initialize(); throw new NotImplementedException(); }
public static double[] TrackingError(timeSeries portfolio, timeSeries benchmark) { Initialize(); throw new NotImplementedException(); }
/// <summary> /// /// </summary> /// <param name="portfolio"></param> /// <param name="minreturn"></param> /// <param name="method"></param> /// <returns></returns> public static double[] UpsidePotentialRatio(timeSeries portfolio, timeSeries minreturn, string method) { Initialize(); throw new NotImplementedException(); }
private List<double> createInputVector(int counter, timeSeries _ts, forecastSettings _fs, double _maxValue, double _minValue, int _multiplier, double _maxValueT, double _meanValueT, bool replaceOutliers) { var lowerBound = counter - (_fs.energyLags.Max() * _multiplier); if (lowerBound < 0) { return null; } List<double> InputVector = new List<double>(); InputVector.Add(1.0); //добавляем все что только можно //InputVector.Add(Convert.ToDouble(_ts.timestamps[counter].DayOfWeek) / 7); //InputVector.Add(Convert.ToDouble(_ts.timestamps[counter].Month) / 12); //cvPair.InputVector.Add(Convert.ToDouble(_ts.timestamps[i].Hour) / 24); //add status input for (int j = 0; j < _fs.statusLags.Count; j++) { InputVector.Add((Double)_ts.status[counter - _fs.statusLags[j]]); } //add energy inputs double? correctValue = null; if (replaceOutliers) { for (int j = 0; j < _fs.energyLags.Count; j++) { //if (_ts.outlierLabel[counter - (_fs.energyLags[j]*_multiplier)] == 0) { correctValue = _ts.timeseries[counter - (_fs.energyLags[j] * _multiplier)]; break; } } if (correctValue == null) return null; } for (int j = 0; j < _fs.energyLags.Count; j++) { double energyValue; if (replaceOutliers /*&& _ts.outlierLabel[counter - (_fs.energyLags[j]*_multiplier)] != 0*/) { energyValue = correctValue.Value; } else { energyValue = _ts.timeseries[counter - (_fs.energyLags[j] * _multiplier)]; } InputVector.Add((energyValue - _minValue) / (_maxValue - _minValue)); } //int k = 0; //for (int j = 0; j < _fs.energyLags.Count; j++) //{ // if (_ts.status[counter] == _ts.status[counter - (_fs.energyLags[j] * _multiplier)]) // { // InputVector.Add(_ts.timeseries[counter - (_fs.energyLags[j] * _multiplier)] / _maxValue - _minValue); // k++; // } //} //if (k == 0) //{ // Console.WriteLine("SHIT!!!"); // InputVector = null; //} //else //{ // if (k < _fs.energyLags.Count) // { // int dif = Math.Abs(k - _fs.energyLags.Count); // for (int m = 0; m < dif; m++) // { // InputVector.Add(InputVector[_fs.statusLags.Count + 1]); // } // } //} //add temperature inputs for (int j = 0; j < _fs.temparatureLags.Count; j++) { InputVector.Add(_ts.timeseries[counter - (_fs.energyLags[j] * _multiplier)] / _maxValueT - _meanValueT); } //bool ender = false; //int cx = 0; //while (!ender) //{ // if (_ts.status[counter] == _ts.status[counter - (cx + 1) * 7 * _multiplier]) // { // InputVector.Add(_ts.timeseries[counter - ((cx + 1) * 7 * _multiplier)] / _maxValue - _minValue); // cx++; // } // if (cx == _fs.energyLags.Count) // { // ender = true; // } //} return InputVector; }
private List<double> createOutputVector(int counter, timeSeries _ts, forecastSettings _fs, double _maxValue, double _minValue) { List<double> OutputVector = new List<double>(); OutputVector.Add((_ts.timeseries[counter] - _minValue) / (_maxValue - _minValue)); return OutputVector; }
/// <summary> /// /// </summary> /// <param name="portfolio"></param> /// <returns></returns> public static double CalmarRatio(timeSeries portfolio) { Initialize(); throw new NotImplementedException(); }
/// <summary> /// /// </summary> /// <param name="portfolio"></param> /// <param name="benchmark"></param> /// <param name="riskfree"></param> /// <param name="riskaversion"></param> /// <returns></returns> public static double ValueAdded(timeSeries portfolio, timeSeries benchmark, double riskfree, double riskaversion) { Initialize(); throw new NotImplementedException(); }
public timeSeries forecast(timeSeries _ts, int _horizon, forecastSettings _fs) { timeSeries f = _ts; _horizon = 0; //формируем входной вектор List<double> InputVector = new List<double>(); int i = _ts.timeseries.Count - 1; InputVector = createInputVector(i, _ts, _fs, maxValue[counter], minValue[counter], n_timestamps, maxValueT[counter], meanValueT[counter], false); if (InputVector != null) { if (mlnset.Count > counter) { mlnset[counter].propagate(InputVector); foreach (var output in mlnset[counter].Outputs) { f.timestamps[i] = _ts.timestamps[i]; f.timeseries[i] = (output * (maxValue[counter] - minValue[counter]) + minValue[counter]); } counter++; if (counter == n_timestamps) { counter = 0; } } } //if (_ts.timeseries.Count == trainingSize) //{ // //extract training set; // timeSeries trainingTS = _ts.getSample(0, _ts.timeseries.Count); // int _hour = 0; // int _minutes = 0; // for (int i = 0; i < n_timestamps; i++) // { // tslocal.Add(trainingTS.getSample(_hour, _minutes, true)); // _minutes = _minutes + 15; // if (_minutes == 60) // { // _hour++; // _minutes = 0; // } // } // //traing // Console.WriteLine("train"); // trainingEnsemble(tslocal, _fs); //} //else //{ // if (_ts.timeseries.Count > trainingSize) // { // //формируем входной вектор // List<double> InputVector = new List<double>(); // int i = _ts.timeseries.Count - 1; // InputVector = createInputVector(i, _ts, _fs, maxValue[counter], minValue[counter], n_timestamps, maxValueT[counter], meanValueT[counter]); // mlnset[counter].propagate(InputVector); // foreach (var output in mlnset[counter].Outputs) // { // f.timestamps[i] = _ts.timestamps[i]; // f.timeseries[i] = (output + minValue[counter]) * maxValue[counter]; // } // counter++; // if (counter == n_timestamps) // { // counter = 0; // } // } //} return f; }
/// <summary> /// /// </summary> /// <param name="portfolio"></param> /// <param name="excess"></param> /// <returns></returns> public static double SterlingRatio(timeSeries portfolio, double excess = 0.1) { Initialize(); throw new NotImplementedException(); }
/// <summary> /// /// </summary> /// <param name="portfolio"></param> /// <param name="riskfree"></param> /// <returns></returns> public static double[] TreynorRatio(timeSeries portfolio, double riskfree) { Initialize(); throw new NotImplementedException(); }