Overall Statistics |
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 58.222% Drawdown 2.500% Expectancy 0 Net Profit 6.985% Sharpe Ratio 4.106 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.767 Beta -16.257 Annual Standard Deviation 0.111 Annual Variance 0.012 Information Ratio 3.929 Tracking Error 0.111 Treynor Ratio -0.028 Total Fees $3.25 |
namespace QuantConnect.Algorithm.CSharp { /// <summary> /// Basic template algorithm simply initializes the date range and cash. This is a skeleton /// framework you can use for designing an algorithm. /// </summary> public class BasicTemplateAlgorithm : QCAlgorithm { private string _spy_s="SPY"; private TradeBar _workingDailyBar,_workingWeeklyBar; private bool dailydataJustConsolidated = false,weeklydataJustConsolidated = false; private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA); private int totalticks,totaldays; /// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// need to consolidate weekly bars. /// </summary> public override void Initialize() { totalticks=0; totaldays=0; SetStartDate(2013, 10, 03); //Set Start Date SetEndDate(2013, 11, 25); //Set End Date SetCash(100000); //Set Strategy Cash // Find more symbols here: http://quantconnect.com/data // Forex, CFD, Equities Resolutions: Tick, Second, Minute, Hour, Daily. // Futures Resolution: Tick, Second, Minute // Options Resolution: Minute Only. AddEquity(_spy_s, Resolution.Second ); TradeBarConsolidator dailyconsolidator = new TradeBarConsolidator(TimeSpan.FromDays(1) ); dailyconsolidator.DataConsolidated += DailyHandler; SubscriptionManager.AddConsolidator(_spy_s, dailyconsolidator); TradeBarConsolidator weeklyconsolidator = new TradeBarConsolidator(TimeSpan.FromDays(7) ); weeklyconsolidator.DataConsolidated += WeeklyHandler; SubscriptionManager.AddConsolidator(_spy_s, weeklyconsolidator); // The time rule here tells it to fire 10 minutes before SPY's market close Schedule.On(DateRules.EveryDay(_spy_s), TimeRules.BeforeMarketClose(_spy_s, 10), () => { Log("EveryDay.SPY 10 min before close: Fired at: " + Time); }); // There are other assets with similar methods. See "Selecting Options" etc for more details. // AddFuture, AddForex, AddCfd, AddOption } /// <summary> /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. /// </summary> /// <param name="data">Slice object keyed by symbol containing the stock data</param> public override void OnData(Slice data) { ConsolidateDailyWeeklyBars( data); totalticks++; if (!Portfolio.Invested) { SetHoldings(_spy, 1); Debug("Purchased Stock"); } // Log("OnData" + data.Time); } public void OnData(TradeBars data) { // TradeBars objects are piped into this method. Log( "????open" + data["SPY"].Open); } private void ConsolidateDailyWeeklyBars(Slice data) { //https://groups.google.com/forum/#!topic/lean-engine/JRKIP-QDwNs if(_workingWeeklyBar == null || weeklydataJustConsolidated) { } } protected DateTime GetRoundedBarTime(DateTime time) { // return last EOD time return time.RoundDown(TimeSpan.FromDays(1)); } public override void OnEndOfDay(string symbol) { // close up shop each day and reset our 'last' value so we start tomorrow fresh Log("eod data" + symbol + "total ticks" + totalticks); } public override void OnEndOfDay() { // close up shop each day and reset our 'last' value so we start tomorrow fresh Log("eod data" ); } public void WeeklyHandler(object sender, TradeBar data) { Log(" *****WeeklyHandler" + data.EndTime + "total days " + totaldays); totaldays=0; // handle the data each daily here } public void DailyHandler(object sender, TradeBar data) { Log("Daily Handler" + data.EndTime + "total ticks" + totalticks); totalticks=0; totaldays++; // handle the data each daily here } } }