mento-protocol / simulation

Apache License 2.0
1 stars 1 forks source link

Simulate Uncorrelated Paths with Separate Path Generator Instead of Multivariate Path Generator #131

Closed bowd closed 2 years ago

bowd commented 2 years ago

"python\r\ndef generate_uncorrelated_paths(self):\r\n sequence_generator = UniformRandomSequenceGenerator(\r\n len(time_grid), UniformRandomGenerator())\r\n gaussian_sequence_generator = GaussianRandomSequenceGenerator(\r\n sequence_generator)\r\n maturity = time_grid[len(time_grid) - 1]\r\n path_generator = GaussianPathGenerator(\r\n process, maturity, len(time_grid), gaussian_sequence_generator, False)\r\n paths = np.zeros(shape=(number_of_paths, len(time_grid)))\r\n for path_index in range(number_of_paths):\r\n path = path_generator.next().value()\r\n paths[path_index, :] = np.array(\r\n [path[j] for j in range(len(time_grid))])\r\n\r\n log_returns = np.diff(np.log(paths[0]))\r\n # the current setup does only support simulation of processes with independent\r\n # increments or processes without if the value is not changed in other sub-steps\r\n increments = {}\r\n for asset, path in list(zip(self.processes, log_returns)):\r\n increments[asset] = path\r\n\r\n return increments\r\n\r\n def switcher(self, params):\r\n if (np.array(params['correlation']) -\r\n np.diag(np.ones(len(params['correlation'])))\r\n == np.zeros(np.array(params['correlation']).shape)).all():\r\n process = self.process_container(params=params)\r\n else:\r\n process = None\r\n return process\r\n\r\n\r\n"