chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace QuantConnect.Data.Custom.AlphaStreams
|
||||
{
|
||||
/// <summary>
|
||||
/// Static class for place holder
|
||||
/// </summary>
|
||||
[Obsolete("'QuantConnect.Data.Custom.Alphas' namespace is obsolete")]
|
||||
public static class PlaceHolder
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using static QuantConnect.StringExtensions;
|
||||
|
||||
namespace QuantConnect.Data.Custom
|
||||
{
|
||||
/// <summary>
|
||||
/// FXCM Real FOREX Volume and Transaction data from its clients base, available for the following pairs:
|
||||
/// - EURUSD, USDJPY, GBPUSD, USDCHF, EURCHF, AUDUSD, USDCAD,
|
||||
/// NZDUSD, EURGBP, EURJPY, GBPJPY, EURAUD, EURCAD, AUDJPY
|
||||
/// FXCM only provides support for FX symbols which produced over 110 million average daily volume (ADV) during 2013.
|
||||
/// This limit is imposed to ensure we do not highlight low volume/low ticket symbols in addition to other financial
|
||||
/// reporting concerns.
|
||||
/// </summary>
|
||||
/// <seealso cref="QuantConnect.Data.BaseData" />
|
||||
public class FxcmVolume : BaseData
|
||||
{
|
||||
/// <summary>
|
||||
/// Auxiliary enum used to map the pair symbol into FXCM request code.
|
||||
/// </summary>
|
||||
private enum FxcmSymbolId
|
||||
{
|
||||
EURUSD = 1,
|
||||
USDJPY = 2,
|
||||
GBPUSD = 3,
|
||||
USDCHF = 4,
|
||||
EURCHF = 5,
|
||||
AUDUSD = 6,
|
||||
USDCAD = 7,
|
||||
NZDUSD = 8,
|
||||
EURGBP = 9,
|
||||
EURJPY = 10,
|
||||
GBPJPY = 11,
|
||||
EURAUD = 14,
|
||||
EURCAD = 15,
|
||||
AUDJPY = 17
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The request base URL.
|
||||
/// </summary>
|
||||
private readonly string _baseUrl = " http://marketsummary2.fxcorporate.com/ssisa/servlet?RT=SSI";
|
||||
|
||||
/// <summary>
|
||||
/// FXCM session id.
|
||||
/// </summary>
|
||||
private readonly string _sid = "quantconnect";
|
||||
|
||||
/// <summary>
|
||||
/// The columns index which should be added to obtain the transactions.
|
||||
/// </summary>
|
||||
private readonly long[] _transactionsIdx = { 27, 29, 31, 33 };
|
||||
|
||||
/// <summary>
|
||||
/// Integer representing client version.
|
||||
/// </summary>
|
||||
private readonly int _ver = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The columns index which should be added to obtain the volume.
|
||||
/// </summary>
|
||||
private readonly int[] _volumeIdx = { 26, 28, 30, 32 };
|
||||
|
||||
/// <summary>
|
||||
/// Sum of opening and closing Transactions for the entire time interval.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The transactions.
|
||||
/// </value>
|
||||
public int Transactions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sum of opening and closing Volume for the entire time interval.
|
||||
/// The volume measured in the QUOTE CURRENCY.
|
||||
/// </summary>
|
||||
/// <remarks>Please remember to convert this data to a common currency before making comparison between different pairs.</remarks>
|
||||
public long Volume { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Return the URL string source of the file. This will be converted to a stream
|
||||
/// </summary>
|
||||
/// <param name="config">Configuration object</param>
|
||||
/// <param name="date">Date of this source file</param>
|
||||
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
||||
/// <returns>
|
||||
/// String URL of source file.
|
||||
/// </returns>
|
||||
/// <exception cref="System.NotImplementedException">FOREX Volume data is not available in live mode, yet.</exception>
|
||||
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
||||
{
|
||||
var interval = GetIntervalFromResolution(config.Resolution);
|
||||
var symbolId = GetFxcmIDFromSymbol(config.Symbol.Value.Split('_').First());
|
||||
|
||||
if (isLiveMode)
|
||||
{
|
||||
var source = Invariant($"{_baseUrl}&ver={_ver}&sid={_sid}&interval={interval}&offerID={symbolId}");
|
||||
return new SubscriptionDataSource(source, SubscriptionTransportMedium.Rest, FileFormat.Csv);
|
||||
}
|
||||
else
|
||||
{
|
||||
var source = GenerateZipFilePath(config, date);
|
||||
return new SubscriptionDataSource(source, SubscriptionTransportMedium.LocalFile);
|
||||
}
|
||||
}
|
||||
|
||||
/// <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. The returned object is assumed to be time stamped in the config.ExchangeTimeZone.
|
||||
/// </summary>
|
||||
/// <param name="config">Subscription data config setup object</param>
|
||||
/// <param name="line">Line of the source document</param>
|
||||
/// <param name="date">Date of the requested data</param>
|
||||
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
||||
/// <returns>
|
||||
/// Instance of the T:BaseData object generated by this line of the CSV
|
||||
/// </returns>
|
||||
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
||||
{
|
||||
var fxcmVolume = new FxcmVolume { DataType = MarketDataType.Base, Symbol = config.Symbol };
|
||||
if (isLiveMode)
|
||||
{
|
||||
try
|
||||
{
|
||||
var obs = line.Split('\n')[2].Split(';');
|
||||
var stringDate = obs[0].Substring(startIndex: 3);
|
||||
fxcmVolume.Time = DateTime.ParseExact(stringDate, "yyyyMMddHHmm", DateTimeFormatInfo.InvariantInfo);
|
||||
fxcmVolume.Volume = _volumeIdx.Select(x => Parse.Long(obs[x])).Sum();
|
||||
fxcmVolume.Transactions = _transactionsIdx.Select(x => Parse.Int(obs[x])).Sum();
|
||||
fxcmVolume.Value = fxcmVolume.Volume;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Logging.Log.Error($"Invalid data. Line: {line}. Exception: {exception.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var obs = line.Split(',');
|
||||
if (config.Resolution == Resolution.Minute)
|
||||
{
|
||||
fxcmVolume.Time = date.Date.AddMilliseconds(Parse.Int(obs[0]));
|
||||
}
|
||||
else
|
||||
{
|
||||
fxcmVolume.Time = DateTime.ParseExact(obs[0], "yyyyMMdd HH:mm", CultureInfo.InvariantCulture);
|
||||
}
|
||||
fxcmVolume.Volume = Parse.Long(obs[1]);
|
||||
fxcmVolume.Transactions = obs[2].ConvertInvariant<int>();
|
||||
fxcmVolume.Value = fxcmVolume.Volume;
|
||||
}
|
||||
return fxcmVolume;
|
||||
}
|
||||
|
||||
private static string GenerateZipFilePath(SubscriptionDataConfig config, DateTime date)
|
||||
{
|
||||
var source = Path.Combine(new[] { Globals.DataFolder, "forex", "fxcm", config.Resolution.ToLower() });
|
||||
string filename;
|
||||
|
||||
var symbol = config.Symbol.Value.Split('_').First().ToLowerInvariant();
|
||||
if (config.Resolution == Resolution.Minute)
|
||||
{
|
||||
filename = Invariant($"{date:yyyyMMdd}_volume.zip");
|
||||
source = Path.Combine(source, symbol, filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = $"{symbol}_volume.zip";
|
||||
source = Path.Combine(source, filename);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the FXCM identifier from a FOREX pair ticker.
|
||||
/// </summary>
|
||||
/// <param name="ticker">The pair ticker.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.ArgumentException">Volume data is not available for the selected ticker. - ticker</exception>
|
||||
private int GetFxcmIDFromSymbol(string ticker)
|
||||
{
|
||||
int symbolId;
|
||||
try
|
||||
{
|
||||
symbolId = (int)Enum.Parse(typeof(FxcmSymbolId), ticker);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(ticker), ticker,
|
||||
"Volume data is not available for the selected ticker.");
|
||||
}
|
||||
return symbolId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string interval representation from the resolution.
|
||||
/// </summary>
|
||||
/// <param name="resolution">The requested resolution.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">
|
||||
/// resolution - tick or second resolution are not supported for Forex
|
||||
/// Volume.
|
||||
/// </exception>
|
||||
private string GetIntervalFromResolution(Resolution resolution)
|
||||
{
|
||||
string interval;
|
||||
switch (resolution)
|
||||
{
|
||||
case Resolution.Minute:
|
||||
interval = "M1";
|
||||
break;
|
||||
|
||||
case Resolution.Hour:
|
||||
interval = "H1";
|
||||
break;
|
||||
|
||||
case Resolution.Daily:
|
||||
interval = "D1";
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(resolution), resolution,
|
||||
"Tick or second resolution are not supported for Forex Volume. Available resolutions are Minute, Hour and Daily.");
|
||||
}
|
||||
return interval;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using NodaTime;
|
||||
using QuantConnect.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ProtoBuf;
|
||||
|
||||
namespace QuantConnect.Data.Custom.IconicTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Data type that is indexed, i.e. a file that points to another file containing the contents
|
||||
/// we're looking for in a Symbol.
|
||||
/// </summary>
|
||||
[ProtoContract(SkipConstructor = true)]
|
||||
public class IndexedLinkedData : IndexedBaseData
|
||||
{
|
||||
/// <summary>
|
||||
/// Example data property
|
||||
/// </summary>
|
||||
[ProtoMember(55)]
|
||||
public int Count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines the actual source from an index contained within a ticker folder
|
||||
/// </summary>
|
||||
/// <param name="config">Subscription configuration</param>
|
||||
/// <param name="date">Date</param>
|
||||
/// <param name="index">File to load data from</param>
|
||||
/// <param name="isLiveMode">Is live mode</param>
|
||||
/// <returns>SubscriptionDataSource pointing to the article</returns>
|
||||
public override SubscriptionDataSource GetSourceForAnIndex(SubscriptionDataConfig config, DateTime date, string index, bool isLiveMode)
|
||||
{
|
||||
return new SubscriptionDataSource(
|
||||
Path.Combine("TestData",
|
||||
"indexlinked",
|
||||
"content",
|
||||
$"{date.ToStringInvariant(DateFormat.EightCharacter)}.zip#{index}"
|
||||
),
|
||||
SubscriptionTransportMedium.LocalFile,
|
||||
FileFormat.Csv
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the source of the index file
|
||||
/// </summary>
|
||||
/// <param name="config">Configuration object</param>
|
||||
/// <param name="date">Date of this source file</param>
|
||||
/// <param name="isLiveMode">Is live mode</param>
|
||||
/// <returns>SubscriptionDataSource indicating where data is located and how it's stored</returns>
|
||||
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return new SubscriptionDataSource(
|
||||
Path.Combine(
|
||||
"TestData",
|
||||
"indexlinked",
|
||||
config.Symbol.Value.ToLowerInvariant(),
|
||||
$"{date.ToStringInvariant(DateFormat.EightCharacter)}.csv"
|
||||
),
|
||||
SubscriptionTransportMedium.LocalFile,
|
||||
FileFormat.Index
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance from a line of JSON containing article information read from the `content` directory
|
||||
/// </summary>
|
||||
/// <param name="config">Subscription configuration</param>
|
||||
/// <param name="line">Line of data</param>
|
||||
/// <param name="date">Date</param>
|
||||
/// <param name="isLiveMode">Is live mode</param>
|
||||
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return new IndexedLinkedData
|
||||
{
|
||||
Count = 10,
|
||||
Symbol = config.Symbol,
|
||||
EndTime = date
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the data source is sparse.
|
||||
/// If false, it will disable missing file logging.
|
||||
/// </summary>
|
||||
/// <returns>true</returns>
|
||||
public override bool IsSparseData()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the data source can undergo
|
||||
/// rename events/is tied to equities.
|
||||
/// </summary>
|
||||
/// <returns>true</returns>
|
||||
public override bool RequiresMapping()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the data time zone to UTC
|
||||
/// </summary>
|
||||
/// <returns>Time zone as UTC</returns>
|
||||
public override DateTimeZone DataTimeZone()
|
||||
{
|
||||
return TimeZones.Utc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the default resolution to Second
|
||||
/// </summary>
|
||||
/// <returns>Resolution.Second</returns>
|
||||
public override Resolution DefaultResolution()
|
||||
{
|
||||
return Resolution.Daily;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all the supported Resolutions
|
||||
/// </summary>
|
||||
/// <returns>All resolutions</returns>
|
||||
public override List<Resolution> SupportedResolutions()
|
||||
{
|
||||
return DailyResolution;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using NodaTime;
|
||||
using QuantConnect.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ProtoBuf;
|
||||
|
||||
namespace QuantConnect.Data.Custom.IconicTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Data type that is indexed, i.e. a file that points to another file containing the contents
|
||||
/// we're looking for in a Symbol.
|
||||
/// </summary>
|
||||
[ProtoContract(SkipConstructor = true)]
|
||||
public class IndexedLinkedData2 : IndexedBaseData
|
||||
{
|
||||
/// <summary>
|
||||
/// Example data property
|
||||
/// </summary>
|
||||
[ProtoMember(55)]
|
||||
public int Count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines the actual source from an index contained within a ticker folder
|
||||
/// </summary>
|
||||
/// <param name="config">Subscription configuration</param>
|
||||
/// <param name="date">Date</param>
|
||||
/// <param name="index">File to load data from</param>
|
||||
/// <param name="isLiveMode">Is live mode</param>
|
||||
/// <returns>SubscriptionDataSource pointing to the article</returns>
|
||||
public override SubscriptionDataSource GetSourceForAnIndex(SubscriptionDataConfig config, DateTime date, string index, bool isLiveMode)
|
||||
{
|
||||
return new SubscriptionDataSource(
|
||||
Path.Combine("TestData",
|
||||
"indexlinked2",
|
||||
"content",
|
||||
$"{date.ToStringInvariant(DateFormat.EightCharacter)}.zip#{index}"
|
||||
),
|
||||
SubscriptionTransportMedium.LocalFile,
|
||||
FileFormat.Csv
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the source of the index file
|
||||
/// </summary>
|
||||
/// <param name="config">Configuration object</param>
|
||||
/// <param name="date">Date of this source file</param>
|
||||
/// <param name="isLiveMode">Is live mode</param>
|
||||
/// <returns>SubscriptionDataSource indicating where data is located and how it's stored</returns>
|
||||
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
||||
{
|
||||
if (isLiveMode)
|
||||
{
|
||||
throw new NotImplementedException("Live mode not supported");
|
||||
}
|
||||
|
||||
return new SubscriptionDataSource(
|
||||
Path.Combine(
|
||||
"TestData",
|
||||
"indexlinked2",
|
||||
config.Symbol.Value.ToLowerInvariant(),
|
||||
$"{date.ToStringInvariant(DateFormat.EightCharacter)}.csv"
|
||||
),
|
||||
SubscriptionTransportMedium.LocalFile,
|
||||
FileFormat.Index
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance from a line of JSON containing article information read from the `content` directory
|
||||
/// </summary>
|
||||
/// <param name="config">Subscription configuration</param>
|
||||
/// <param name="line">Line of data</param>
|
||||
/// <param name="date">Date</param>
|
||||
/// <param name="isLiveMode">Is live mode</param>
|
||||
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return new IndexedLinkedData2
|
||||
{
|
||||
Count = 10,
|
||||
Symbol = config.Symbol,
|
||||
EndTime = date
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the data source is sparse.
|
||||
/// If false, it will disable missing file logging.
|
||||
/// </summary>
|
||||
/// <returns>true</returns>
|
||||
public override bool IsSparseData()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the data source can undergo
|
||||
/// rename events/is tied to equities.
|
||||
/// </summary>
|
||||
/// <returns>true</returns>
|
||||
public override bool RequiresMapping()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the data time zone to UTC
|
||||
/// </summary>
|
||||
/// <returns>Time zone as UTC</returns>
|
||||
public override DateTimeZone DataTimeZone()
|
||||
{
|
||||
return TimeZones.Utc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the default resolution to Second
|
||||
/// </summary>
|
||||
/// <returns>Resolution.Second</returns>
|
||||
public override Resolution DefaultResolution()
|
||||
{
|
||||
return Resolution.Daily;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all the supported Resolutions
|
||||
/// </summary>
|
||||
/// <returns>All resolutions</returns>
|
||||
public override List<Resolution> SupportedResolutions()
|
||||
{
|
||||
return DailyResolution;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using NodaTime;
|
||||
using QuantConnect.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ProtoBuf;
|
||||
|
||||
namespace QuantConnect.Data.Custom.IconicTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Data source that is linked (tickers that can have renames or be delisted)
|
||||
/// </summary>
|
||||
[ProtoContract(SkipConstructor = true)]
|
||||
public class LinkedData : BaseData
|
||||
{
|
||||
/// <summary>
|
||||
/// Example data
|
||||
/// </summary>
|
||||
[ProtoMember(55)]
|
||||
public int Count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Return the URL string source of the file. This will be converted to a stream
|
||||
/// </summary>
|
||||
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return new SubscriptionDataSource(
|
||||
Path.Combine(
|
||||
"TestData",
|
||||
"linked",
|
||||
$"{config.Symbol.Underlying.Value.ToLowerInvariant()}.csv"
|
||||
),
|
||||
SubscriptionTransportMedium.LocalFile,
|
||||
FileFormat.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. The returned object is assumed to be time stamped in the config.ExchangeTimeZone.
|
||||
/// </summary>
|
||||
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return new LinkedData
|
||||
{
|
||||
Count = 10,
|
||||
Symbol = config.Symbol,
|
||||
EndTime = date
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the data source is sparse.
|
||||
/// If false, it will disable missing file logging.
|
||||
/// </summary>
|
||||
/// <returns>true</returns>
|
||||
public override bool IsSparseData()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the data source can undergo
|
||||
/// rename events/is tied to equities.
|
||||
/// </summary>
|
||||
/// <returns>true</returns>
|
||||
public override bool RequiresMapping()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the data time zone to UTC
|
||||
/// </summary>
|
||||
/// <returns>Time zone as UTC</returns>
|
||||
public override DateTimeZone DataTimeZone()
|
||||
{
|
||||
return TimeZones.Utc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the default resolution to Second
|
||||
/// </summary>
|
||||
/// <returns>Resolution.Second</returns>
|
||||
public override Resolution DefaultResolution()
|
||||
{
|
||||
return Resolution.Daily;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all the supported Resolutions
|
||||
/// </summary>
|
||||
/// <returns>All resolutions</returns>
|
||||
public override List<Resolution> SupportedResolutions()
|
||||
{
|
||||
return DailyResolution;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using NodaTime;
|
||||
using QuantConnect.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ProtoBuf;
|
||||
|
||||
namespace QuantConnect.Data.Custom.IconicTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Data source that is unlinked (no mapping) and takes any ticker when calling AddData
|
||||
/// </summary>
|
||||
[ProtoContract(SkipConstructor = true)]
|
||||
public class UnlinkedData : BaseData
|
||||
{
|
||||
/// <summary>
|
||||
/// If true, we accept any ticker from the AddData call
|
||||
/// </summary>
|
||||
public static bool AnyTicker { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Example data
|
||||
/// </summary>
|
||||
[ProtoMember(55)]
|
||||
public string Ticker { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Return the path string source of the file. This will be converted to a stream
|
||||
/// </summary>
|
||||
/// <param name="config">Configuration object</param>
|
||||
/// <param name="date">Date of this source file</param>
|
||||
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
||||
/// <returns>String path of source file.</returns>
|
||||
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return new SubscriptionDataSource(
|
||||
Path.Combine(
|
||||
"TestData",
|
||||
"unlinked",
|
||||
AnyTicker ? "data.csv" : $"{config.Symbol.Value.ToLowerInvariant()}.csv"
|
||||
),
|
||||
SubscriptionTransportMedium.LocalFile,
|
||||
FileFormat.Csv);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates UnlinkedData objects using the subscription data config setup as well as the date.
|
||||
/// </summary>
|
||||
/// <param name="config">Subscription data config setup object</param>
|
||||
/// <param name="line">Line of the source document</param>
|
||||
/// <param name="date">Date of the requested data</param>
|
||||
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
||||
/// <returns>Instance of the UnlinkedData object generated by this line of the CSV</returns>
|
||||
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return new UnlinkedData
|
||||
{
|
||||
Ticker = AnyTicker ? "ANY" : $"{config.Symbol.Value}",
|
||||
Symbol = config.Symbol,
|
||||
EndTime = date
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the data source is sparse.
|
||||
/// If false, it will disable missing file logging.
|
||||
/// </summary>
|
||||
/// <returns>true</returns>
|
||||
public override bool IsSparseData()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the data source can undergo
|
||||
/// rename events/is tied to equities.
|
||||
/// </summary>
|
||||
/// <returns>true</returns>
|
||||
public override bool RequiresMapping()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the data time zone to UTC
|
||||
/// </summary>
|
||||
/// <returns>Time zone as UTC</returns>
|
||||
public override DateTimeZone DataTimeZone()
|
||||
{
|
||||
return TimeZones.Utc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the default resolution to Second
|
||||
/// </summary>
|
||||
/// <returns>Resolution.Second</returns>
|
||||
public override Resolution DefaultResolution()
|
||||
{
|
||||
return Resolution.Daily;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all the supported Resolutions
|
||||
/// </summary>
|
||||
/// <returns>All resolutions</returns>
|
||||
public override List<Resolution> SupportedResolutions()
|
||||
{
|
||||
return DailyResolution;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using NodaTime;
|
||||
using QuantConnect.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ProtoBuf;
|
||||
using QuantConnect.Data.Market;
|
||||
|
||||
namespace QuantConnect.Data.Custom.IconicTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Data source that is unlinked (no mapping) and takes any ticker when calling AddData
|
||||
/// </summary>
|
||||
[ProtoContract(SkipConstructor = true)]
|
||||
public class UnlinkedDataTradeBar : TradeBar
|
||||
{
|
||||
/// <summary>
|
||||
/// If true, we accept any ticker from the AddData call
|
||||
/// </summary>
|
||||
public static bool AnyTicker { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of an UnlinkedTradeBar
|
||||
/// </summary>
|
||||
public UnlinkedDataTradeBar()
|
||||
{
|
||||
DataType = MarketDataType.Base;
|
||||
Period = TimeSpan.FromDays(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Source for Custom Data File
|
||||
/// >> What source file location would you prefer for each type of usage:
|
||||
/// </summary>
|
||||
/// <param name="config">Configuration object</param>
|
||||
/// <param name="date">Date of this source request if source spread across multiple files</param>
|
||||
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
||||
/// <returns>String source location of the file</returns>
|
||||
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return new SubscriptionDataSource(
|
||||
Path.Combine(
|
||||
"TestData",
|
||||
"unlinkedtradebar",
|
||||
AnyTicker ? "data.csv" : $"{config.Symbol.Value.ToLowerInvariant()}.csv"
|
||||
),
|
||||
SubscriptionTransportMedium.LocalFile,
|
||||
FileFormat.Csv);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetch the data from the storage and feed it line by line into the engine.
|
||||
/// </summary>
|
||||
/// <param name="config">Symbols, Resolution, DataType, </param>
|
||||
/// <param name="line">Line from the data file requested</param>
|
||||
/// <param name="date">Date of this reader request</param>
|
||||
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
||||
/// <returns>Enumerable iterator for returning each line of the required data.</returns>
|
||||
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return new UnlinkedDataTradeBar
|
||||
{
|
||||
Open = 1m,
|
||||
High = 2m,
|
||||
Low = 1m,
|
||||
Close = 1.5m,
|
||||
Volume = 0m,
|
||||
|
||||
Symbol = config.Symbol,
|
||||
EndTime = date
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the data source is sparse.
|
||||
/// If false, it will disable missing file logging.
|
||||
/// </summary>
|
||||
/// <returns>true</returns>
|
||||
public override bool IsSparseData()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the data source can undergo
|
||||
/// rename events/is tied to equities.
|
||||
/// </summary>
|
||||
/// <returns>true</returns>
|
||||
public override bool RequiresMapping()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the data time zone to UTC
|
||||
/// </summary>
|
||||
/// <returns>Time zone as UTC</returns>
|
||||
public override DateTimeZone DataTimeZone()
|
||||
{
|
||||
return TimeZones.Utc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the default resolution to Second
|
||||
/// </summary>
|
||||
/// <returns>Resolution.Second</returns>
|
||||
public override Resolution DefaultResolution()
|
||||
{
|
||||
return Resolution.Daily;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all the supported Resolutions
|
||||
/// </summary>
|
||||
/// <returns>All resolutions</returns>
|
||||
public override List<Resolution> SupportedResolutions()
|
||||
{
|
||||
return DailyResolution;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,498 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace QuantConnect.Data.Custom.Intrinio
|
||||
{
|
||||
/// <summary>
|
||||
/// Intrinio Data Source
|
||||
/// </summary>
|
||||
public static class IntrinioEconomicDataSources
|
||||
{
|
||||
/// <summary>
|
||||
/// Bank of America Merrill Lynch
|
||||
/// </summary>
|
||||
public static class BofAMerrillLynch
|
||||
{
|
||||
/// <summary>
|
||||
/// This data represents the effective yield of the BofA Merrill Lynch US Corporate BBB Index, a subset of the BofA
|
||||
/// Merrill Lynch US Corporate Master Index tracking the performance of US dollar denominated investment grade rated
|
||||
/// corporate debt publically issued in the US domestic market.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/BAMLC0A4CBBBEY
|
||||
/// </remarks>
|
||||
public const string USCorporateBBBEffectiveYield = "$BAMLC0A4CBBBEY";
|
||||
|
||||
/// <summary>
|
||||
/// This data represents the Option-Adjusted Spread (OAS) of the BofA Merrill Lynch US Corporate BBB Index, a subset of
|
||||
/// the BofA Merrill Lynch US Corporate Master Index tracking the performance of US dollar denominated investment grade
|
||||
/// rated corporate debt publically issued in the US domestic market.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/BAMLC0A4CBBB
|
||||
/// </remarks>
|
||||
public const string USCorporateBBBOptionAdjustedSpread = "$BAMLC0A4CBBB";
|
||||
|
||||
/// <summary>
|
||||
/// The BofA Merrill Lynch Option-Adjusted Spreads (OASs) are the calculated spreads between a computed OAS index of
|
||||
/// all bonds in a given rating category and a spot Treasury curve. An OAS index is constructed using each constituent
|
||||
/// bond’s OAS, weighted by market capitalization.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/BAMLC0A0CM
|
||||
/// </remarks>
|
||||
public const string USCorporateMasterOptionAdjustedSpread = "$BAMLC0A0CM";
|
||||
|
||||
/// <summary>
|
||||
/// This data represents the Option-Adjusted Spread (OAS) of the BofA Merrill Lynch US Corporate BB Index, a subset of
|
||||
/// the BofA Merrill Lynch US High Yield Master II Index tracking the performance of US dollar denominated below
|
||||
/// investment grade rated corporate debt publically issued in the US domestic market.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/BAMLH0A1HYBB
|
||||
/// </remarks>
|
||||
public const string USHighYieldBBOptionAdjustedSpread = "$BAMLH0A1HYBB";
|
||||
|
||||
/// <summary>
|
||||
/// This data represents the Option-Adjusted Spread (OAS) of the BofA Merrill Lynch US Corporate B Index, a subset of
|
||||
/// the BofA Merrill Lynch US High Yield Master II Index tracking the performance of US dollar denominated below
|
||||
/// investment grade rated corporate debt publically issued in the US domestic market. This subset includes all
|
||||
/// securities with a given investment grade rating B.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/BAMLH0A2HYB
|
||||
/// </remarks>
|
||||
public const string USHighYieldBOptionAdjustedSpread = "$BAMLH0A2HYB";
|
||||
|
||||
/// <summary>
|
||||
/// This data represents the Option-Adjusted Spread (OAS) of the BofA Merrill Lynch US Corporate C Index, a subset of
|
||||
/// the BofA Merrill Lynch US High Yield Master II Index tracking the performance of US dollar denominated below
|
||||
/// investment grade rated corporate debt publically issued in the US domestic market.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/BAMLH0A3HYC
|
||||
/// </remarks>
|
||||
public const string USHighYieldCCCorBelowOptionAdjustedSpread = "$BAMLH0A3HYC";
|
||||
|
||||
/// <summary>
|
||||
/// This data represents the effective yield of the BofA Merrill Lynch US High Yield Master II Index, which tracks the
|
||||
/// performance of US dollar denominated below investment grade rated corporate debt publically issued in the US
|
||||
/// domestic market.
|
||||
/// Source: https://fred.stlouisfed.org/series/BAMLH0A0HYM2EY
|
||||
/// </summary>
|
||||
public const string USHighYieldEffectiveYield = "$BAMLH0A0HYM2EY";
|
||||
|
||||
/// <summary>
|
||||
/// This data represents the BofA Merrill Lynch US High Yield Master II Index value, which tracks the performance of US
|
||||
/// dollar denominated below investment grade rated corporate debt publically issued in the US domestic market.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/BAMLHYH0A0HYM2TRIV
|
||||
/// </remarks>
|
||||
public const string USHighYieldMasterIITotalReturnIndexValue = "$BAMLHYH0A0HYM2TRIV";
|
||||
|
||||
/// <summary>
|
||||
/// The BofA Merrill Lynch Option-Adjusted Spreads (OASs) are the calculated spreads between a computed OAS index of
|
||||
/// all bonds in a given rating category and a spot Treasury curve. An OAS index is constructed using each constituent
|
||||
/// bond’s OAS, weighted by market capitalization.
|
||||
/// Source: https://fred.stlouisfed.org/series/BAMLH0A0HYM2
|
||||
/// </summary>
|
||||
public const string USHighYieldOptionAdjustedSpread = "$BAMLH0A0HYM2";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chicago Board Options Exchange
|
||||
/// </summary>
|
||||
public static class CBOE
|
||||
{
|
||||
/// <summary>
|
||||
/// CBOE China ETF Volatility Index
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/VXFXICLS
|
||||
/// </remarks>
|
||||
public const string ChinaETFVolatilityIndex = "$VXFXICLS";
|
||||
|
||||
/// <summary>
|
||||
/// CBOE Crude Oil ETF Volatility Index
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/OVXCLS
|
||||
/// </remarks>
|
||||
public const string CrudeOilETFVolatilityIndex = "$OVXCLS";
|
||||
|
||||
/// <summary>
|
||||
/// CBOE Emerging Markets ETF Volatility Index
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/VXEEMCLS
|
||||
/// </remarks>
|
||||
public const string EmergingMarketsETFVolatilityIndex = "$VXEEMCLS";
|
||||
|
||||
/// <summary>
|
||||
/// CBOE Gold ETF Volatility Index
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/GVZCLS
|
||||
/// </remarks>
|
||||
public const string GoldETFVolatilityIndex = "$GVZCLS";
|
||||
|
||||
/// <summary>
|
||||
/// CBOE 10-Year Treasury Note Volatility Futures
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/VXTYN
|
||||
/// </remarks>
|
||||
public const string TenYearTreasuryNoteVolatilityFutures = "$VXTYN";
|
||||
|
||||
/// <summary>
|
||||
/// CBOE Volatility Index: VIX
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/VIXCLS
|
||||
/// </remarks>
|
||||
public const string VIX = "$VIXCLS";
|
||||
|
||||
/// <summary>
|
||||
/// CBOE S&P 100 Volatility Index: VXO
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/VXOCLS
|
||||
/// </remarks>
|
||||
public const string VXO = "$VXOCLS";
|
||||
|
||||
/// <summary>
|
||||
/// CBOE S&P 500 3-Month Volatility Index
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/VXVCLS
|
||||
/// </remarks>
|
||||
public const string VXV = "$VXVCLS";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Commodities
|
||||
/// </summary>
|
||||
public static class Commodities
|
||||
{
|
||||
/// <summary>
|
||||
/// Crude Oil Prices: Brent - Europe
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/DCOILBRENTEU
|
||||
/// </remarks>
|
||||
public const string CrudeOilBrent = "$DCOILBRENTEU";
|
||||
|
||||
/// <summary>
|
||||
/// Crude Oil Prices: West Texas Intermediate (WTI) - Cushing, Oklahoma
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/DCOILWTICO
|
||||
/// </remarks>
|
||||
public const string CrudeOilWTI = "$DCOILWTICO";
|
||||
|
||||
/// <summary>
|
||||
/// Conventional Gasoline Prices: U.S. Gulf Coast, Regular
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/DGASUSGULF
|
||||
/// </remarks>
|
||||
public const string GasolineUSGulfCoast = "$DGASUSGULF";
|
||||
|
||||
/// <summary>
|
||||
/// Gold Fixing Price 10:30 A.M. (London time) in London Bullion Market, based in U.S. Dollars
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/GOLDAMGBD228NLBM
|
||||
/// </remarks>
|
||||
public const string GoldFixingPrice1030amLondon = "$GOLDAMGBD228NLBM";
|
||||
|
||||
/// <summary>
|
||||
/// Gold Fixing Price 3:00 P.M. (London time) in London Bullion Market, based in U.S. Dollars
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/GOLDPMGBD228NLBM
|
||||
/// </remarks>
|
||||
public const string GoldFixingPrice1500amLondon = "$GOLDPMGBD228NLBM";
|
||||
|
||||
/// <summary>
|
||||
/// Henry Hub Natural Gas Spot Price
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/DHHNGSP
|
||||
/// </remarks>
|
||||
public const string NaturalGas = "$DHHNGSP";
|
||||
|
||||
/// <summary>
|
||||
/// Propane Prices: Mont Belvieu, Texas
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/DPROPANEMBTX
|
||||
/// </remarks>
|
||||
public const string Propane = "$DPROPANEMBTX";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exchange Rates
|
||||
/// </summary>
|
||||
public static class ExchangeRates
|
||||
{
|
||||
/// <summary>
|
||||
/// Brazilian Reals to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string Brazil_USA = "$DEXBZUS";
|
||||
|
||||
/// <summary>
|
||||
/// Canadian Dollars to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string Canada_USA = "$DEXCAUS";
|
||||
|
||||
/// <summary>
|
||||
/// Chinese Yuan to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string China_USA = "$DEXCHUS";
|
||||
|
||||
/// <summary>
|
||||
/// Hong Kong Dollars to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string HongKong_USA = "$DEXHKUS";
|
||||
|
||||
/// <summary>
|
||||
/// Indian Rupees to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string India_USA = "$DEXINUS";
|
||||
|
||||
/// <summary>
|
||||
/// Japanese Yen to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string Japan_USA = "$DEXJPUS";
|
||||
|
||||
/// <summary>
|
||||
/// Malaysian Ringgit to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string Malaysia_USA = "$DEXMAUS";
|
||||
|
||||
/// <summary>
|
||||
/// Mexican New Pesos to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string Mexico_USA = "$DEXMXUS";
|
||||
|
||||
/// <summary>
|
||||
/// Norwegian Kroner to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string Norway_USA = "$DEXNOUS";
|
||||
|
||||
/// <summary>
|
||||
/// Singapore Dollars to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string Singapore_USA = "$DEXSIUS";
|
||||
|
||||
/// <summary>
|
||||
/// South African Rand to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string SouthAfrica_USA = "$DEXSFUS";
|
||||
|
||||
/// <summary>
|
||||
/// South Korean Won to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string SouthKorea_USA = "$DEXKOUS";
|
||||
|
||||
/// <summary>
|
||||
/// Sri Lankan Rupees to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string SriLanka_USA = "$DEXSLUS";
|
||||
|
||||
/// <summary>
|
||||
/// Swiss Francs to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string Switzerland_USA = "$DEXSZUS";
|
||||
|
||||
/// <summary>
|
||||
/// New Taiwan Dollars to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string Taiwan_USA = "$DEXTAUS";
|
||||
|
||||
/// <summary>
|
||||
/// Thai Baht to One U.S. Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string Thailand_USA = "$DEXTHUS";
|
||||
|
||||
/// <summary>
|
||||
/// U.S. Dollars to One Australian Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string USA_Australia = "$DEXUSAL";
|
||||
|
||||
/// <summary>
|
||||
/// U.S. Dollars to One Euro
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string USA_Euro = "$DEXUSEU";
|
||||
|
||||
/// <summary>
|
||||
/// U.S. Dollars to One New Zealand Dollar
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string USA_NewZealand = "$DEXUSNZ";
|
||||
|
||||
/// <summary>
|
||||
/// U.S. Dollars to One British Pound
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: Board of Governors of the Federal Reserve System https://www.federalreserve.gov/releases/h10/
|
||||
/// </remarks>
|
||||
public const string USA_UK = "$DEXUSUK";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moody's Investors Service
|
||||
/// </summary>
|
||||
public static class Moodys
|
||||
{
|
||||
/// <summary>
|
||||
/// Moody's Seasoned Aaa Corporate Bond© and 10-Year Treasury Constant Maturity.
|
||||
/// These instruments are based on bonds with maturities 20 years and above.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/DAAA
|
||||
/// </remarks>
|
||||
public const string SeasonedAaaCorporateBondYield = "$DAAA";
|
||||
|
||||
/// <summary>
|
||||
/// Series is calculated as the spread between Moody's Seasoned Aaa Corporate Bond© and 10-Year Treasury Constant
|
||||
/// Maturity
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/AAA10Y
|
||||
/// </remarks>
|
||||
public const string SeasonedAaaCorporateBondYieldRelativeTo10YearTreasuryConstantMaturity = "$AAA10Y";
|
||||
|
||||
/// <summary>
|
||||
/// Moody's Seasoned Baa Corporate Bond© and 10-Year Treasury Constant Maturity.
|
||||
/// These instruments are based on bonds with maturities 20 years and above.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/DBAA
|
||||
/// </remarks>
|
||||
public const string SeasonedBaaCorporateBondYield = "$DBAA";
|
||||
|
||||
/// <summary>
|
||||
/// Series is calculated as the spread between Moody's Seasoned Baa Corporate Bond© and 10-Year Treasury Constant Maturity
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/BAA10Y
|
||||
/// </remarks>
|
||||
public const string SeasonedBaaCorporateBondYieldRelativeTo10YearTreasuryConstantMaturity = "$BAA10Y";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Trade Weighted US Dollar Index
|
||||
/// </summary>
|
||||
public static class TradeWeightedUsDollarIndex
|
||||
{
|
||||
/// <summary>
|
||||
/// A weighted average of the foreign exchange value of the U.S. dollar against the currencies of a broad group of
|
||||
/// major U.S. trading partners. Broad currency index includes the Euro Area, Canada, Japan, Mexico, China, United
|
||||
/// Kingdom, Taiwan, Korea, Singapore, Hong Kong, Malaysia, Brazil, Switzerland, Thailand, Philippines, Australia,
|
||||
/// Indonesia, India, Israel, Saudi Arabia, Russia, Sweden, Argentina, Venezuela, Chile and Colombia.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/DTWEXB
|
||||
/// For more information about trade-weighted indexes see
|
||||
/// http://www.federalreserve.gov/pubs/bulletin/2005/winter05_index.pdf.
|
||||
/// </remarks>
|
||||
public const string Broad = "$DTWEXB";
|
||||
|
||||
/// <summary>
|
||||
/// A weighted average of the foreign exchange value of the U.S. dollar against a subset of the broad index currencies
|
||||
/// that circulate widely outside the country of issue. Major currencies index includes the Euro Area, Canada, Japan,
|
||||
/// United Kingdom, Switzerland, Australia, and Sweden.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/DTWEXM
|
||||
/// For more information about trade-weighted indexes see
|
||||
/// http://www.federalreserve.gov/pubs/bulletin/2005/winter05_index.pdf.
|
||||
/// </remarks>
|
||||
public const string MajorCurrencies = "$DTWEXM";
|
||||
|
||||
/// <summary>
|
||||
/// A weighted average of the foreign exchange value of the U.S. dollar against a subset of the broad index currencies
|
||||
/// that do not circulate widely outside the country of issue. Countries whose currencies are included in the other
|
||||
/// important trading partners index are Mexico, China, Taiwan, Korea, Singapore, Hong Kong, Malaysia, Brazil,
|
||||
/// Thailand, Philippines, Indonesia, India, Israel, Saudi Arabia, Russia, Argentina, Venezuela, Chile and Colombia.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Source: https://fred.stlouisfed.org/series/DTWEXO
|
||||
/// For more information about trade-weighted indexes see
|
||||
/// http://www.federalreserve.gov/pubs/bulletin/2005/winter05_index.pdf.
|
||||
/// </remarks>
|
||||
public const string OtherImportantTradingPartners = "$DTWEXO";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Util;
|
||||
|
||||
namespace QuantConnect.Data.Custom.Intrinio
|
||||
{
|
||||
/// <summary>
|
||||
/// Auxiliary class to access all Intrinio API data.
|
||||
/// </summary>
|
||||
public static class IntrinioConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public static RateGate RateGate =
|
||||
new RateGate(1, TimeSpan.FromMilliseconds(5000));
|
||||
|
||||
/// <summary>
|
||||
/// Check if Intrinio API user and password are not empty or null.
|
||||
/// </summary>
|
||||
public static bool IsInitialized => !string.IsNullOrWhiteSpace(User) && !string.IsNullOrWhiteSpace(Password);
|
||||
|
||||
/// <summary>
|
||||
/// Intrinio API password
|
||||
/// </summary>
|
||||
public static string Password = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Intrinio API user
|
||||
/// </summary>
|
||||
public static string User = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the time interval between calls.
|
||||
/// For more information, please refer to: https://intrinio.com/documentation/api#limits
|
||||
/// </summary>
|
||||
/// <param name="timeSpan">Time interval between to consecutive calls.</param>
|
||||
/// <remarks>
|
||||
/// Paid subscription has limits of 1 call per second.
|
||||
/// Free subscription has limits of 1 call per minute.
|
||||
/// </remarks>
|
||||
public static void SetTimeIntervalBetweenCalls(TimeSpan timeSpan)
|
||||
{
|
||||
RateGate = new RateGate(1, timeSpan);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the Intrinio API user and password.
|
||||
/// </summary>
|
||||
public static void SetUserAndPassword(string user, string password)
|
||||
{
|
||||
User = user;
|
||||
Password = password;
|
||||
|
||||
if (!IsInitialized)
|
||||
{
|
||||
throw new InvalidOperationException("Please set a valid Intrinio user and password.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace QuantConnect.Data.Custom.Intrinio
|
||||
{
|
||||
/// <summary>
|
||||
/// TRanformation available for the Economic data.
|
||||
/// </summary>
|
||||
public enum IntrinioDataTransformation
|
||||
{
|
||||
/// <summary>
|
||||
/// The rate of change
|
||||
/// </summary>
|
||||
Roc,
|
||||
|
||||
/// <summary>
|
||||
/// Rate of change from Year Ago
|
||||
/// </summary>
|
||||
AnnualyRoc,
|
||||
|
||||
/// <summary>
|
||||
/// The compounded annual rate of change
|
||||
/// </summary>
|
||||
CompoundedAnnualRoc,
|
||||
|
||||
/// <summary>
|
||||
/// The continuously compounded annual rate of change
|
||||
/// </summary>
|
||||
AnnualyCCRoc,
|
||||
|
||||
/// <summary>
|
||||
/// The continuously compounded rateof change
|
||||
/// </summary>
|
||||
CCRoc,
|
||||
|
||||
/// <summary>
|
||||
/// The level, no transformation.
|
||||
/// </summary>
|
||||
Level,
|
||||
|
||||
/// <summary>
|
||||
/// The natural log
|
||||
/// </summary>
|
||||
Ln,
|
||||
|
||||
/// <summary>
|
||||
/// The percent change
|
||||
/// </summary>
|
||||
Pc,
|
||||
|
||||
/// <summary>
|
||||
/// The percent change from year ago
|
||||
/// </summary>
|
||||
AnnualyPc
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Access the massive repository of economic data from the Federal Reserve Economic Data system via the Intrinio API.
|
||||
/// </summary>
|
||||
/// <seealso cref="QuantConnect.Data.BaseData" />
|
||||
public class IntrinioEconomicData : BaseData
|
||||
{
|
||||
private readonly string _baseUrl = @"https://api.intrinio.com/historical_data.csv?";
|
||||
|
||||
private readonly IntrinioDataTransformation _dataTransformation;
|
||||
|
||||
|
||||
private bool _backtestingFirstTimeCallOrLiveMode = true;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IntrinioEconomicData" /> class.
|
||||
/// </summary>
|
||||
public IntrinioEconomicData() : this(IntrinioDataTransformation.Level)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IntrinioEconomicData" /> class.
|
||||
/// </summary>
|
||||
/// <param name="dataTransformation">The item.</param>
|
||||
public IntrinioEconomicData(IntrinioDataTransformation dataTransformation)
|
||||
{
|
||||
_dataTransformation = dataTransformation;
|
||||
|
||||
// If the user and the password is not set then then throw error.
|
||||
if (!IntrinioConfig.IsInitialized)
|
||||
{
|
||||
throw new
|
||||
InvalidOperationException("Please set a valid Intrinio user and password using the 'IntrinioEconomicData.SetUserAndPassword' static method. " +
|
||||
"For local backtesting, the user and password can be set in the 'parameters' fields from the 'config.json' file.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Return the URL string source of the file. This will be converted to a stream
|
||||
/// </summary>
|
||||
/// <param name="config">Configuration object</param>
|
||||
/// <param name="date">Date of this source file</param>
|
||||
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
||||
/// <returns>
|
||||
/// String URL of source file.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// Given Intrinio's API limits, we cannot make more than one CSV request per second. That's why in backtesting mode
|
||||
/// we make sure we make just one call to retrieve all the data needed. Also, to avoid the problem of many sources
|
||||
/// asking the data at the beginning of the algorithm, a pause of a second is added.
|
||||
/// </remarks>
|
||||
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
||||
{
|
||||
SubscriptionDataSource subscription;
|
||||
|
||||
// We want to make just one call with all the data in backtesting mode.
|
||||
// Also we want to make one call per second becasue of the API limit.
|
||||
if (_backtestingFirstTimeCallOrLiveMode)
|
||||
{
|
||||
// Force the engine to wait at least 1000 ms between API calls.
|
||||
IntrinioConfig.RateGate.WaitToProceed();
|
||||
|
||||
// In backtesting mode, there is only one call at the beggining with all the data
|
||||
_backtestingFirstTimeCallOrLiveMode = false || isLiveMode;
|
||||
subscription = GetIntrinioSubscription(config, isLiveMode);
|
||||
}
|
||||
else
|
||||
{
|
||||
subscription = new SubscriptionDataSource("", SubscriptionTransportMedium.LocalFile);
|
||||
}
|
||||
return subscription;
|
||||
}
|
||||
|
||||
/// <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. The returned object is assumed to be time stamped in the config.ExchangeTimeZone.
|
||||
/// </summary>
|
||||
/// <param name="config">Subscription data config setup object</param>
|
||||
/// <param name="line">Line of the source document</param>
|
||||
/// <param name="date">Date of the requested data</param>
|
||||
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
||||
/// <returns>
|
||||
/// Instance of the T:BaseData object generated by this line of the CSV
|
||||
/// </returns>
|
||||
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
||||
{
|
||||
var obs = line.Split(',');
|
||||
var time = DateTime.MinValue;
|
||||
if (!DateTime.TryParseExact(obs[0], "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None,
|
||||
out time)) return null;
|
||||
var value = obs[1].ToDecimal();
|
||||
return new IntrinioEconomicData
|
||||
{
|
||||
Symbol = config.Symbol,
|
||||
Time = time,
|
||||
EndTime = time + QuantConnect.Time.OneDay,
|
||||
Value = value
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetStringForDataTransformation(IntrinioDataTransformation dataTransformation)
|
||||
{
|
||||
var item = "level";
|
||||
switch (dataTransformation)
|
||||
{
|
||||
case IntrinioDataTransformation.Roc:
|
||||
item = "change";
|
||||
break;
|
||||
case IntrinioDataTransformation.AnnualyRoc:
|
||||
item = "yr_change";
|
||||
break;
|
||||
case IntrinioDataTransformation.CompoundedAnnualRoc:
|
||||
item = "c_annual_roc";
|
||||
break;
|
||||
case IntrinioDataTransformation.AnnualyCCRoc:
|
||||
item = "cc_annual_roc";
|
||||
break;
|
||||
case IntrinioDataTransformation.CCRoc:
|
||||
item = "cc_roc";
|
||||
break;
|
||||
case IntrinioDataTransformation.Level:
|
||||
item = "level";
|
||||
break;
|
||||
case IntrinioDataTransformation.Ln:
|
||||
item = "log";
|
||||
break;
|
||||
case IntrinioDataTransformation.Pc:
|
||||
item = "percent_change";
|
||||
break;
|
||||
case IntrinioDataTransformation.AnnualyPc:
|
||||
item = "yr_percent_change";
|
||||
break;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
private SubscriptionDataSource GetIntrinioSubscription(SubscriptionDataConfig config, bool isLiveMode)
|
||||
{
|
||||
// In Live mode, we only want the last observation, in backtesitng we need the data in ascending order.
|
||||
var order = isLiveMode ? "desc" : "asc";
|
||||
var item = GetStringForDataTransformation(_dataTransformation);
|
||||
var url = $"{_baseUrl}identifier={config.Symbol.Value}&item={item}&sort_order={order}";
|
||||
var byteKey = Encoding.ASCII.GetBytes($"{IntrinioConfig.User}:{IntrinioConfig.Password}");
|
||||
var authorizationHeaders = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("Authorization",
|
||||
$"Basic ({Convert.ToBase64String(byteKey)})")
|
||||
};
|
||||
|
||||
return new SubscriptionDataSource(url, SubscriptionTransportMedium.RemoteFile, FileFormat.Csv,
|
||||
authorizationHeaders);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
|
||||
namespace QuantConnect.DataSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a custom data type place holder
|
||||
/// </summary>
|
||||
public class NullData : BaseData
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace QuantConnect.Data.Custom.Tiingo
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper class for Tiingo configuration
|
||||
/// </summary>
|
||||
public static class Tiingo
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Tiingo API token.
|
||||
/// </summary>
|
||||
public static string AuthCode { get; private set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the Tiingo API token has been set.
|
||||
/// </summary>
|
||||
public static bool IsAuthCodeSet { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the Tiingo API token.
|
||||
/// </summary>
|
||||
/// <param name="authCode">The Tiingo API token</param>
|
||||
public static void SetAuthCode(string authCode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(authCode)) return;
|
||||
|
||||
AuthCode = authCode;
|
||||
IsAuthCodeSet = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace QuantConnect.Data.Custom.Tiingo
|
||||
{
|
||||
/// <summary>
|
||||
/// Tiingo daily price data
|
||||
/// https://api.tiingo.com/docs/tiingo/daily
|
||||
/// </summary>
|
||||
/// <remarks>Requires setting <see cref="Tiingo.AuthCode"/></remarks>
|
||||
[Obsolete("This is kept for backwards compatibility, please use TiingoPrice")]
|
||||
public class TiingoDailyData : TiingoPrice
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using NodaTime;
|
||||
using QuantConnect.Data.Market;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using static QuantConnect.StringExtensions;
|
||||
|
||||
namespace QuantConnect.Data.Custom.Tiingo
|
||||
{
|
||||
/// <summary>
|
||||
/// Tiingo daily price data
|
||||
/// https://api.tiingo.com/docs/tiingo/daily
|
||||
/// </summary>
|
||||
/// <remarks>Requires setting <see cref="Tiingo.AuthCode"/></remarks>
|
||||
public class TiingoPrice : TradeBar
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, DateTime> _startDates = new ConcurrentDictionary<string, DateTime>();
|
||||
|
||||
/// <summary>
|
||||
/// The end time of this data. Some data covers spans (trade bars) and as such we want
|
||||
/// to know the entire time span covered
|
||||
/// </summary>
|
||||
public override DateTime EndTime
|
||||
{
|
||||
get { return Time + Period; }
|
||||
set { Time = value - Period; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The period of this trade bar, (second, minute, daily, ect...)
|
||||
/// </summary>
|
||||
public override TimeSpan Period => QuantConnect.Time.OneDay;
|
||||
|
||||
/// <summary>
|
||||
/// The date this data pertains to
|
||||
/// </summary>
|
||||
[JsonProperty("date")]
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The actual (not adjusted) open price of the asset on the specific date
|
||||
/// </summary>
|
||||
[JsonProperty("open")]
|
||||
public override decimal Open { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The actual (not adjusted) high price of the asset on the specific date
|
||||
/// </summary>
|
||||
[JsonProperty("high")]
|
||||
public override decimal High { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The actual (not adjusted) low price of the asset on the specific date
|
||||
/// </summary>
|
||||
[JsonProperty("low")]
|
||||
public override decimal Low { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The actual (not adjusted) closing price of the asset on the specific date
|
||||
/// </summary>
|
||||
[JsonProperty("close")]
|
||||
public override decimal Close { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The actual (not adjusted) number of shares traded during the day
|
||||
/// </summary>
|
||||
[JsonProperty("volume")]
|
||||
public override decimal Volume { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The adjusted opening price of the asset on the specific date. Returns null if not available.
|
||||
/// </summary>
|
||||
[JsonProperty("adjOpen")]
|
||||
public decimal AdjustedOpen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The adjusted high price of the asset on the specific date. Returns null if not available.
|
||||
/// </summary>
|
||||
[JsonProperty("adjHigh")]
|
||||
public decimal AdjustedHigh { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The adjusted low price of the asset on the specific date. Returns null if not available.
|
||||
/// </summary>
|
||||
[JsonProperty("adjLow")]
|
||||
public decimal AdjustedLow { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The adjusted close price of the asset on the specific date. Returns null if not available.
|
||||
/// </summary>
|
||||
[JsonProperty("adjClose")]
|
||||
public decimal AdjustedClose { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The adjusted number of shares traded during the day - adjusted for splits. Returns null if not available
|
||||
/// </summary>
|
||||
[JsonProperty("adjVolume")]
|
||||
public long AdjustedVolume { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The dividend paid out on "date" (note that "date" will be the "exDate" for the dividend)
|
||||
/// </summary>
|
||||
[JsonProperty("divCash")]
|
||||
public decimal Dividend { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A factor used when a company splits or reverse splits. On days where there is ONLY a split (no dividend payment),
|
||||
/// you can calculate the adjusted close as follows: adjClose = "Previous Close"/splitFactor
|
||||
/// </summary>
|
||||
[JsonProperty("splitFactor")]
|
||||
public decimal SplitFactor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of the <see cref="TiingoPrice"/> class.
|
||||
/// </summary>
|
||||
public TiingoPrice()
|
||||
{
|
||||
Symbol = Symbol.Empty;
|
||||
DataType = MarketDataType.Base;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the URL string source of the file. This will be converted to a stream
|
||||
/// </summary>
|
||||
/// <param name="config">Configuration object</param>
|
||||
/// <param name="date">Date of this source file</param>
|
||||
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
||||
/// <returns>String URL of source file.</returns>
|
||||
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
||||
{
|
||||
DateTime startDate;
|
||||
if (!_startDates.TryGetValue(config.Symbol.Value, out startDate))
|
||||
{
|
||||
startDate = date;
|
||||
_startDates.TryAdd(config.Symbol.Value, startDate);
|
||||
}
|
||||
|
||||
var tiingoTicker = TiingoSymbolMapper.GetTiingoTicker(config.Symbol);
|
||||
var source = Invariant($"https://api.tiingo.com/tiingo/daily/{tiingoTicker}/prices?startDate={startDate:yyyy-MM-dd}&token={Tiingo.AuthCode}");
|
||||
return new SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile, FileFormat.UnfoldingCollection);
|
||||
}
|
||||
|
||||
/// <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. The returned object is assumed to be time stamped in the config.ExchangeTimeZone.
|
||||
/// </summary>
|
||||
/// <param name="config">Subscription data config setup object</param>
|
||||
/// <param name="line">Content of the source document</param>
|
||||
/// <param name="date">Date of the requested data</param>
|
||||
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
||||
/// <returns>
|
||||
/// Instance of the T:BaseData object generated by this line of the CSV
|
||||
/// </returns>
|
||||
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
||||
{
|
||||
var list = JsonConvert.DeserializeObject<List<TiingoPrice>>(line);
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
item.Symbol = config.Symbol;
|
||||
item.Time = item.Date;
|
||||
item.Value = item.Close;
|
||||
}
|
||||
|
||||
return new BaseDataCollection(date, config.Symbol, list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if there is support for mapping
|
||||
/// </summary>
|
||||
/// <returns>True indicates mapping should be used</returns>
|
||||
public override bool RequiresMapping()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the data time zone for this data type. This is useful for custom data types
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="DateTimeZone"/> of this data type</returns>
|
||||
public override DateTimeZone DataTimeZone()
|
||||
{
|
||||
return TimeZones.Utc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default resolution for this data and security type
|
||||
/// </summary>
|
||||
public override Resolution DefaultResolution()
|
||||
{
|
||||
return Resolution.Daily;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the supported resolution for this data and security type
|
||||
/// </summary>
|
||||
public override List<Resolution> SupportedResolutions()
|
||||
{
|
||||
return DailyResolution;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace QuantConnect.Data.Custom.Tiingo
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper class to map a Lean format ticker to Tiingo format
|
||||
/// </summary>
|
||||
/// <remarks>To be used when performing direct queries to Tiingo API</remarks>
|
||||
/// <remarks>https://api.tiingo.com/documentation/appendix/symbology</remarks>
|
||||
public static class TiingoSymbolMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps a given <see cref="Symbol"/> instance to it's Tiingo equivalent
|
||||
/// </summary>
|
||||
public static string GetTiingoTicker(Symbol symbol)
|
||||
{
|
||||
return symbol.Value.Replace(".", "-");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a given Tiingo ticker to Lean equivalent
|
||||
/// </summary>
|
||||
public static string GetLeanTicker(string ticker)
|
||||
{
|
||||
return ticker.Replace("-", ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user