Overall Statistics |
Total Trades 26 Average Win 479.29% Average Loss -13.64% Compounding Annual Return 10.373% Drawdown 84.100% Expectancy 5.774 Net Profit 161.806% Sharpe Ratio 0.437 Loss Rate 81% Win Rate 19% Profit-Loss Ratio 35.13 Alpha 0.206 Beta 0.046 Annual Standard Deviation 0.48 Annual Variance 0.23 Information Ratio 0.229 Tracking Error 0.516 Treynor Ratio 4.607 Total Fees $242.07 |
namespace QuantConnect { public class BasicTemplateAlgorithm : QCAlgorithm { private RateOfChangePercent ROCPyear; private RateOfChange ROCPROCPyear; //private ROCPRateOfChangePercent ROCPROCPyear; private string symbol; public override void Initialize() { SetStartDate(2006, 1, 1); SetEndDate(DateTime.Now); SetCash(25000); symbol = "LNG"; AddSecurity(SecurityType.Equity, symbol, Resolution.Daily); ROCPyear = new RateOfChangePercent(252); // 252 trading days in a US year RegisterIndicator(symbol, ROCPyear, Resolution.Daily, Field.Close); PlotIndicator("ROCP", true, ROCPyear); ROCPROCPyear = new RateOfChange(252).Of(ROCPyear); //ROCPROCPyear = new ROCPRateOfChangePercent(252); //RegisterIndicator(symbol, ROCPROCPyear, Resolution.Daily, Field.Close); PlotIndicator("ROCP", true, ROCPROCPyear); } //Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol. public void OnData(TradeBars data) { if (!ROCPyear.IsReady) return; var quantity = Portfolio[symbol].Quantity; if (quantity == 0 && ROCPyear > 20) { SetHoldings(symbol, .75); } if (quantity > 0) { if (ROCPyear < 0) { SetHoldings(symbol, 0); } } if (quantity < 0) { if (ROCPyear > 0) { SetHoldings(symbol, 0); } } if (quantity == 0 && ROCPyear < -20) { SetHoldings(symbol, -.75); } } } }
using MathNet.Numerics; namespace QuantConnect { public class AnnualizedExponentialSlope : WindowIndicator<IndicatorDataPoint> { public AnnualizedExponentialSlope(int period) : base("AdjustedSlope" + period, period) { } public AnnualizedExponentialSlope(string name, int period) : base(name, period) { } protected override decimal ComputeNextValue(IReadOnlyWindow<IndicatorDataPoint> window, IndicatorDataPoint input) { if (window.Count < 3) return 0m; var xVals = new double[window.Count]; var yVals = new double[window.Count]; // load input data for regression for (int i = 0; i < window.Count; i++) { xVals[i] = i; // we want the log of our y values yVals[i] = Math.Log((double)window[window.Count - i - 1].Value); } //http://numerics.mathdotnet.com/Regression.html // solves y=a + b*x via linear regression var fit = Fit.Line(xVals, yVals); var intercept = fit.Item1; var slope = fit.Item2; // compute rsquared var rsquared = GoodnessOfFit.RSquared(xVals.Select(x => intercept + slope*x), yVals); // anything this small can be viewed as flat if (double.IsNaN(slope) || Math.Abs(slope) < 1e-25) return 0m; // trading days per year for us equities const int dayCount = 252; // annualize dy/dt var annualSlope = ((Math.Pow(Math.Exp(slope), dayCount)) - 1) * 100; // scale with rsquared annualSlope = annualSlope * rsquared; return (decimal) annualSlope; } } }