Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio NaN Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha NaN Beta NaN Annual Standard Deviation NaN Annual Variance NaN Information Ratio NaN Tracking Error NaN Treynor Ratio NaN Total Fees $0.00 |
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> /// Testing algorithm simply initializes the date range and cash /// </summary> public class TestingCustomDataAlgo : QCAlgorithm { /// <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(new DateTime(2010, 05, 03, 00, 00, 00)); SetEndDate(2010, 06, 01); AddData<EURUSD>("EURUSD"); //create an event to handle the hourly bars var consolidator = ResolveConsolidator("EURUSD", Resolution.Daily); consolidator.DataConsolidated += HourBarHandler; SubscriptionManager.AddConsolidator("EURUSD", consolidator); var dtbConsolidator = new DailyTradeBarConsolidator(); dtbConsolidator.DataConsolidated += DayBarHandler; SubscriptionManager.AddConsolidator("EURUSD", dtbConsolidator); } private void DayBarHandler(object sender, BaseData consolidated) { Console.WriteLine("\nDBH Consolidated Time: " + consolidated.Time.DayOfWeek + " at " + consolidated.Time); } /// <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(EURUSD data) { //Console.WriteLine("Time: " + data.Time); } private void HourBarHandler(object sender, BaseData consolidated) { Console.WriteLine("\nConsolidated Time: " + consolidated.Time.DayOfWeek + " at " + consolidated.Time); //Debug("\nConsolidated Daily Time: " + consolidated.Time); } } /// <summary> /// ad hoc fix for daily close issue /// </summary> public class DailyTradeBarConsolidator : DataConsolidator<TradeBar> { private TradeBar _working; /// <summary> /// OutputType returns a Type? /// </summary> public override Type OutputType { get { return typeof(TradeBar); } } /// <summary> /// Update method /// </summary> /// <param name="data">Tradebar type</param> public override void Update(TradeBar data) { if (_working != null && _working.Time.Date != data.Time.Date) { OnDataConsolidated(_working); _working = null; } AggregateBar(ref _working, data); } /// <summary> /// Aggregates the new 'data' into the 'workingBar'. The 'workingBar' will be /// null following the event firing /// </summary> /// <param name="workingBar">The bar we're building, null if the event was just fired and we're starting a new trade bar</param> /// <param name="data">The new data</param> protected void AggregateBar(ref TradeBar workingBar, TradeBar data) { if (workingBar == null) { workingBar = new TradeBar { Time = data.Time, Symbol = data.Symbol, Open = data.Open, High = data.High, Low = data.Low, Close = data.Close, Volume = data.Volume, DataType = MarketDataType.TradeBar, Period = data.Period }; } else { //Aggregate the working bar workingBar.Close = data.Close; workingBar.Volume += data.Volume; workingBar.Period += data.Period; if (data.Low < workingBar.Low) workingBar.Low = data.Low; if (data.High > workingBar.High) workingBar.High = data.High; } } } /// <summary> /// EURUSD is a custom data type we create for this algorithm /// </summary> public class EURUSD : TradeBar { /// <summary> /// Default initializer for EURUSD. /// </summary> public EURUSD() { Symbol = "EURUSD"; } /// <summary> /// Return the URL string source of the file. This will be converted to a stream /// </summary> public override string GetSource(SubscriptionDataConfig config, DateTime date, DataFeedEndpoint datafeed) { return @"..\..\..\Data\custom\EURUSD_1M_20100401_20141111.csv"; } /// <summary> /// Reader converts each line of the data source into BaseData objects. Each data type creates its own factory method, and returns a new instance of the object /// each time it is called. /// </summary> public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, DataFeedEndpoint datafeed) { EURUSD index = new EURUSD(); try { string[] data = line.Split(','); string timeValue = (Convert.ToInt32(data[2])).ToString("00:00:00"); string dateValue = (Convert.ToInt32(data[1])).ToString("0000/00/00"); index.Symbol = data[0]; index.Time = DateTime.Parse(dateValue + " " + timeValue); index.Open = Convert.ToDecimal(data[3], CultureInfo.InvariantCulture); index.High = Convert.ToDecimal(data[4], CultureInfo.InvariantCulture); index.Low = Convert.ToDecimal(data[5], CultureInfo.InvariantCulture); index.Close = Convert.ToDecimal(data[6], CultureInfo.InvariantCulture); index.Value = index.Close; } catch (Exception ex) { ex.ToString(); } return index; } } }