public void EventCstrReplays()
        {
            var opt = GetTestOption(_expiration);

            var opt2 = new OwnedOption(opt.Events);

            Assert.Equal(opt.State.Expiration, opt2.State.Expiration);
            Assert.Equal(opt.State.Id, opt2.State.Id);
            Assert.Equal(opt.State.Ticker, opt2.State.Ticker);
            Assert.Equal(opt.State.OptionType, opt.State.OptionType);
        }
Beispiel #2
0
 public ReviewEntry(OwnedOption o)
 {
     Created     = null;
     Ticker      = o.Ticker;
     Description = o.Description;
     Expiration  = o.Expiration;
     IsExpired   = o.IsExpired;
     ExpiresSoon = o.ExpiresSoon;
     DaysLeft    = o.DaysLeft;
     Stats       = null;
     Price       = new TickerPrice();
     IsOption    = true;
     IsNote      = false;
 }
        private static OwnedOption GetTestOption(
            DateTimeOffset expiration,
            string ticker         = "TEUM",
            OptionType optionType = OptionType.PUT,
            double strikePrice    = 2.5)
        {
            var option = new OwnedOption(
                ticker,
                strikePrice,
                optionType,
                expiration,
                Guid.NewGuid());

            return(option);
        }
Beispiel #4
0
 public static object ToOptionView(OwnedOption o, TickerPrice currentPrice)
 {
     return(new
     {
         id = o.State.Id,
         ticker = o.State.Ticker,
         currentPrice = currentPrice.Amount,
         optionType = o.State.OptionType.ToString(),
         strikePrice = o.State.StrikePrice,
         premium = o.State.Credit - o.State.Debit,
         expirationDate = o.State.Expiration.ToString("yyyy-MM-dd"),
         numberOfContracts = Math.Abs(o.State.NumberOfContracts),
         boughtOrSold = o.State.NumberOfContracts > 0 ? "Bought" : "Sold",
         transactions = new TransactionList(o.State.Transactions, null, null),
         expiresSoon = o.ExpiresSoon,
         isExpired = o.IsExpired
     });
 }
 public EmailReviewEntry(OwnedOption o)
 {
     Created     = null;
     Ticker      = o.State.Ticker;
     Description = $"{Math.Abs(o.State.NumberOfContracts)} ${o.State.StrikePrice} {o.State.OptionType} contracts";
     OptionType  = o.State.OptionType;
     Expiration  = o.State.Expiration;
     IsExpired   = o.State.IsExpired;
     ExpiresSoon = o.State.ExpiresSoon;
     DaysLeft    = o.State.DaysLeft;
     Stats       = null;
     IsOption    = true;
     IsAlert     = false;
     AverageCost = 0;
     OptionType  = o.State.OptionType;
     StrikePrice = o.State.StrikePrice;
     PricePoints = new List <AlertPricePoint>();
 }
        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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
        public async Task OwnedOption_WorksAsync()
        {
            var expiration = DateTimeOffset.UtcNow.AddDays(30).Date;

            var option = new OwnedOption(
                GenerateTestTicker(),
                2.5,
                OptionType.CALL,
                expiration,
                _userId
                );

            var storage = CreateStorage();

            await storage.Save(option, _userId);

            var loaded = await storage.GetOwnedOption(
                option.State.Id,
                _userId);

            Assert.NotNull(loaded);

            Assert.Equal(option.State.StrikePrice, loaded.State.StrikePrice);

            var list = await storage.GetOwnedOptions(_userId);

            var fromList = list.Single(o => o.State.Ticker == option.State.Ticker);

            Assert.Equal(option.State.StrikePrice, fromList.State.StrikePrice);

            await storage.Delete(_userId);

            var afterDelete = await storage.GetOwnedOptions(_userId);

            Assert.Empty(afterDelete);
        }
Beispiel #12
0
 public Task Save(OwnedOption option, Guid userId)
 {
     return(Save(option, _option_entity, userId));
 }
        public Task Save(OwnedOption option, Guid userId)
        {
            _options[option.State.Id.ToString()] = option;

            return(Task.CompletedTask);
        }
 internal void Register(OwnedOption opt)
 {
     _options.Add(opt.State.Id.ToString(), opt);
 }