Hello,
I am working on an algorithm, in which we are trading for four months. But when I run the algo in QC, we could not see any trading or orders after one month. But when I set the date range for that specific month then the trading happened and orders generated.
So is there any limitation for trading line one month or something. Below is the algo I am trying with.
using QuantConnect.Data;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using System;
using System.Net;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Algorithm.Framework.Selection;
namespace QuantConnect.Algorithm.CSharp
{
public class TachyonQuantumCompensator : QCAlgorithm
{
private List<Symbol> _longSymbols = new List<Symbol>();
private List<Symbol> _shortSymbols = new List<Symbol>();
public override void Initialize()
{
SetStartDate(2020, 07, 06);
SetEndDate(2020, 10, 31);
SetBenchmark("AAPL");
//SetEndDate(2020, 08, 27);
//why is is profitable when we set this to 1mil but not 100k?
//maybe fill problems when cash is too low
//reduced shares bouch by an order of magnatude to test
SetCash(100000);
//If no price found, need to take the last known price.
SetSecurityInitializer(s =>
{
var data = GetLastKnownPrice(s);
if (data == null)
{
Debug($"No historical data on {Time} for {s.Symbol}");
_longSymbols.Remove(s.Symbol);
_shortSymbols.Remove(s.Symbol);
}
s.SetMarketPrice(data);
});
SetUniverseSelection(new ScheduledUniverseSelectionModel(
DateRules.EveryDay(),
TimeRules.At(9, 30),
SelectSymbols
));
//sell before the close
Schedule.On(
DateRules.EveryDay(),
TimeRules.At(16, 45), () =>
{
Liquidate();
_longSymbols.Clear();
_shortSymbols.Clear();
});
}
private IEnumerable<Symbol> SelectSymbols(DateTime dateTime)
{
var currentDate = dateTime.ToString("yyyyMMdd", CultureInfo.InvariantCulture);
var longUrl = $@"https://batchformattertest.blob.core.windows.net/output/{currentDate}/longs.txt";
var shortUrl = $@"https://batchformattertest.blob.core.windows.net/output/{currentDate}/shorts.txt";
try
{
_longSymbols = StringToSymbols(Download(longUrl));
_shortSymbols = StringToSymbols(Download(shortUrl));
var symbols = _longSymbols.Concat(_shortSymbols);
return symbols.Count() == 0
? Universe.Unchanged
: symbols;
}
catch (WebException ex)
{
Log($"{ex.Message}");
_longSymbols.Clear();
_shortSymbols.Clear();
return Universe.Unchanged;
}
}
public override void OnData(Slice slice)
{
if (Time.Hour == 9 && Time.Minute <= 31)
{
try
{
foreach (var symbol in slice.Keys)
{
if (!Securities[symbol].Invested)
{
var openingBar = slice.Bars[symbol];
if (_shortSymbols.Contains(symbol) && openingBar.Close > openingBar.Open)
{
StopMarketOrder(symbol, -10, 0.9975m * Securities[symbol].Close);
//Debug($"Short order placed for {symbol.Value} at {Time}");
}
else if (_longSymbols.Contains(symbol) && openingBar.Close > openingBar.Open)
{
StopMarketOrder(symbol, 10, 1.0025m * Securities[symbol].Close);
// Debug($"Long order placed for {symbol.Value} at {Time}");
}
}
}
}
catch (Exception e)
{
Debug($"Excepion for the date {Time} : {e.StackTrace}");
}
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var security in changes.RemovedSecurities)
{
if (security.Invested)
{
Liquidate(security.Symbol, $"Removed from Universe at {Time}");
}
}
}
private List<Symbol> StringToSymbols(string tickers)
{
var list = new List<Symbol>();
if (string.IsNullOrEmpty(tickers) || tickers.IndexOf("error", StringComparison.InvariantCultureIgnoreCase) >= 0)
return list;
foreach (var item in tickers.Split('\n'))
{
var ticker = item.Replace("\r", "");
if (!string.IsNullOrWhiteSpace(ticker))
{
try
{
list.Add(QuantConnect.Symbol.Create(ticker, SecurityType.Equity, Market.USA));
}
catch
{
// NOP
}
}
}
return list;
}
}
}
?
Derek Melchin
Hi Parthiv,
For issues with live algorithms, contact support@quantconnect.com.
Best,
Derek Melchin
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.
Parthiv HardPress
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!