Overall Statistics |
Total Trades 1 Average Win 93.15% Average Loss 0% Compounding Annual Return 14.086% Drawdown 19.900% Expectancy 0 Net Profit 93.151% Sharpe Ratio 0.912 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.002 Beta 1 Annual Standard Deviation 0.158 Annual Variance 0.025 Information Ratio 0.107 Tracking Error 0.014 Treynor Ratio 0.144 Total Fees $9.26 |
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using QuantConnect.Data; using QuantConnect.Data.Market; using QuantConnect.Data.Consolidators; namespace QuantConnect.Algorithm.Examples { /// <summary> /// Algorithm that plots data in the past /// </summary> public class PastPlottingAlgorithm : QCAlgorithm { Series pastData; bool first = true; SomeOtherClass someOtherClass; /// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> public override void Initialize() { SetStartDate(2010, 05, 03); SetEndDate(2015, 04, 30); AddSecurity(SecurityType.Equity, "SPY"); // create our object and pass a reference to our algorithm someOtherClass = new SomeOtherClass(this); } /// <summary> /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. /// </summary> /// <param name="data">TradeBars IDictionary object with your stock data</param> public void OnData(TradeBars data) { if (!Portfolio.Invested) { SetHoldings("SPY", 0.5m); } if (first) { first = false; pastData = someOtherClass.InitializeChart(); } // plot every morning at 930 if (data["SPY"].Time.TimeOfDay.TotalHours == 9.5 && Time.Date > new DateTime(2010, 06, 01)) { pastData.AddPoint(Time.Subtract(TimeSpan.FromDays(15)), data["SPY"].Price); } } } }
using System; using System.Collections; using System.Collections.Generic; using QuantConnect.Securities; using QuantConnect.Models; namespace QuantConnect { // Shows how we can still call algorithm method from other files/classes public class SomeOtherClass { private readonly QCAlgorithm _algorithm; // this is a constructor and accepts an algorithm instance public SomeOtherClass(QCAlgorithm algorithm) { _algorithm = algorithm; } // creates a chart and adds it to the algorithm public Series InitializeChart() { var chart = new Chart("SPY"); var series = new Series("past-data"); chart.AddSeries(series); _algorithm.AddChart(chart); return series; } } }