{"id":25244154,"url":"https://github.com/mrc/bilo","last_synced_at":"2026-07-04T07:32:43.438Z","repository":{"id":30248507,"uuid":"33799743","full_name":"mrc/bilo","owner":"mrc","description":"A simple calculator to find the maximum return on investment from historical price movements","archived":false,"fork":false,"pushed_at":"2015-04-12T02:08:30.000Z","size":104,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T20:44:14.733Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","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/mrc.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}},"created_at":"2015-04-12T02:08:07.000Z","updated_at":"2015-04-12T02:08:30.000Z","dependencies_parsed_at":"2022-07-31T08:08:04.497Z","dependency_job_id":null,"html_url":"https://github.com/mrc/bilo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mrc/bilo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrc%2Fbilo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrc%2Fbilo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrc%2Fbilo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrc%2Fbilo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrc","download_url":"https://codeload.github.com/mrc/bilo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrc%2Fbilo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35114172,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-04T02:00:05.987Z","response_time":113,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-02-12T01:17:51.479Z","updated_at":"2026-07-04T07:32:43.423Z","avatar_url":"https://github.com/mrc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Finding optimal investment\n==========================\nA simple calculator to find the maximum return on investment from\nhistorical price movements.\n\nRequires Python 2.6\n\nGoal\n====\nGiven an input list of price movements, provide the optimal dates to\nbuy and sell to maximise the return on investment.\n\n\nRunning\n=======\nThe main program \"find_optimal_return.py\" can be run via Python, or\n(on Unix/Linux/OSX) can be run directly like so:\n\n    % ./find_optimal_return.py\n\nIt reads the file \"prices.txt\" and writes to the file \"output.txt\",\nboth in the current working directory.\n\n\nRunning tests\n=============\nThe unit tests in t_return_optimiser.py can be run like so:\n\n    % python t_return_optimiser.py\n\n\nPerformance and implementation\n==============================\nAlgorithmically, this program performs in linear time using constant\nmemory. It accesses the file prices.txt in a linear sequence. Internally,\nit uses generators to avoid storing data.\n\nIt is implemented using some high level Python features such as\nregular expressions which would provide some low hanging fruit for\nfurther optimisation, but I would want to do some profiling with\nrepresentative data first.\n\nI have avoided putting all the logic into a class for its own sake; I\nuse a class (return_optimiser.BestReturn) simply as a data structure.\n\n\nBugs and assumptions\n====================\nIn the event of no available profit (because of no uptick in the\ndata), both the low and high dates written will be the start date,\nand the profit will be shown as \"0.0\".\n\nThe program does no explicit input validation. Python will perform\nsome (e.g. it will throw an exception if the input file does not\nexist, or if the movement is not convertible to float), but this\nmay not be sufficient (it depends on the reliability of whatever\ngenerates prices.txt, for instance).\n\nI have deliberately not validated dates; I assume that the generator\nof prices.txt generates correct format dates. This program has no\nconcept of a date and just treats the 2nd column of prices.txt as a\nstring. The big benefit here is the program is resilient in the face\nof a date format change (e.g. changing to a 4 digit year).\n\nThe output writes the profit field with only a single decimal place.\nThis minimises some issues with precision lost due to use of floating\npoint maths (e.g. 10% cannot be faithfully represented in binary\nfloating point).\n\nNot a bug: the single division in the program will never divide by zero\nbecause the only situation where that could happen is if the low price\nis 0, caused by a -100% movement, and in that case no subsequent\nupticks will cause a high price (and trigger the division) because\nmovement is expressed as a factor of price, and 0*x=0.\n\nFurther investment optimisation\n===============================\nAs it stands, the optimiser misses the case where there is more than\none equivalent return but with a narrower date range. This may or may\nnot be a worthwhile optimisation, depending on other investment\nopportunities and inflation etc., but all things being equal it would\nmake sense to invest for the shortest period.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrc%2Fbilo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrc%2Fbilo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrc%2Fbilo/lists"}