Overall Statistics |
Total Trades 2 Average Win 2.27% Average Loss 0% Compounding Annual Return 113.409% Drawdown 0.100% Expectancy 0 Net Profit 2.134% Sharpe Ratio 5.292 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.699 Beta 0.477 Annual Standard Deviation 0.113 Annual Variance 0.013 Information Ratio 7.156 Tracking Error 0.113 Treynor Ratio 1.253 Total Fees $3.63 |
using System; using QuantConnect.Securities; using QuantConnect.Orders.Fees; using QuantConnect.Notifications; using QuantConnect.Orders; using QuantConnect.Data.Market; using QuantConnect.Packets; using QuantConnect.Util; using System.Reflection; using QuantConnect.Scheduling; using System.Linq; using System.Net; namespace QuantConnect { public class BasicTemplateAlgorithm : QCAlgorithm { string symbol; int _holdings; decimal _pct; bool first = true; static string globalString; static decimal _symPrice; static decimal _profits; bool ready = false; const decimal StopLossPercent = 0.003m; private decimal highestPrice = 0.0m; private OrderTicket CurrentOrder; private OrderTicket StopLoss; string time; string date; string utctime; string utcdate; const string url = @"https://www.dropbox.com/s/qx8hs2q81im9zmu/SymbolToday.csv?dl=1"; public override void Initialize() { SetBrokerageModel(BrokerageName.TradierBrokerage, AccountType.Cash); SetStartDate(2016, 03, 20); SetEndDate(DateTime.Now.Date.AddDays(-1)); SetCash(2750); _pct = Portfolio.Cash/3 * .03m; AddSecurity(SecurityType.Equity, "SPY", Resolution.Daily); Schedule.Event().EveryDay().At(9,35).Run(() => { using (var client = new WebClient()) { var file = client.DownloadString(url); var csv = file.Split(','); var csvdatetime = csv[4]; symbol = csv[1]; DateTime dt = DateTime.Parse(csvdatetime); time = dt.ToString("HH:mm:ss"); date = dt.Date.ToString("MM/dd/yyyy"); utctime = UtcTime.ToString("HH:mm:ss"); utcdate = UtcTime.Date.ToString("MM/dd/yyyy"); Log("t"+time); Log("d"+date); Log("ut"+utctime); Log("ud"+utcdate); } AddSecurity(SecurityType.Equity, symbol, Resolution.Second, fillDataForward: true, extendedMarketHours: false, leverage: 1); }); } //public void PostInitialize() //{ //} public void OnData(TradeBars data) { if (!data.ContainsKey(symbol)) return; _symPrice = data[symbol].Price; _profits = Portfolio.TotalUnrealizedProfit; var shareCount = CalculateOrderQuantity(symbol, 1m/3); //if(date = utcdate) //{ if(first) { first = false; CurrentOrder = Order(symbol, shareCount); StopLoss = StopMarketOrder(symbol, -shareCount, _symPrice * (1m - .03m)); Notify.Sms("+15126454560", "Buy " + globalString); } //} if (Portfolio.HoldStock) { if (_symPrice > highestPrice && _profits > _pct) { highestPrice = _symPrice; StopLoss.Update(new UpdateOrderFields{ StopPrice = _symPrice * (1m - StopLossPercent) }); } Schedule.Event().EveryDay().BeforeMarketClose(symbol, 1).Run(() => { Liquidate(); }); } string messageString = String.Format("{0} \nTime: {1} \nPrice: {2} \nProfit: {3} \nHigh {4}", symbol, time, _symPrice.ToString(), _profits, StopLoss.ToString()); globalString = messageString; } } }