| Overall Statistics |
|
Total Trades 32 Average Win 3.11% Average Loss -3.53% Compounding Annual Return -9.361% Drawdown 40.400% Expectancy -0.123 Net Profit -6.080% Sharpe Ratio -0.045 Probabilistic Sharpe Ratio 17.851% Loss Rate 53% Win Rate 47% Profit-Loss Ratio 0.88 Alpha -0.031 Beta 0.07 Annual Standard Deviation 0.359 Annual Variance 0.129 Information Ratio -0.624 Tracking Error 0.377 Treynor Ratio -0.23 Total Fees $116.46 |
using QuantConnect.Data;
using QuantConnect.Data.Auxiliary;
using QuantConnect.Data.Custom.SEC;
namespace QuantConnect.Algorithm.CSharp
{
public class SECReport8KAlgorithm : 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(2019, 1, 1);
SetEndDate(2019, 8, 21);
SetCash(100000);
UniverseSettings.Resolution = Resolution.Minute;
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseSelector));
// Request underlying equity data.
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
// Add SEC report 10-Q data for the underlying IBM asset
var earningsFiling = AddData<SECReport10Q>(ibm).Symbol;
// Request 120 days of history with the SECReport10Q IBM custom data Symbol.
var history = History<SECReport10Q>(earningsFiling, 120, Resolution.Daily);
// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}
public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
{
// Add SEC data from the filtered coarse selection
var symbols = coarse.Where(x => x.HasFundamentalData && x.DollarVolume > 50000000)
.Select(x => x.Symbol)
.Take(10);
foreach (var symbol in symbols)
{
AddData<SECReport8K>(symbol);
}
return symbols;
}
public override void OnData(Slice data)
{
// Store the symbols we want to long in a list
// so that we can have an equal-weighted portfolio
var longEquitySymbols = new List<Symbol>();
// Get all SEC data and loop over it
foreach (var report in data.Get<SECReport8K>().Values)
{
// Get the length of all contents contained within the report
var reportTextLength = report.Report.Documents.Select(x => x.Text.Length).Sum();
if (reportTextLength > 20000)
{
longEquitySymbols.Add(report.Symbol.Underlying);
}
}
foreach (var equitySymbol in longEquitySymbols)
{
SetHoldings(equitySymbol, 1m / longEquitySymbols.Count);
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var r in changes.RemovedSecurities.Where(x => x.Symbol.SecurityType == SecurityType.Equity))
{
// If removed from the universe, liquidate and remove the custom data from the algorithm
Liquidate(r.Symbol);
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(SECReport8K), r.Symbol, Market.USA));
}
}
}
}