コード例 #1
0
        private DiscretePayoffs GetOutcomes(string[]?outcomes)
        {
            string optionName = "outcome";

            if (outcomes is null || outcomes.Length is 0)
            {
                throw new CommandOptionRequiredException(optionName);
            }
            DiscretePayoffs pnl = new DiscretePayoffs();

            for (int i = 0; i < outcomes.Length; i++)
            {
                var separator = outcomes[i].LastIndexOf(':');
                if (separator == -1)
                {
                    throw new CommandException(optionName, "Invalid outcome, the format should be \'outcome:reward\' where \'reward\' is in sats (\'1000 sats\') or in BTC (\'0.2\')");
                }
                var outcome = outcomes[i].Substring(0, separator);
                var reward  = outcomes[i].Substring(separator + 1);
                reward = reward.ToLowerInvariant().Trim();
                var   satsSeparator = reward.IndexOf("sats");
                Money rewardMoney   = Money.Zero;
                if (satsSeparator == -1)
                {
                    rewardMoney = Money.Parse(reward);
                }
                else
                {
                    rewardMoney = Money.Satoshis(long.Parse(reward.Substring(0, satsSeparator)));
                }
                pnl.Add(new DiscretePayoff(outcome, rewardMoney));
            }
            return(pnl);
        }
コード例 #2
0
ファイル: BitcoinSTests.cs プロジェクト: dgarage/NDLC
        public void CanConvertContractInfoToPayoff()
        {
            var payoffs = new DiscretePayoffs();

            payoffs.Add(new DiscreteOutcome("a"), Money.Coins(5.0m));
            payoffs.Add(new DiscreteOutcome("b"), Money.Coins(-5.0m));
            payoffs.Add(new DiscreteOutcome("c"), Money.Coins(-2.0m));
            Assert.Equal(Money.Coins(5.0m), payoffs.CalculateMinimumCollateral());
            var ci = payoffs.ToContractInfo(payoffs.CalculateMinimumCollateral());

            Assert.Equal(Money.Coins(10.0m), ci[0].Payout);
            Assert.Equal(Money.Coins(0m), ci[1].Payout);
            Assert.Equal(Money.Coins(3.0m), ci[2].Payout);

            payoffs = DiscretePayoffs.CreateFromContractInfo(ci, Money.Coins(5.0m));
            Assert.Equal(Money.Coins(5.0m), payoffs[0].Reward);
            Assert.Equal(Money.Coins(-5.0m), payoffs[1].Reward);
            Assert.Equal(Money.Coins(-2.0m), payoffs[2].Reward);
        }
コード例 #3
0
        public DiscretePayoffs ToDiscretePayoffs(ContractInfo[] contractInfo)
        {
            if (contractInfo is null || contractInfo.Length is 0)
            {
                throw new ArgumentException("contractInfo is required", nameof(contractInfo));
            }
            DiscretePayoffs payoffs = new DiscretePayoffs();

            foreach (var ci in contractInfo)
            {
                payoffs.Add(new DiscretePayoff(ci.Outcome, ci.Payout - TotalCollateral));
            }
            return(payoffs);
        }
コード例 #4
0
        private DiscretePayoffs CreatePayoffs(List <string> payoffs)
        {
            var result = new DiscretePayoffs();

            foreach (var payoff in payoffs)
            {
                if (!DiscretePayoff.TryParse(payoff, out var o) || o is null)
                {
                    throw new CommandException("payoff", "The payoff can't be parsed");
                }
                result.Add(o);
            }
            return(result);
        }