public void SaveQuotes_Multiple_Success() { IQuotesSource source = CreateSource(); IQuotesDal dal = PrepareQuotesDal(); IQuotesDalSaveTimeseriesValuesParams saveParams = dal.CreateSaveTimeseriesValuesParams(); string[] tickers = { ConfigurationManager.AppSettings["TickerSPY"], ConfigurationManager.AppSettings["TickerQQQ"] }; IQuotesSourceGetQuotesParams getQuotesParams = source.CreateGetQuotesParams(); foreach (var t in tickers) { getQuotesParams.Tickers.Add(t); } getQuotesParams.Country = ConfigurationManager.AppSettings["CountryUS"]; getQuotesParams.PeriodStart = DateTime.Parse("2009/1/1"); getQuotesParams.PeriodEnd = DateTime.Parse("2019/1/1"); getQuotesParams.TimeFrame = ETimeFrame.Daily; IQuotesSourceGetQuotesResult getQuotesResult = source.GetQuotes(getQuotesParams); saveParams.Quotes.AddRange(getQuotesResult.QuotesData); IQuotesDalSaveTimeseriesValuesResult saveResult = dal.SaveTimeseriesValues(saveParams); Assert.IsTrue(saveResult.Success); Assert.IsTrue(!saveResult.HasWarnings, "Unexpected warnings while performing save"); Assert.IsTrue(!saveResult.HasErrors, "Unexpected errors while performing save"); }
public void BuildPortfolio_5Tickers_MaxReturn_Success() { IQuotesDal dal = PrepareQuotesDal(); IPortfolioBuilder builder = PreparePortfolioBuilder(dal); // preparing list of instruments IPortfolioBuilderBuildParams buildParams = builder.CreatePortfolioBuilderBuildParams(); buildParams.Goal = EOptimizationGoal.Max; // maximizing portfolio return buildParams.OptimizationTarget = EProtfolioProperty.Return; buildParams.Instruments.Add(ConfigurationManager.AppSettings["TickerSPY"]); buildParams.Instruments.Add(ConfigurationManager.AppSettings["TickerQQQ"]); buildParams.Instruments.Add(ConfigurationManager.AppSettings["TickerGLD"]); buildParams.Instruments.Add(ConfigurationManager.AppSettings["TickerSLV"]); buildParams.Instruments.Add(ConfigurationManager.AppSettings["TickerTLT"]); buildParams.TimeFrame = PortfolioInterfaces.ETimeFrame.Monthly; buildParams.PeriodStart = DateTime.Parse(ConfigurationManager.AppSettings["PeriodStart"]); buildParams.PeriodEnd = DateTime.Parse(ConfigurationManager.AppSettings["PeriodEnd"]); // setting constraints foreach (var i in buildParams.Instruments) { IPortfolioBuilderConstraint cl = builder.CreateConstraint(); cl.Operation = EConstraintOp.GreaterOrEqual; cl.Property = EProtfolioProperty.Instrument; cl.Ticker = i; cl.Value = 0; IPortfolioBuilderConstraint cu = builder.CreateConstraint(); cu.Operation = EConstraintOp.LessOrEqual; cu.Property = EProtfolioProperty.Instrument; cu.Ticker = i; cu.Value = 1; buildParams.Constraints.Add(cl); buildParams.Constraints.Add(cu); } IPortfolioBuilderConstraint cstdev = builder.CreateConstraint(); cstdev.Operation = EConstraintOp.LessOrEqual; cstdev.Property = EProtfolioProperty.StDev; cstdev.Value = (decimal)0.1; // limiting stdev to 10% buildParams.Constraints.Add(cstdev); IPortfolioBuilderBuildResult result = builder.Build(buildParams); Assert.IsTrue(result.Success); Assert.IsNotNull(result.Portfolio); Assert.IsNotNull(result.Portfolio.Instruments); Assert.AreEqual(result.Portfolio.Instruments.Count, 5); Assert.AreEqual(result.Portfolio.Instruments.Values.ElementAt(0) + result.Portfolio.Instruments.Values.ElementAt(1) + result.Portfolio.Instruments.Values.ElementAt(2) + result.Portfolio.Instruments.Values.ElementAt(3) + result.Portfolio.Instruments.Values.ElementAt(4), (decimal)1, "Sum of weights is not 100%"); }
private IPortfolioBuilder PreparePortfolioBuilder(IQuotesDal dal) { IPortfolioBuilder builder = new PortfolioBuilder(); // initializing IPortfolioBuilderInitParams initParams = builder.CreateInitParams(); initParams.QuotesDal = dal; builder.Init(initParams); return(builder); }
private void InitDAL() { string dalType = ConfigurationManager.AppSettings["QuotesDalType"]; _dal = _compContainer.GetExport <IQuotesDal>(dalType).Value; IQuotesDalInitParams initParams = _dal.CreateInitParams(); initParams.Parameters["RootFolder"] = Path.Combine(_compContainer.GetExportedValue <string>("ServiceRootFolder"), ConfigurationManager.AppSettings["CSVDalRootFolder"]); initParams.Parameters["ConnectionStringTimeSeries"] = ConfigurationManager.AppSettings["ConnectionStringTimeSeries"]; _dal.Init(initParams); }
private void InitDAL() { _logger.Log(EErrorType.Info, string.Format("InitDAL: Connecting to '{0}'", ConfigurationManager.AppSettings["ConnectionStringTimeSeries"])); Lazy <IQuotesDal> dal = _compContainer.GetExport <IQuotesDal>(ConfigurationManager.AppSettings["DALType"]); IQuotesDalInitParams dalParams = dal.Value.CreateInitParams(); dalParams.Parameters.Add("ConnectionStringTimeSeries", ConfigurationManager.AppSettings["ConnectionStringTimeSeries"]); dal.Value.Init(dalParams); _dal = dal.Value; }
public void GetQuotes_Single_Failed() { IQuotesDal dal = PrepareQuotesDal(); IQuotesDalGetTimeSeriesValuesParams getParams = dal.CreateGetQuotesParams(); getParams.Country = ConfigurationManager.AppSettings["CountryUS"]; getParams.Tickers.Add(ConfigurationManager.AppSettings["InvalidTicker"]); getParams.TimeFrame = ETimeFrame.Monthly; IQuotesDalGetTimeseriesValuesResult result = dal.GetTimseriesValues(getParams); Assert.IsFalse(result.Success); Assert.IsNotNull(result.Quotes); Assert.AreEqual(result.Quotes.Count, 0); }
public void GetQuotes_Single_Success() { IQuotesDal dal = PrepareQuotesDal(); IQuotesDalGetTimeSeriesValuesParams getParams = dal.CreateGetQuotesParams(); getParams.Country = ConfigurationManager.AppSettings["CountryUS"]; getParams.Tickers.Add(ConfigurationManager.AppSettings["TickerSPY"]); getParams.TimeFrame = ETimeFrame.Monthly; IQuotesDalGetTimeseriesValuesResult result = dal.GetTimseriesValues(getParams); Assert.IsTrue(result.Success); Assert.IsNotNull(result.Quotes); Assert.AreEqual(result.Quotes.Count, 1); Assert.AreEqual(result.Quotes[0].Ticker, ConfigurationManager.AppSettings["TickerSPY"]); Assert.AreEqual(result.Quotes[0].Country, ConfigurationManager.AppSettings["CountryUS"]); Assert.AreNotEqual(result.Quotes[0].Quotes.Count(), 0); }
public void Init(IPortfolioBuilderInitParams initParams) { _logger = initParams.Logger; _quotesDal = initParams.QuotesDal; }