private void Init(Stock stock, DateTime date) { InitializeComponent(); _chain = OptionDataBase.Get(stock, date); FillChainExpandables(); FillSymbolLabel(); ClearPreviewTrade(); }
public void ChangeStock(Stock stock, DateTime date) { _chain = OptionDataBase.Get(stock, date); if (_chain != null) { FillChainExpandables(); FillSymbolLabel(); ClearPreviewTrade(); } }
public bool HistoricData(DateTime date) { OptionChain chain = OptionDataBase.Get(_stock, date); if (chain != null) { return(true); } return(false); }
public FormMain() { GlobalObjects.Initialize(); Api.Initialize(File.ReadAllText("AlphavantageKey.txt")); StockDataBase.Initialize(TimeSpan.FromHours(5)); OptionDataBase.Initialize(); WatchListManager.Initialize(); InitializeComponent(); watchListUI.Link(GlobalObjects.Chart); chartControl.Link(GlobalObjects.Chart); watchListUI.LoadStockEvent += new WatchListUI.LoadStockHandler(LoadStock); chartControl.LoadStockEvent += new ChartControl.LoadStockHandler(LoadStockChart); }
public static Option GetOption(Stock stock, OptionType optionType, PositionType posType, double strike, DateTime experation, DateTime date) { OptionChain chain = OptionDataBase.Get(stock, date); if (chain != null) { OptionChainDataPoint option = chain.FindOption(optionType, experation, strike); return(new Option(stock, option.Type, posType, option.Strike, option.Experation)); } else { int daysUntilThursday = 4 - (int)experation.DayOfWeek; experation = experation.AddDays(daysUntilThursday); strike = Math.Round(strike, 0); double amountFromTwoFifty = (strike % 2.5) <= (2.5 - strike % 2.5) ? -(strike % 2.5) : (2.5 - strike % 2.5); strike += amountFromTwoFifty; return(new Option(stock, optionType, posType, strike, experation)); } }
public async Task <double> Price(DateTime date) { double price = 0; OptionChain chain = OptionDataBase.Get(_stock, date); if (chain != null) { OptionChainDataPoint option = chain.FindOption(_optionType, _expDate, _strike); price = (option.Bid + option.Ask) * 0.5; } else { TimeSpan updateSpan = DateTime.UtcNow - date; StockData data = await StockDataBase.Get(_stock, Api.Interval.Daily, updateSpan); int index = data.FindDateIndex(date); int expiration = DaysUntilExpiration(date); price = Indicators.Options.AproxPrice(data, index, _optionType, _strike, expiration); } return(price); }
public void Fill(OptionTrade trade, DateTime dataDate) { Clear(); if (trade.Spread.Options[0] != null) { if (trade.Spread.Options[0].Strike > 0) { OptionChain chain = OptionDataBase.Get(trade.Spread.Stock, dataDate); OptionChainDataPoint option1 = chain.FindOption(trade.Spread.Options[0].OptionType, trade.Spread.Options[0].ExpirationDate, trade.Spread.Options[0].Strike); if (trade.Spread.Options[0].PositionType == PositionType.Long) { orderLineUI1.Fill(option1, trade.Amount); } else if (trade.Spread.Options[0].PositionType == PositionType.Short) { orderLineUI1.Fill(option1, trade.Amount * -1); } } } if (trade.Spread.Options[1] != null) { if (trade.Spread.Options[1].Strike > 0) { OptionChain chain = OptionDataBase.Get(trade.Spread.Stock, dataDate); OptionChainDataPoint option1 = chain.FindOption(trade.Spread.Options[1].OptionType, trade.Spread.Options[1].ExpirationDate, trade.Spread.Options[1].Strike); if (trade.Spread.Options[1].PositionType == PositionType.Long) { orderLineUI2.Fill(option1, trade.Amount); } else if (trade.Spread.Options[1].PositionType == PositionType.Short) { orderLineUI2.Fill(option1, trade.Amount * -1); } } } }
public static Spread GetSpread(Stock stock, SpreadType type, double strikeLow, double spreadWidth, DateTime experationDate, DateTime date) { Option[] options; if (type == SpreadType.LongCall || type == SpreadType.LongPut || type == SpreadType.ShortPut) { options = new Option[1]; } else { options = new Option[2]; } switch (type) { case SpreadType.LongCall: options[0] = Option.GetOption(stock, OptionType.Call, PositionType.Long, strikeLow, experationDate, date); break; case SpreadType.LongPut: options[0] = Option.GetOption(stock, OptionType.Put, PositionType.Long, strikeLow, experationDate, date); break; case SpreadType.ShortPut: options[0] = Option.GetOption(stock, OptionType.Put, PositionType.Short, strikeLow, experationDate, date); break; case SpreadType.LongCallVertical: options[0] = Option.GetOption(stock, OptionType.Call, PositionType.Long, strikeLow, experationDate, date); options[1] = Option.GetOption(stock, OptionType.Call, PositionType.Short, strikeLow + spreadWidth, experationDate, date); break; case SpreadType.ShortCallVertical: options[0] = Option.GetOption(stock, OptionType.Call, PositionType.Short, strikeLow, experationDate, date); options[1] = Option.GetOption(stock, OptionType.Call, PositionType.Long, strikeLow + spreadWidth, experationDate, date); break; case SpreadType.LongPutVertical: options[0] = Option.GetOption(stock, OptionType.Put, PositionType.Short, strikeLow, experationDate, date); options[1] = Option.GetOption(stock, OptionType.Put, PositionType.Long, strikeLow + spreadWidth, experationDate, date); break; case SpreadType.ShortPutVertical: options[0] = Option.GetOption(stock, OptionType.Put, PositionType.Long, strikeLow, experationDate, date); options[1] = Option.GetOption(stock, OptionType.Put, PositionType.Short, strikeLow + spreadWidth, experationDate, date); break; } if (options.Length == 2) { if (options[0].Strike == options[1].Strike) { OptionChain chain = OptionDataBase.Get(options[1].Stock, date); double newStrike = chain.FindNextStrike(options[1].Strike, options[1].ExpirationDate); options[1] = Option.GetOption(options[1].Stock, options[1].OptionType, options[1].PositionType, newStrike, options[1].ExpirationDate, date); } } Spread spread = new Spread(options); return(spread); }