public void MultipleBuySells() { var owned = new OwnedOption( new Ticker("SFIX"), 23.5m, OptionType.CALL, DateTimeOffset.Parse("2020-08-07"), Guid.NewGuid()); owned.Buy(1, 100, DateTimeOffset.Parse("2020-07-16"), null); owned.Sell(1, 50, DateTimeOffset.Parse("2020-07-17"), null); owned.Buy(1, 100, DateTimeOffset.Parse("2020-07-16"), null); owned.Sell(1, 50, DateTimeOffset.Parse("2020-07-17"), null); var pl = owned.State.Transactions.Where(tx => tx.IsPL); var profit = pl.Sum(t => t.Profit); Assert.Equal(-100, profit); }
public void ExportOptionsHeader() { var option = new OwnedOption( "tlsa", 2.5m, OptionType.CALL, DateTimeOffset.UtcNow.AddDays(1), Guid.NewGuid()); option.Sell(1, 20, DateTimeOffset.UtcNow, "some note"); var report = CSVExport.Generate(new[] { option }); Assert.Contains(CSVExport.OPTION_HEADER, report); Assert.Contains("TLSA", report); Assert.Contains("CALL", report); Assert.Contains("2.5", report); }
public FakePortfolioStorage CreateStorageWithSoldOption() { var storage = new FakePortfolioStorage(); var cmd = CreateSellCommand(); var opt = new OwnedOption( cmd.Ticker, cmd.StrikePrice, (OptionType)Enum.Parse(typeof(OptionType), cmd.OptionType), cmd.ExpirationDate.Value, cmd.UserId); opt.Sell(1, 20, DateTimeOffset.UtcNow, "some note"); storage.Register(opt); return(storage); }
public void AssignedCallBug() { var date = new DateTimeOffset(2020, 3, 13, 0, 0, 0, 0, TimeSpan.FromHours(0)); var user = Guid.NewGuid(); var option = new OwnedOption(new Ticker("SFIX"), 17.5m, OptionType.CALL, date, user); option.Sell(3, 100, date.AddDays(-20), null); option.Buy(2, 10, date.AddDays(-10), null); option.Expire(true); Assert.True(option.State.IsExpired); Assert.True(option.State.Assigned); Assert.False(option.State.Active); Assert.True(option.State.SoldToOpen); var pl = option.State.Transactions.Where(t => t.IsPL); Assert.Single(pl); }
public (IPortfolioStorage, OwnedOption) CreateStorageWithSoldOption() { var cmd = CreateSellCommand(); var opt = new OwnedOption( cmd.Ticker, cmd.StrikePrice, (OptionType)Enum.Parse(typeof(OptionType), cmd.OptionType), cmd.ExpirationDate.Value, cmd.UserId); opt.Sell(1, 20, DateTimeOffset.UtcNow, "some note"); var mock = new Mock <IPortfolioStorage>(); mock.Setup(s => s.GetOwnedOptions(User.Id)) .ReturnsAsync(new[] { opt }); mock.Setup(s => s.GetOwnedOption(opt.Id, User.Id)) .ReturnsAsync(opt); return(mock.Object, opt); }