Back

Get symbol (for use in schedule function) from universe

Hi, I am just getting my head around universes but I am having one simple problem. I cant get a symbol to put in my schedule function.

Attached is the code. Essentially I am using the top5DollarVolume coarse universe example. But I want to trigger a schedule function and need one symbol for the date rule part.

You can see i have created logs to try get a symbol, but I am not sure if any symbols are added to my unverse in the first place.

using Accord;
using MathNet.Numerics.Statistics;

namespace QuantConnect.Algorithm.CSharp
{
public class prev_day_change : QCAlgorithm
{

private const int NumberOfSymbols = 5;

private SecurityChanges _changes = SecurityChanges.None;

/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
public override void Initialize()
{
//SetWarmUp(TimeSpan.FromDays(2)); //Warm up 30 days of data.
UniverseSettings.Resolution = Resolution.Minute;
SetStartDate(2013, 10, 07); //Set Start Date //SetStartDate(2013, 10, 07);
SetEndDate(2013, 10, 11); //Set End Date
SetCash(10000); //Set Strategy Cash
// Find more symbols here: http://quantconnect.com/data

AddUniverse(CoarseSelectionFunction);
Log("beginning:" + _changes.AddedSecurities.Count);
Log("securities.values" + Securities.Values);
foreach (var security in _changes.AddedSecurities)
{
Log("test security:" + security.Symbol);
}
var a = 1;



//Schedule function that runs 60 min after open every day
Schedule.On(DateRules.EveryDay(SYMBOL), TimeRules.AfterMarketOpen(SYMBOL, 10), () =>
{

//Create a function that calls the functions I want to call and put it here
testFunction();
});

}

public static IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
{
// sort descending by daily dollar volume
var sortedByDollarVolume = coarse.OrderByDescending(x => x.DollarVolume);

// take the top entries from our sorted collection
var top5 = sortedByDollarVolume.Take(NumberOfSymbols);

// we need to return only the symbol objects
return top5.Select(x => x.Symbol);
}
Update Backtest








Can you not use SPY?

_SYMBOL = AddEquity("SPY").Symbol;

Then you need to monitor the symbols you are going to add to the universe. If SPY doesn't belong to to them SPY is not tradable:

_isTradable = top5.Any(x => x.Symbol.Equals(SYMBOL));
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed