Overall Statistics |
Total Trades 418 Average Win 0.01% Average Loss -0.01% Compounding Annual Return -0.379% Drawdown 0.600% Expectancy -0.155 Net Profit -0.310% Sharpe Ratio -1.498 Loss Rate 62% Win Rate 38% Profit-Loss Ratio 1.21 Alpha -0.003 Beta -0.002 Annual Standard Deviation 0.002 Annual Variance 0 Information Ratio -0.467 Tracking Error 0.116 Treynor Ratio 1.514 Total Fees $865.09 |
namespace QuantConnect { public class TimeAlphaAlgorithm : QCAlgorithm { TradeBars price; Dictionary<string, OrderTicket> stopTickets = new Dictionary<string, OrderTicket>(); decimal riskPerTrade = 100; Dictionary<string, StandardDeviation> std = new Dictionary<string, StandardDeviation>(); List<string> symbols = new List<string>(){"EURUSD" /* "AUDCAD", "AUDCHF", "AUDJPY", "AUDNZD", "AUDUSD", "CADCHF", "CADJPY", "CHFJPY", "EURAUD", "EURCAD", "EURCHF", "EURGBP", "EURJPY", "EURNOK", "EURNZD", "EURSEK", "EURTRY", "EURUSD", "GBPAUD", "GBPCAD", "GBPCHF", "GBPJPY", "GBPNZD", "GBPUSD", "NZDCAD", "NZDCHF", "NZDJPY",/* "NZDUSD", "TRYJPY", "USDCAD", "USDCHF", "USDCNH", "USDJPY", "USDMXN", "USDNOK", "USDSEK", "USDTRY", "USDZAR", "ZARJPY"*/ }; public override void Initialize() { SetStartDate(2016, 1, 1); SetEndDate(DateTime.Now); SetCash(1000000); foreach(var symbol in symbols) { AddSecurity(SecurityType.Forex, symbol, Resolution.Minute); std.Add(symbol, STD(symbol, 390)); stopTickets.Add(symbol,null); } var days = new [] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday }; Schedule.On(DateRules.Every(days),TimeRules.At(9, 30), () => { foreach(var symbol in symbols) { PlaceOrder(symbol); } }); Schedule.On(DateRules.Every(days),TimeRules.At(16, 0), () => { Plot("STD","EURUSD",std["EURUSD"]); foreach(var symbol in symbols) { Liquidate(symbol); /* if (stopTickets.ContainsKey(symbol)) { if (stopTickets[symbol] != null) stopTickets[symbol].Cancel(); }*/ } }); } private void PlaceOrder(Symbol symbol) { if (!std.ContainsKey(symbol)) return; var deviation = std[symbol]; var potentialMovement = deviation*2m; if (price == null) return; if (!price.ContainsKey(symbol)) { return; } if (!stopTickets.ContainsKey(symbol)) { return; } if (price[symbol].Close == 0) return; if (potentialMovement == 0) return; var qty = ((int)(riskPerTrade / potentialMovement) * 1000) / 1000; if (qty > 0){ Log(symbol+" "+qty.ToString()); MarketOrder(symbol, qty); stopTickets[symbol] = StopMarketOrder(symbol, -qty, Math.Round(price[symbol].Close - potentialMovement, 5)); } } public void OnData(TradeBars data) { price = data; } } }