Overall Statistics |
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 183.401% Drawdown 6.000% Expectancy 0 Net Profit 0% Sharpe Ratio 1.806 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.843 Beta -0.027 Annual Standard Deviation 0.458 Annual Variance 0.21 Information Ratio 0.468 Tracking Error 0.478 Treynor Ratio -30.704 Total Fees $101.94 |
using System; using System.Collections.Generic; using System.Linq; using System.Net; using QuantConnect.Data; using QuantConnect.Data.UniverseSelection; namespace QuantConnect.Algorithm.CSharp { public class DropboxUniverseSelectionAlgorithm : QCAlgorithm { private SecurityChanges _changes = SecurityChanges.None; DateTime _liveDate; static string _liveTime; public override void Initialize() { UniverseSettings.Resolution = Resolution.Daily; SetStartDate(2013, 01, 01); SetEndDate(2013, 01, 10); AddUniverse("my-dropbox-universe", Resolution.Daily, dateTime => { const string liveUrl = @"https://www.dropbox.com/s/qx8hs2q81im9zmu/SymbolToday.csv?dl=1"; const string backtestUrl = @"https://www.dropbox.com/s/qx8hs2q81im9zmu/SymbolToday.csv?dl=1"; var url = LiveMode ? liveUrl : backtestUrl; using (var client = new WebClient()) { //if we're live check DateTime against file and pull our symbol for the day if(LiveMode) { var liveFile = client.DownloadString(url); foreach (var liveLine in liveFile.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)) { var liveCsv = liveLine.Split(','); var liveSymbols = liveCsv[1]; var liveTime = liveCsv[4]; DateTime dt = DateTime.Parse(liveTime); var dtDate = dt.ToString("mmddyyyy"); _liveDate = dt.Date; _liveTime = dt.ToString("HH:mm:ss"); List<string> liveResults = new List<string>(); liveResults.Add(liveSymbols); return liveResults; return Universe.Unchanged; } } //if we're backtesting only return the symbol if(!LiveMode) { var file = client.DownloadString(url); foreach (var line in file.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)) { var csv = line.ToCsv(); var symbols = csv[1]; List<string> results = new List<string>(); results.Add(symbols); return results; } } return Universe.Unchanged; } }); } public void OnData(TradeBars data) { if (data.Count == 0) return; if (_changes == SecurityChanges.None) return; // start fresh Liquidate(); var date = DateTime.Now.Date;//.ToString("MM/dd/yyyy"); var time = DateTime.Now.ToString("HH:mm:ss"); try { if (_liveDate == date) { Log("Match Found!"); var timeCompare = String.Compare(time, _liveTime); if(timeCompare == 1) { Log("Time Found!"); } } } catch{Notify.Sms("+1#######", "Time mismatch: scrape failed");} var percentage = 1m/data.Count; foreach (var tradeBar in data.Values) { SetHoldings(tradeBar.Symbol, percentage); } // reset changes _changes = SecurityChanges.None; } public override void OnSecuritiesChanged(SecurityChanges changes) { _changes = changes; } } }