Exemple #1
0
        public void Deploy(string ownerPrivteKey, string nodeUrl)
        {
            _account = new Account(ownerPrivteKey);
            _web3    = new Web3(_account, nodeUrl);

            _contractInfo = GetContractInfo();

            if (contractAddress == string.Empty)
            {
                var senderAddress   = _account.Address;
                var transactionHash = _web3.Eth.DeployContract.SendRequestAsync(_contractInfo.GetAbi(), _contractInfo.ByteCode, senderAddress, DefaultGas, new object[] { }).GetAwaiter().GetResult();

                var receipt = _web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).GetAwaiter().GetResult();
                while (receipt == null)
                {
                    Thread.Sleep(1000);
                    receipt = _web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).GetAwaiter().GetResult();
                }

                contractAddress = receipt.ContractAddress;
                CreateGame(GameMove.Rock, GameMove.Rock, GameMove.Rock);
                CreateGame(GameMove.Rock, GameMove.Rock, GameMove.Rock);
                CreateGame(GameMove.Rock, GameMove.Rock, GameMove.Rock);
                CreateGame(GameMove.Rock, GameMove.Rock, GameMove.Rock);
                CreateGame(GameMove.Rock, GameMove.Rock, GameMove.Rock);

                CreateGame(GameMove.Paper, GameMove.Scissors, GameMove.Paper);
                CreateGame(GameMove.Scissors, GameMove.Paper, GameMove.Scissors);

                AcceptGame(0, GameMove.Paper, GameMove.Rock, GameMove.Rock);
                var res = GetCompletedByIndex(0);
            }
        }
Exemple #2
0
        public static double GetPortfolioRiskFromCovMatrix(DataTable positionTable, DataTable covMatrix)
        {
            double portfolioStd = 0;

            DataRow[] positionRows = positionTable.Select("Qty<>0");

            if (positionRows.Length > 0)
            {
                for (int i = 0; i < positionRows.Length; i++)
                {
                    string    tickerI     = positionRows[i].Field <string>("FullTicker");
                    string    tickerheadI = ContractMetaInfo.GetContractSpecs(tickerI).tickerHead;
                    DataRow[] covRows     = covMatrix.Select("index='" + tickerheadI + "'");

                    portfolioStd = portfolioStd + covRows[0].Field <double>(tickerheadI) * Math.Pow(positionRows[i].Field <double>("Qty"), 2);

                    for (int j = i + 1; j < positionRows.Length; j++)
                    {
                        string tickerJ     = positionRows[j].Field <string>("FullTicker");
                        string tickerheadJ = ContractMetaInfo.GetContractSpecs(tickerJ).tickerHead;
                        portfolioStd = portfolioStd + 2 * covRows[0].Field <double>(tickerheadJ) *
                                       positionRows[i].Field <double>("Qty") * positionRows[j].Field <double>("Qty");
                    }
                }
            }
            return(Math.Sqrt(portfolioStd));
        }
Exemple #3
0
        public static double GetStd4Ticker(string fullTicker, DataTable covMatrix)
        {
            string TickerHead = ContractMetaInfo.GetContractSpecs(fullTicker).tickerHead;

            DataRow[] covRows = covMatrix.Select("index='" + TickerHead + "'");
            return(Math.Sqrt(covRows[0].Field <double>(TickerHead)));
        }
        public void Deploy(string ownerPrivteKey, string nodeUrl)
        {
            _account = new Account(ownerPrivteKey);
            _web3    = new Web3(_account, nodeUrl);

            _contractInfo = GetContractInfo();

            if (contractAddress == string.Empty)
            {
                var senderAddress   = _account.Address;
                var transactionHash = _web3.Eth.DeployContract.SendRequestAsync(_contractInfo.GetAbi(), _contractInfo.ByteCode, senderAddress, DefaultGas, new object[] { }).GetAwaiter().GetResult();

                var receipt = _web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).GetAwaiter().GetResult();
                while (receipt == null)
                {
                    Thread.Sleep(1000);
                    receipt = _web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).GetAwaiter().GetResult();
                }

                contractAddress = receipt.ContractAddress;
                AddNewProduct("Cheese 1kg", 50, 100);
                AddNewProduct("iPhone XX", 1500, 10);
                AddNewProduct("Smart TV", 1000, 10);
                AddNewProduct("Toilet paper", 20, 1000);
                AddNewProduct("Product 10", 20, 500);
            }
        }
Exemple #5
0
        public static double GetChangeInRiskAfterTickerInclusion(DataTable positionTable, DataTable covMatrix, string ticker2Include, double qty)
        {
            string TickerHead = ContractMetaInfo.GetContractSpecs(ticker2Include).tickerHead;

            DataRow[] covRows            = covMatrix.Select("index='" + TickerHead + "'");
            DataRow[] positionRows       = positionTable.Select("Qty<>0");
            double    portfolioVarChange = covRows[0].Field <double>(TickerHead) * Math.Pow(qty, 2);

            for (int i = 0; i < positionRows.Length; i++)
            {
                string TickerI     = positionRows[i].Field <string>("FullTicker");
                string TickerHeadI = ContractMetaInfo.GetContractSpecs(TickerI).tickerHead;
                portfolioVarChange = portfolioVarChange + 2 * covRows[0].Field <double>(TickerHeadI) *
                                     positionRows[i].Field <double>("Qty") * qty;
            }
            return(portfolioVarChange);
        }