/// <summary> /// Calculates the Black-Scholes price of an option. /// High-Low volatility used with a range of one year, should be set in option already. /// </summary> /// <param name="option"> /// </param> /// <returns> /// </returns> public double BlackScholes(OptionDto option) { try { if (Math.Abs(option.Volatility) < double.Epsilon) { return(0.0); } var optionType = option.Symbol[10] == 'C' ? AlgoTrader.BlackScholes.Type.Call : AlgoTrader.BlackScholes.Type.Put; var timeToExpiryInYears = float.Parse(option.DaysToExpiry) / 365; var blackScholesPrice = AlgoTrader.BlackScholes.Black_Scholes( optionType, (double)option.LastPrice, (double)option.StrikePrice, timeToExpiryInYears, 0.25, // U.S. Govt. Treasury Interest Rate circa.12/2013. option.Volatility); return(Math.Round(blackScholesPrice, 2)); } catch (Exception ex) { throw ex; } }
protected virtual async Task Create(OptionDto input) { Option comment = MappingProfile.MappingConfigurationSetups().Map<Option>(input); _context.Option.Add(comment); await _context.SaveChangesAsync(); }
protected virtual async Task Update(OptionDto input) { var option = await _context.Option.Where(x => x.Id == input.Id).FirstOrDefaultAsync(); if (option != null) { Option optionDto = MappingProfile.MappingConfigurationSetups().Map<Option>(input); _context.Option.Update(optionDto); await _context.SaveChangesAsync(); } }
public async Task CreateOrEditOption(OptionDto input) { if (input.Id == 0) { await Create(input); } else { await Update(input); } }
public async Task<OptionDto> GetOptionForEdit(OptionDto input) { var option = await _context.Option.Where(x => x.Id == input.Id).FirstOrDefaultAsync(); if (option != null) { Option optionDto = MappingProfile.MappingConfigurationSetups().Map<Option>(input); _context.Option.Update(optionDto); await _context.SaveChangesAsync(); return MappingProfile.MappingConfigurationSetups().Map<OptionDto>(optionDto); } return new OptionDto(); }
/// <summary> /// The volatility. /// </summary> /// <param name="option"> /// The option. /// </param> /// <param name="fromDate"> /// </param> /// <param name="toDate"> /// The to Date. /// </param> /// <returns> /// The <see cref="double"/>. /// </returns> public double Volatility(OptionDto option, DateTime?fromDate, DateTime?toDate) { try { var companyTicker = string.Empty; for (var i = 0; i <= 4; i++) { int res; var isNum = int.TryParse(option.Symbol[i].ToString(), out res); if (!isNum) { companyTicker += option.Symbol[i]; } } // Annual volatilty by default. fromDate = fromDate ?? DateTime.Today.AddYears(-1); toDate = toDate ?? DateTime.Today; // If volatility already calculated for this symbol/option use the stored value. double volatility = 0; if (_symbolVolatility.Key != companyTicker) { volatility = AlgoTrader.YahooApi.VolatilityAndMarketData.highLowVolatility(companyTicker, fromDate.Value, toDate.Value); _symbolVolatility = new KeyValuePair <string, double>(companyTicker, volatility); } else if (_symbolVolatility.Key == companyTicker) { volatility = _symbolVolatility.Value; } if (Math.Abs(volatility) < double.Epsilon) { throw new InvalidOperationException( $"Volatility cannot be zero (tolerance double epsilson constant)'{volatility}'"); } return(volatility); } catch (WebException ex) { // TODO Log http exception and carry on. return(0.0); } catch (Exception ex) { throw ex; } }
public IHttpActionResult SearchTrain(int startStationId, int endStationId) { int statStationRouteId = _context.Stations.Single(s => s.SID == startStationId).RID; int endStationRouteId = _context.Stations.Single(s => s.SID == endStationId).RID; //both stations in same GetRoute if (statStationRouteId == endStationRouteId) { var data = GetTrains(startStationId, endStationId); var timeTaken = TimeSpan.FromSeconds(CalculateApproximateTime(data)); var options = new OptionDto { TimeTaken = timeTaken.ToString("g"), Options = data }; var result = new SearchTrainResult(); result.Result.Add(options); result.Count = "1"; return(Ok(result)); } //stations in near by GetRoute var startStationPrimaryRId = _context.Routes.Single(r => r.RID == statStationRouteId).prid; var endStationPrimaryRId = _context.Routes.Single(r => r.RID == endStationRouteId).prid; var flag = (statStationRouteId == endStationPrimaryRId) ? 1 : ((endStationRouteId == startStationPrimaryRId) ? 2 : ((startStationPrimaryRId == endStationPrimaryRId) ? 3 : 0)); if (flag > 0) { int findStation = flag == 1 ? endStationRouteId : statStationRouteId; int connectingStation = GetConnectingStation(findStation); var list1 = GetTrains(startStationId, connectingStation); var list2 = GetTrains(connectingStation, endStationId); var result = FilterResult(list1, list2); return(Ok(result)); } { _routeIdList = new List <int>(); _routeIdList = GetRoute(statStationRouteId, endStationRouteId); return(Ok(_routeIdList)); } }
public static async Task <IValidator <OptionDto, Option> > CreateOptionAsync(OptionDto optionDto, IEnumerable <IRuleSpecification <OptionDto> > rules) { var validator = new Validator <OptionDto, Option>(rules); await validator.ExecuteCheckAsync(optionDto, new Option()); //Qui potrebbero essere inserite delle rules a livello di codice da richiamare sempre //(oppure prima del controllo delle rules dinamiche) if (!validator.IsValid) { return(validator); } validator.ValidatedObject.SetName(optionDto.Name); validator.ValidatedObject.SetDescription(optionDto.Description); validator.ValidatedObject.Note = optionDto.Note; return(validator); }
private void ParsePayoutFields(string[] content, int index, OptionDto option) { // 2,1;2;3;4,3,3 // 11 - 13, 20 - 22 // 14 - 16 , 23 - 25 if (string.IsNullOrWhiteSpace(content[index])) { return; } PayoutDto payout = new PayoutDto(); payout.PayoutNumber = int.Parse(content[index]); payout.PayoutTypeId = string.IsNullOrWhiteSpace(content[index + 1]) ? null : (int?)int.Parse(content[index + 1]); payout.FieldsContent = content[index + 2].Trim(); option.Payouts.Add(payout); }
private void ParseOptionFields(string[] content, int index) { // 8 - 10 1,1;2;3;4 // 17 - 19 if (string.IsNullOrWhiteSpace(content[index])) { return; } OptionDto option = new OptionDto(); option.OptionNumber = int.Parse(content[index]); option.OptionTypeId = string.IsNullOrWhiteSpace(content[index + 1]) ? null : (int?)int.Parse(content[index + 1]); option.FieldsContent = content[index + 2].Trim(); ParsePayoutFields(content, index + 3, option); ParsePayoutFields(content, index + 6, option); ((ScrubCaCommand)Command).Options.Add(option); }
private static SearchTrainResult FilterResult(IEnumerable <TrainDataDto> list1, List <TrainDataDto> list2) { SearchTrainResult result = new SearchTrainResult(); foreach (TrainDataDto dataDto in list1) { var data = new OptionDto(); foreach (TrainDataDto trainDataDto in list2) { if (trainDataDto.StartStationDeparture1 >= dataDto.EndStationArrival1) { if (dataDto.TrainId == trainDataDto.TrainId) { dataDto.EndStationArrival = trainDataDto.EndStationArrival; //dataDto.EndStationDeparture = trainDataDto.EndStationDeparture; dataDto.EndStationId = trainDataDto.EndStationId; data.Options.Add(dataDto); list2.Remove(trainDataDto); break; } else { data.Options.Add(dataDto); data.Options.Add(trainDataDto); break; } } } if (data.Options.Count <= 0) { continue; } data.TimeTaken = TimeSpan.FromSeconds(CalculateApproximateTime(data.Options)).ToString(); result.Result.Add(data); } result.Count = result.Result.Count.ToString(); return(result); }
public List<OptionDto> GetAllOption(OptionDto input) { var query = (from option in _context.Option.ToList() join question in _context.Question.ToList() on option.QuestionId equals question.Id select new OptionDto { QuestionName = question.Questions, Id = option.Id, DateCreated = option.DateCreated, Status = option.Status, UserId = option.UserId, Options = option.Options }).ToList().Skip((input.PagedResultDto.Page - 1) * input.PagedResultDto.SkipCount).Take(input.PagedResultDto.MaxResultCount); // Map Records List<OptionDto> ratingDto = MappingProfile.MappingConfigurationSetups().Map<List<OptionDto>>(query); //Apply Sort ratingDto = Sort(input.PagedResultDto.Sort, input.PagedResultDto.SortOrder, ratingDto); // Apply search if (!string.IsNullOrEmpty(input.PagedResultDto.Search)) { ratingDto = ratingDto.Where(p => p.Status != null && p.Status.ToLower().ToString().ToLower().Contains(input.PagedResultDto.Search.ToLower()) || p.QuestionName != null && p.QuestionName.ToString().ToLower().Contains(input.PagedResultDto.Search.ToLower()) || p.DateCreated != null && p.DateCreated.ToString().ToLower().Contains(input.PagedResultDto.Search.ToLower()) || p.Options != null && p.Options.ToString().ToLower().ToString().Contains(input.PagedResultDto.Search.ToLower()) ).ToList(); } return ratingDto; }
public async Task CreateOrEditOption(OptionDto input) { await _unitOfWork.Options.CreateOrEditOption(input); }
public UpdateOptionCommand(OptionDto option) { Option = option; }
public async Task GetOptionForEdit(OptionDto input) { await _unitOfWork.Options.GetOptionForEdit(input); }
public List <OptionDto> GetAllOption(OptionDto input) { return(_unitOfWork.Options.GetAllOption(input)); }
private async Task seedDatabaseForProduct(IProductRepository repository, IRepository <Category> categoryRepository, IRepository <Option> optionRepository) { //Per fare presto (essendo un progettino di dimostrazione) //Popolo il database nel caos in cui non trovo nessun prodotto //Utilizzo direttamente ListAll per fare prima a scrivere il codice anche se sarĂ piu lento var products = await repository.ListAllAsync(); var category = await categoryRepository.ListAllAsync(); var option = await optionRepository.ListAllAsync(); if (products.Count > 0 || category.Count > 0 || option.Count > 0) { return; } var categoryDto = new CategoryDto { Name = "Abiti Estivi", Description = "Ogni tipo di abito per l'estate", CategoryId = 1 }; var catOne = (await Category.CreateCategoryAsync(categoryDto, null)).ValidatedObject; categoryRepository.Add(catOne); await categoryRepository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente categoryDto = new CategoryDto { Name = "Abiti Invernali", Description = "Ogni tipo di abito invernale", CategoryId = 2 }; var catTwo = (await Category.CreateCategoryAsync(categoryDto, null)).ValidatedObject; categoryRepository.Add(catTwo); await categoryRepository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente categoryDto = new CategoryDto { Name = "Scarpe", Description = "Tutte le scarpe", CategoryId = 3 }; var catThree = (await Category.CreateCategoryAsync(categoryDto, null)).ValidatedObject; categoryRepository.Add(catThree); await categoryRepository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente var dto = new ProductDto { Name = "Pantanoni Lana", Description = "Pantaloni di lana economici", CategoryId = 2 }; var productOne = (await Product.CreateProductAsync(dto, null)).ValidatedObject; repository.Add(productOne); await repository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente dto = new ProductDto { Name = "Maglione Lana", Description = "Maglione di lana economici", CategoryId = 2 }; var productTwo = (await Product.CreateProductAsync(dto, null)).ValidatedObject; repository.Add(productTwo); await repository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente dto = new ProductDto { Name = "Camicia estiva", Description = "Camicia leggera", CategoryId = 1 }; var productThree = (await Product.CreateProductAsync(dto, null)).ValidatedObject; repository.Add(productThree); await repository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente dto = new ProductDto { Name = "Pantaloncini", Description = "Pantaloncini ottimi", CategoryId = 1 }; var productFour = (await Product.CreateProductAsync(dto, null)).ValidatedObject; repository.Add(productFour); await repository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente dto = new ProductDto { Name = "Scarpa", Description = "Scarpa per ogni stagione", CategoryId = 3 }; var productFive = (await Product.CreateProductAsync(dto, null)).ValidatedObject; repository.Add(productFive); await repository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente dto = new ProductDto { Name = "ScarpaSenzaOptioni", Description = "Scarpa usata senza optioni", CategoryId = 3 }; var productSix = (await Product.CreateProductAsync(dto, null)).ValidatedObject; repository.Add(productSix); await repository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente var optionDto = new OptionDto { Name = "Colore", Description = "Colore associato" }; var option1 = (await Option.CreateOptionAsync(optionDto, null)).ValidatedObject; optionRepository.Add(option1); await optionRepository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente optionDto = new OptionDto { Name = "Taglia", Description = "Taglia associata" }; var option2 = (await Option.CreateOptionAsync(optionDto, null)).ValidatedObject; optionRepository.Add(option2); await optionRepository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente optionDto = new OptionDto { Name = "Ricamo", Description = "Tipologia di ricamo" }; var option3 = (await Option.CreateOptionAsync(optionDto, null)).ValidatedObject; optionRepository.Add(option3); await optionRepository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente optionDto = new OptionDto { Name = "Misura", Description = "Misara in cm" }; var option4 = (await Option.CreateOptionAsync(optionDto, null)).ValidatedObject; optionRepository.Add(option4); await optionRepository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente optionDto = new OptionDto { Name = "OptioneMaiUsata", Description = "DescOption5" }; var option5 = (await Option.CreateOptionAsync(optionDto, null)).ValidatedObject; optionRepository.Add(option5); await optionRepository.SaveChangeAsync(); //Fatto ogni volta per garantirmi l'id crescente //repository.LinkCategory(productOne, catOne); //repository.LinkCategory(productFour, catOne); //repository.LinkCategory(productTwo, catTwo); //repository.LinkCategory(productFive, catTwo); //repository.LinkCategory(productThree, catThree); repository.LinkOption(productOne, option1); repository.LinkOption(productTwo, option1); repository.LinkOption(productThree, option1); repository.LinkOption(productFour, option1); repository.LinkOption(productFive, option1); repository.LinkOption(productOne, option2); repository.LinkOption(productTwo, option2); repository.LinkOption(productThree, option2); repository.LinkOption(productFour, option2); repository.LinkOption(productOne, option3); repository.LinkOption(productTwo, option3); repository.LinkOption(productThree, option3); repository.LinkOption(productFour, option3); repository.LinkOption(productFive, option4); await optionRepository.SaveChangeAsync(); }