Overall Statistics |
Total Trades 149 Average Win 1.41% Average Loss -1.90% Compounding Annual Return 7.385% Drawdown 18.400% Expectancy 0.417 Net Profit 93.739% Sharpe Ratio 0.658 Loss Rate 19% Win Rate 81% Profit-Loss Ratio 0.74 Alpha 0.047 Beta 0.275 Annual Standard Deviation 0.096 Annual Variance 0.009 Information Ratio 0.022 Tracking Error 0.158 Treynor Ratio 0.229 Total Fees $555.49 |
using System; using System.Collections.Concurrent; namespace QuantConnect { public class BasicTemplateAlgorithm : QCAlgorithm { SecurityChanges _changes = SecurityChanges.None; public const int count = 100; public int CurrentMonth = 0; private readonly ConcurrentDictionary<Symbol, SelectionData> _symbolsData = new ConcurrentDictionary<Symbol, SelectionData>(); public override void Initialize() { UniverseSettings.Leverage = 2.0m; UniverseSettings.Resolution = Resolution.Daily; SetStartDate(2008, 1, 1); SetEndDate(DateTime.Now); SetCash(100*1000); AddUniverse( coarse => { return ( from cf in coarse let avg = _symbolsData.GetOrAdd(cf.Symbol, sym => new SelectionData()) where cf.Price > 10.0m where avg.Update(cf.EndTime,cf.Price) orderby cf.DollarVolume descending select cf.Symbol ).Take(count); } ); } public void OnData(TradeBars data) { if(CurrentMonth != Time.Month) { foreach(var symbol in Portfolio.Keys) { if(_symbolsData[symbol].Months < 6) { _symbolsData[symbol].Months += 1; }else { _symbolsData[symbol].Months = 0; Liquidate(symbol); } } CurrentMonth = Time.Month; IEnumerable<Symbol> highVolatile = ( from sym in data.Keys let info = _symbolsData[sym] orderby info.volatility select sym).Take(count/10); IEnumerable<Symbol> highPerforming = ( from sym in highVolatile let info = _symbolsData[sym] orderby info.momentum descending select sym).Take(1); // IEnumerable<Symbol> lowPerforming = ( from sym in highVolatile // let info = _symbolsData[sym] // orderby info.momentum // select sym).Take(1); foreach(var symbol in highPerforming) { if(data[symbol].Close > 10.0m) { SetHoldings(symbol,(decimal)1/6); _symbolsData[symbol].Months = 1; } } // foreach(var symbol in lowPerforming) // { // SetHoldings(symbol,-(decimal)1/18); // _symbolsData[symbol].Months = 1; // } } } public override void OnSecuritiesChanged(SecurityChanges changes) { _changes = changes; } } }
using System; using System.Collections.Concurrent; using System.Linq; using QuantConnect.Data.Market; using QuantConnect.Data.UniverseSelection; using QuantConnect.Indicators; namespace QuantConnect { public class SelectionData { public int numberOfDay = 0; public struct timePrice { public DateTime time; public decimal price; public timePrice(DateTime _time, decimal _price) { time = _time; price = _price; } } public Queue<timePrice> weeksPrices = new Queue<timePrice>(); public StandardDeviation volatility; public readonly Momentum momentum; private int months; public int Months { get{ return months;} set{ months = value;} } public bool Update(DateTime time, decimal price) { weeksPrices.Enqueue(new timePrice(time,price)); if(numberOfDay >= 7) { timePrice previousDay = weeksPrices.Dequeue(); return momentum.Update(previousDay.time,previousDay.price) && volatility.Update(previousDay.time,previousDay.price); }else { numberOfDay++; return false; } } public SelectionData() { volatility = new StandardDeviation(180); momentum = new Momentum(180); } } }