Overall Statistics |
Total Trades 1 Average Win 27.62% Average Loss 0% Compounding Annual Return 11.697% Drawdown 5.900% Expectancy 0 Net Profit 27.618% Sharpe Ratio 1.576 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha -0.005 Beta 0.598 Annual Standard Deviation 0.068 Annual Variance 0.005 Information Ratio -1.7 Tracking Error 0.047 Treynor Ratio 0.18 |
namespace QuantConnect { /* * QuantConnect University: Consolidators - Creating custom timespan events. * * Consolidators are tools inside of LEAN to merge data into single bars. They are * very flexible and can generate events which trigger from any timespan. */ public class ConsolidatorAlgorithm : QCAlgorithm { TradeBar _spyDaily; public override void Initialize() { SetStartDate(2013, 1, 1); SetEndDate(DateTime.Now.Date.AddDays(-1)); SetCash(25000); AddSecurity(SecurityType.Equity, "SPY", Resolution.Minute); // define our daily trade bar consolidator. we can access the daily bar // from the DataConsolidated events var dailyConsolidator = new TradeBarConsolidator(TimeSpan.FromDays(1)); // attach our event handler. the event handler is a function that will be called each time we produce // a new consolidated piece of data. dailyConsolidator.DataConsolidated += OnDataDaily; // this call adds our daily consolidator to the manager to receive updates from the engine SubscriptionManager.AddConsolidator("SPY", dailyConsolidator); } /// <summary> /// This is our event handler for our daily trade bar defined above in Initialize(). So each time the consolidator /// produces a new daily bar, this function will be called automatically. The 'sender' parameter will be the /// instance of the IDataConsolidator that invoked the event, but you'll almost never need that! /// </summary> private void OnDataDaily(object sender, TradeBar consolidated) { _spyDaily = consolidated; Log(consolidated.Time.ToString("o") + " >> SPY >> LONG >> 100 >> " + Portfolio["SPY"].Quantity); } //Traditional 1 minute events here: public void OnData(TradeBars data) { if (!Portfolio.HoldStock) { Order("SPY", 100); } } } }