Permalink
Switch branches/tags
algo-timeout-stacktrace alpaca-brokerage alpha-value-monthly bitfinex bug-337-add-support-for-python-project-directories bug-2187-remove-framework-pop-avg-score-warmup-period bug-2189-parralelize-fine-fundamental-reading bug-2288-pythonnet-memory-leak bug-2357-fix-insight-close-time bug-2381-daily-benchmark-for-backtesting bug-2381-setbenchmark-fix bug-2504-ib-always-restore-data-subscriptions bug-2513-performcashsync-once bug-2532-apply-splits-in-live-mode bug-2541-live-mode-always-apply-splits-never-apply-dividends bug-2569-apply-dividends-in-live-paper bug-2569-double-dividend-application bug-2611-live-trading-sync-algorithm-status-update bug-2762-market-order-fills-stale-prices bugfix-insight-close-time crypto-symbol-length debugging-api-logging desktop-mk-ii docker-file-lean-foundation-updates feature-452-net-core feature-1040-object-store feature-1093-vwap-order-type feature-1418-buying-power-order-fee-contexts feature-1418-fee-model-units feature-2003-kraken-exchange feature-2047-split-dividend-api feature-2060-multi-leg-currency-conversion feature-2068-refactor-regression-test-suite feature-2271-IRegressionAlgorithmDefinition-CanRunLocally feature-2378-fix-stream-reader-disposal feature-2378-generator-factors feature-2378-live-factor-files feature-2378-minor-split-dividend-fixes feature-2378-split-dividend-improvements feature-2581-multiple-risk-models feature-timestamped-packets feature/1418-fee-model-context feature/2606-custom-brokerage-message-handler features-1998-2219-portfolio-implementation-v2 fix-python-algorithm-loading fix-vix-futures-scale-factor fsdf-thread-count-logging ib-restart-handler-fix ibrokeragemodel-isshortsellingallowed live-test-move-addsubscription-removesubscription log-splits-dividends master multiple-brokerages quandl-live-extra-logging refactor-1418-buying-power-model-context refactor-2491-livetradingdatafeed-will-use-subscriptionsynchronizer refactor-2567-fill-fee-model-invocation refactor-remove-job-packet release-engine-test smarter-live-chart-subscriptions symbol-tostring-no-subscription test-insight-scoring tick_not_decimal track-all-security-subscriptions trade-crypto-history-requests tweak-2530-log-split-dividend-prices tweak-configure-await-extension tweak-improve-map-file-read-time tweak-make-InsightFromSerializedInsight-public tweak-minor-changes-splits-dividends
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
174 lines (155 sloc) 6.41 KB
/*
* 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.IO;
namespace QuantConnect.Data.UniverseSelection
{
/// <summary>
/// Defines summary information about a single symbol for a given date
/// </summary>
public class CoarseFundamental : BaseData
{
/// <summary>
/// Gets the market for this symbol
/// </summary>
public string Market { get; set; }
/// <summary>
/// Gets the day's dollar volume for this symbol
/// </summary>
public decimal DollarVolume { get; set; }
/// <summary>
/// Gets the day's total volume
/// </summary>
public long Volume { get; set; }
/// <summary>
/// Returns whether the symbol has fundamental data for the given date
/// </summary>
public bool HasFundamentalData { get; set; }
/// <summary>
/// Gets the price factor for the given date
/// </summary>
public decimal PriceFactor { get; set; } = 1m;
/// <summary>
/// Gets the split factor for the given date
/// </summary>
public decimal SplitFactor { get; set; } = 1m;
/// <summary>
/// Gets the combined factor used to create adjusted prices from raw prices
/// </summary>
public decimal PriceScaleFactor => PriceFactor * SplitFactor;
/// <summary>
/// Gets the split and dividend adjusted price
/// </summary>
public decimal AdjustedPrice => Price * PriceScaleFactor;
/// <summary>
/// The end time of this data.
/// </summary>
public override DateTime EndTime
{
get { return Time + QuantConnect.Time.OneDay; }
set { Time = value - QuantConnect.Time.OneDay; }
}
/// <summary>
/// Initializes a new instance of the <see cref="CoarseFundamental"/> class
/// </summary>
public CoarseFundamental()
{
DataType = MarketDataType.Auxiliary;
}
/// <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)
{
var path = Path.Combine(Globals.DataFolder, "equity", config.Market, "fundamental", "coarse", date.ToString("yyyyMMdd") + ".csv");
return new SubscriptionDataSource(path, 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.
/// </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)
{
try
{
var csv = line.Split(',');
var coarse = new CoarseFundamental
{
Symbol = new Symbol(SecurityIdentifier.Parse(csv[0]), csv[1]),
Time = date,
Market = config.Market,
Value = csv[2].ToDecimal(),
Volume = csv[3].ToInt64(),
DollarVolume = csv[4].ToDecimal()
};
if (csv.Length > 5)
{
coarse.HasFundamentalData = Convert.ToBoolean(csv[5]);
}
if (csv.Length > 7)
{
coarse.PriceFactor = csv[6].ToDecimal();
coarse.SplitFactor = csv[7].ToDecimal();
}
return coarse;
}
catch (Exception)
{
return null;
}
}
/// <summary>
/// Return a new instance clone of this object, used in fill forward
/// </summary>
/// <returns>A clone of the current object</returns>
public override BaseData Clone()
{
return new CoarseFundamental
{
Symbol = Symbol,
Time = Time,
DollarVolume = DollarVolume,
Market = Market,
Value = Value,
Volume = Volume,
DataType = MarketDataType.Auxiliary,
HasFundamentalData = HasFundamentalData,
PriceFactor = PriceFactor,
SplitFactor = SplitFactor
};
}
/// <summary>
/// Creates the symbol used for coarse fundamental data
/// </summary>
/// <param name="market">The market</param>
/// <returns>A coarse universe symbol for the specified market</returns>
public static Symbol CreateUniverseSymbol(string market)
{
market = market.ToLower();
var ticker = "qc-universe-coarse-" + market;
var sid = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market);
return new Symbol(sid, ticker);
}
}
}