Back

Memory Usage Maxed Out

Hallo, I am trying to run a simple dip buying strategy backtest. The strategy buys the first stock out of the list, which price falls 2% below yesterday close and sell it at close. When I try to run with secod resolution, I alwas get error message: Memory Usage Maxed Out. Am I doing something wrong in the code?

/*
Strategy DipFast
buy intraday the first stock out of the list, which price drops below the yesterday Close * 0.98
*/

namespace QuantConnect
{
public class BasicTemplateAlgorithm : QCAlgorithm
{
string Dow30 = "MMM,APX,AAPL,BA,CAT,CVX,CSCO,KO,DIS,DD,XOM,GE,GS,HD,IBM,INTC,JNJ,JPM,MCD,MRK,MSFT,NKE,PFE,PG,TRV,UTX,UNH,VZ,V,WMT";
string symbols;
List Daily_Close;
List symbolList;

public override void Initialize()
{
SetStartDate(2008, 1, 1);
SetEndDate(DateTime.Now.Date.AddDays(-1));
SetEndDate(2015, 5, 27);
SetCash(10000);
symbols = Dow30;
symbolList = new List(symbols.Split(new char[] { ',' }));
Daily_Close = new List();
Daily_Close.Clear();
for (int n = 0; n < symbolList.Count; n++)
{
AddSecurity(SecurityType.Equity, symbolList[n], Resolution.Second);
Daily_Close.Add(SMA(symbolList[n], 1, Resolution.Daily));
}
}

public void OnData(TradeBars data)
{
for (int n=0; n {
string symbol = symbolList[n];
if (!data.ContainsKey(symbol)) continue;

if ((!Portfolio.HoldStock) && (Time.TimeOfDay.TotalHours >= 9.54) && (Time.TimeOfDay.TotalHours < 15.75))
{
decimal buyLimit = Daily_Close[n] * 0.98m;
decimal price = data[symbol].Price;
if ( price < buyLimit)
{
int quantity = (int)Math.Floor(Portfolio.Cash * 0.99m / price);
Order(symbol, quantity);
break;
}
}
}
if (Portfolio.HoldStock)
{
if ((Time.Minute == 59) && (Time.Hour == 15))
{
Liquidate();
}
}
}
}
}
Update Backtest








Hey Jan!

I will look into what's causing this, but in the mean time I would recommend using minute resolution data over such a large time frame and with 30 symbols.

It appears your strategy doesn't really need the second resolution. Using minute resolution will give you much faster backtests.

I've attached a modified version of your code that uses minute resolution and I've also included a data filter so only the first and last 30 minutes of data during normal equity market hours will be sent into the algorithm. This should greatly reduce the time required for back testing. I hope this helps :)
1

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