{"id":26578832,"url":"https://github.com/pprunty/sde_methods","last_synced_at":"2025-03-23T05:17:14.199Z","repository":{"id":168300402,"uuid":"457947284","full_name":"pprunty/sde_methods","owner":"pprunty","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-23T23:43:05.000Z","size":722,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-11-24T00:27:59.691Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pprunty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-02-10T21:05:43.000Z","updated_at":"2022-02-10T21:06:04.000Z","dependencies_parsed_at":"2023-11-24T00:27:21.770Z","dependency_job_id":"0b4ba304-e713-4f7d-b6e3-4b4b23b8b4ff","html_url":"https://github.com/pprunty/sde_methods","commit_stats":null,"previous_names":["pprunty/sde_methods"],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pprunty%2Fsde_methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pprunty%2Fsde_methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pprunty%2Fsde_methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pprunty%2Fsde_methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pprunty","download_url":"https://codeload.github.com/pprunty/sde_methods/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245056898,"owners_count":20553856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-23T05:17:13.502Z","updated_at":"2025-03-23T05:17:14.190Z","avatar_url":"https://github.com/pprunty.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Part of a college assignment...\n\n# SDE Methods\nThis program compares two discretisation schemes, Euler-Maruyama and Milstein, with the exact solution for GBM. The \nstochastic differential equations (S.D.Es) are solved using Monte Carlo simulation.\n\n\n![Screenshot](graphics/SDE_time_1_timesteps_10.png)\n\n## Contents\n\n1. [Overview](#overview)\n2. [Requirements](#requirements)\n3. [Compilation and Usage](#compilation-and-usage)\n4. [Known Issues](#known-issues)\n\n## Overview\n\nGiven a Stochastic Differential Equation (SDE) of the form:\n\n![Screenshot](graphics/Eq.1.png)\n\nwhere W is a Wiener process. We can do an Itˆo-Taylor expansion of Eq. 1 to various orders in order to obtain a discrete\napproximation of the dynanmics. The first order expansion gives us the Euler-Maruyama Scheme:\n\n![Screenshot](graphics/Eq.2.png)\n\nThe Euler-Maruyama method has error O(∆t). If we add the next order term\nin the expansion we get the Milstein Scheme:\n\n![Screenshot](graphics/Eq.3.png)\n\nThe Milstein method has error O(∆t2).\n\nUnder the assumption of Geometric Brownian Motion, Eq. 1 becomes:\n\n![Screenshot](graphics/Eq.4.png)\n\nand the Euler-Maruyama scheme becomes:\n\n![Screenshot](graphics/Eq.5.png)\n\nwith z ∼ N(0,1) is a standard normal random variate. The Milstein scheme becomes:\n\n![Screenshot](graphics/Eq.6.png)\n\nHowever we can also integrate up Eq. 4 to obtain the exact scheme:\n\n![Screenshot](graphics/Eq.7.png)\n\nThis program compares Eq. 5, Eq. 6 and Eq. 7.\n\nThe program also makes exercises good practical use of smart pointers, polymorphism, random number generation and \nvalarrays.\n\nIn particular, a std::vector\u003cstd::valarray\u003cdouble\u003e\u003e prices_ is used effectively to perform N * num_timestep simulations\nof the stock price as it moves through time. This is because the std::valarray allows for BLAS like operations such as (*)\nwhich multiplies all of its elements by a given number. This fits in nicely with our equation as we move through time.\n\n![Screenshot](graphics/monte_carlo_simulation.png)\n\n## Requirements\n\n- gcc\n- gnuplot (if you would like to produce graphics)\n\n## Compilation and Usage\n\nTo compile the code simply run the following command inside a terminal in the project directory:\n\n```shell\nmake\n```\n\nTo run the program, simply run the following command inside a terminal in the project directory:\n\n```shell\n./sde_methods\n```\n\nTo produce graphics, run the following commands inside the gnuplot terminal in the project directory:\n\n```shell\nset grid ytics lt 0 lw 1 lc rgb \"#bbbbbb\"\nset grid xtics lt 0 lw 1 lc rgb \"#bbbbbb\"\nset title \"Distribution at T = 1 for 10 timesteps\"\nset samples 50 # Adjust this at your own leisure\nplot 'EX_time_1_timesteps_10.txt'  w l t \"Exact Scheme\", 'EM_time_1_timesteps_10.txt' smooth csplines w l t \"\nEuler-Maruyama\", 'M_time_1_timesteps_10.txt' smooth csplines w l t 'Milstein'\n```\n\nNote: I know I can add this to the Makefile as 'make plot' but I prefer to leave the commands here so I can return to them.\n\n## Results\n\nThe following are the results for t = 1 and 10 timesteps:\n\n```shell\nConstructor for 100000 Gaussian variates constructing.\nCreating vector with Mersenne Twister state-size [312].\nExact_path constructor constructing.\nExact_path destructor\nSimulation destructor\nConstructor for Milstein scheme constructing.\nMilstein destructor\nSimulation destructor\nConstructor for Euler-Maruyama scheme constructing.\nEuler-Maruyama destructor\nSimulation destructor\n\nWriting results to file: EX_time_1_timesteps_10.txt\nWriting results to file: M_time_1_timesteps_10.txt\nWriting results to file: EM_time_1_timesteps_10.txt\n\nExpected value Exact: 104.932\nVariance Exact: 433.293\n\n\nExpected value Milstein: 104.92\nVariance Exact Milstein: 428.817\n\n\nExpected value Euler-Maruyama: 104.92\nVariance Exact Euler-Maruyama: 428.353\n\nWriting results to file: EX_time_1_log_rets_at_timestep10.txt\n\nExpected Exact log returns: 0.0288267\nVariance Exact log returns: 0.038675\n\nEuler-Maruyama destructor\nSimulation destructor\nMilstein destructor\nSimulation destructor\nExact_path destructor\nSimulation destructor\n\n```\n\n\n## Known Issues\n\nNone at present.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpprunty%2Fsde_methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpprunty%2Fsde_methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpprunty%2Fsde_methods/lists"}