So, for the following code:
class ForexTemplateAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetCash(100000)
self.SetStartDate(2018,1,1)
self.SetEndDate(datetime.now() - timedelta(1))
self.signs = [
"USDCAD",
"EURUSD",
"USDCHF",
"EURGBP",
"GBPUSD",
"USDJPY",
]
self.symbols = [Symbol.Create(x, SecurityType.Forex, Market.Oanda) for x in self.signs]
self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverseSelection(ManualUniverseSelectionModel(self.symbols))
self.SetAlpha(RsiAlphaModel())
self.SetAlpha(EmaCrossAlphaModel())
self.SetAlpha(MacdAlphaModel())
self.SetPortfolioConstruction(MeanVarianceOptimizationPortfolioConstructionModel())
self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.02))
self.SetExecution(ImmediateExecutionModel())
I get the following errors:
`Runtime Error: An item with the same key has already been added. Key: 11/03/2017 20:00:00 (Open Stacktrace)`
I am assuming it's because I'm trying to analyze Forex data but the MeanVarianceOptimizationPortfolioConstructionModel is calculating returns on 252 trading days as opposed to daily for Forex as shown in this code:
My question is, what should I do to modify the returns formula for the MeanVarianceOptimizationPortfolioConstructionModel code so it's compatible with Forex. Do I calculate returns over 365 days instead?
Thank you for your help! Best wishes.