Overall Statistics |
Total Trades 397 Average Win 1.76% Average Loss -2.05% Compounding Annual Return -2.535% Drawdown 52.300% Expectancy 0.067 Net Profit -5.006% Sharpe Ratio 0.209 Loss Rate 43% Win Rate 57% Profit-Loss Ratio 0.86 Alpha 0.097 Beta 0.069 Annual Standard Deviation 0.484 Annual Variance 0.234 Information Ratio 0.092 Tracking Error 0.495 Treynor Ratio 1.462 Total Fees $755.54 |
using MathNet.Numerics.Statistics; namespace QuantConnect { public class TradingTheOdds : QCAlgorithm { RollingWindow<double> _closingPrices; ExponentialMovingAverage _ema; string _symbolVIX = "YAHOO/INDEX_VIX"; public override void Initialize() { SetStartDate(2014, 1, 1); SetEndDate(2016,1,1); SetCash(25000); AddSecurity(SecurityType.Equity, "SPY", Resolution.Daily); AddSecurity(SecurityType.Equity, "XIV", Resolution.Daily); AddSecurity(SecurityType.Equity, "VXX", Resolution.Daily); //AddData<Quandl>(_symbolVIX, Resolution.Daily); AddData<Quandl>(_symbolVIX, Resolution.Daily); //Initialize: _closingPrices = new RollingWindow<double>(5); _ema = new ExponentialMovingAverage("AvgVixLessASTD", 5); } public override void OnData(Slice data) { //Save off the closing prices _closingPrices.Add((double)data.Bars["SPY"].Close); //Wait till we've got a week data: if (!_closingPrices.IsReady) return; //Save Vix price: var vix = data.Get<Quandl>(_symbolVIX); //Calculate the annualized standard deviation of the last 2 days //standard deviation((LN(todaysclose/yesterdaysclose), LN(yesterdaysclose/twodaysagoclose)) * 100 * sqrt(252)) var samples = new List<double>() { Math.Log(_closingPrices[0]/_closingPrices[1]), Math.Log(_closingPrices[1]/_closingPrices[2]) }; var astd = (decimal) (samples.StandardDeviation() * Convert.ToDouble(Math.Pow(252, 0.5)) * 100); //Calculate the raw unaveraged value: _ema.Update(new IndicatorDataPoint(Time, vix.Value - astd)); //More than 5 EMA points: if (_ema.IsReady) { Log(string.Format("EMA : {0}, VIX : {1}, ASTD : {2}", _ema, vix.Value, astd)); if (_ema > 1.0) { SetHoldings("XIV", 0.9, true); } else { SetHoldings("VXX", 0.9, true); } } } } }