[Script] Estimate the odds of hitting a price, like 100k :)

16 replies 304 views
chris.altHero Member
Posts: 458 · Reputation: 2287
#1Jun 19, 2022, 08:46 PM
Ever wondered how likely it is for Bitcoin to hit 100,000 USD before 2025, or maybe even 200,000 before 2026? I've put together a Python script that lets you calculate this probability based on past price movements. You can pick a time frame from the past that you think resembles the current market conditions. A lot of folks believe we're in a mid-bull market, so years like 2016/17 or 2020/21 are interesting to consider. Here’s how the script works. It analyzes the percentage changes in Bitcoin's price during your selected period, and each change gets assigned an equal probability. For instance, if you choose 2016/17, it’ll look at daily changes from January 1, 2016, to December 31, 2017, which is a total of 730 days (2 years). Each of those daily changes carries a probability of 1 out of 730. You’ll then specify how many days you want to simulate. For example, from now until January 1, 2025, there are 60 days (as of November 2). You also need to input the current Bitcoin price, let’s say $69,500. The script will randomly apply one of the daily changes from the historical data and do this as many times as the number of days you set. If it hits the target price during those simulations, it counts it. At the end, you'll see how many times the target price was reached out of the total simulations. I got this idea from a thread here, but it was closed while we were still discussing the script. So I figured I'd start a new one just for it. Some notable posts from that other thread include this one, this one, and especially this one by user @DirtyKeyboard.
8 Reply Quote Share
wizard777Member
Posts: 6 · Reputation: 95
#2Jun 20, 2022, 02:15 AM
Nice.  I'm working on a little script to keep that pastebin file updated, and I added some graphing. I figured I would run till the end of this year, using the end of last year's data.  Enter start date (YYYY-MM-DD): 2023-11-03 Enter end date (YYYY-MM-DD): 2023-12-31 Number of days to simulate: 58 Starting price: 68442 Number of simulations: 100 Interesting spread.  It ends in profit, but that bottom blue series doesn't look like fun.
5 Reply Quote Share
chris.altHero Member
Posts: 458 · Reputation: 2287
#3Jun 20, 2022, 05:37 AM
I've tried your script with the graph plotting now and it works awesome I've adapted it a bit so it can be used with command line parameters, like my original script. Is it okay for you if I publish it here? (Otherwise I'll adapt my own script adding the CSV saving and plotting parts.) Now as we already saw a new all time high I fed the script with a $75000 starting price. Some scenarios based on the whole last bull market (2019-01-01 to 2021-12-31) [1]: - 35% for 100000 until the end of the year - 60% for 100000 in 100 days - 93% for 100000 in 365 days - 53% for 200000 in 365 days Unfortunately talkimg.com doesn't work for me at the moment, so I couldn't upload the pics I've also modified the script so it also can calculate the probability of crashes (i.e. the price falling below a certain threshold). This could be used to do some hedging. For an example run, I used the same data and calculated the probability to crash to 50.000 until the end of the year. The probability was only of 3,1% which looks fine Even 60000 is not really likely, with 16%. [1] I think the timeframe you chose in your last post is too short, as it is only a single small leg of a bull market, and also an extremely bullish one. As we don't know in which stage of the bull market we are, I thus chose the last entire bull market, including the crashes near the start and near the end.
1 Reply Quote Share
wizard777Member
Posts: 6 · Reputation: 95
#4Jun 20, 2022, 09:35 AM
I know, I know, you're all saying, "Why didn't you use the end of the year from 4 years ago?"  Good question.  I think.  Anyway, this is all for fun speculation.   Enter start date (YYYY-MM-DD): 2020-11-07 Enter end date (YYYY-MM-DD): 2020-12-31 Number of days to simulate: 54 Starting price: 74057 Number of simulations: 10000 Number of simulations reaching $100,000 or more: 9592 Probability of reaching $100,000 or more: 95.92% Wow!  Who got in early?  Like, as in yesterday early?   Here is the AI teamwork makes the LLM dream work script.   I'm more of a terminal input person, but mix and match as you like.  I added a histogram too.  I think the auto format would work with less spread in the results.  With the small time frame, I was just trying to have fun matching the days 1:1 EDITED:  Thanks and if the pictures loaded, I heard imgBB is working.  I might have also fixed the auto scaling.
3 Reply Quote Share
chris.altHero Member
Posts: 458 · Reputation: 2287
#5Jun 20, 2022, 05:58 PM
Thanks for the histogram function, looks awesome I have now expanded the script with some command line options, the graph and histogram functions and the ability to save the file to CSV. The CSV format of my script is however simpler than the one in yours: It stores each simulation as a separate row, this looks more spreadsheet-friendly to me, if someone wants to import the data into Excel, Calc etc.. Two known little problems, I hope to solve them soon: - histogram function creates two figures instead of one - if the graph is shown, then it is not stored correctly (it seems the plot is blanked out). So I added a "--show" option, currently you can only either store the graph or show it. See the Usage section in the script for the command line options.
4 Reply Quote Share
wizard777Member
Posts: 6 · Reputation: 95
#6Jun 20, 2022, 10:25 PM
I'd like to add a new approach.  You know how they say past performance doesn't dictate future results.  What if they're wrong?   Here is a script that asks how many days in the past, from today, you want to match the % change of BTC volume weighted average price since 2012.  Then use that to predict the future. Step 1: go through the date range, and looking for a sequence of past_percent_changes that best matches the recent_percent_changes. Step 2: put the lists side by side and add the delta between each day in the sequence and use the sum of the deltas as a closeness ranking Step 3: move one day forward and look at the new closeness ranking of that past_percent_changes against the recent_percent_changes.   Step 4: using the best matching past day's result dates, look at what happend next (in the past).   Step 5: apply those next past percent changes to today's starting price sequentially to see what might happen in the future.   So, for example, the best match for the past week is from 2023-06-18 to 2023-06-25, so what happened from the 26th on for the next 7 days? The Close score is the sum of the differences in the percent changes divided by the number of days chosen to match.   Close score: (0.79538) Range start date: 2023-06-18 Close score: (0.79579) Range start date: 2021-09-28 Close score: (0.88344) Range start date: 2023-01-18 Close score: (0.95793) Range start date: 2020-04-20 Close score: (0.96967) Range start date: 2020-04-03 Close score: (1.31444) Range start date: 2019-03-02 Close score: (1.38094) Range start date: 2012-04-29 Close score: (1.38704) Range start date: 2016-08-03 Close score: (1.38887) Range start date: 2023-09-28 Close score: (1.39045) Range start date: 2016-03-06 I think these graphs are say, "Don't get scared next week, hold on for longer term profits!" Things got a bit messy trying to put everything on one graph.     Edit: I can't seem to figure out why this script fails when the days are more than somewhere around 250.  The script doesn't fail, it just doesn't output enough predicted_prices.  It's so frunstrating...er fun and frustrating, that I can't find where things are going sideways.  Any help?  For example Close score: (1.86067) Range start date: 2023-03-17 Close score: (1.95362) Range start date: 2023-05-20 Close score: (1.95761) Range start date: 2023-03-25 Close score: (1.96330) Range start date: 2023-03-16 Close score: (1.98632) Range start date: 2023-03-18 Do you see where the red series ends early?  To clarify, it ends early because the csv file ends early, so why does that happen?
3 Reply Quote Share
chris.altHero Member
Posts: 458 · Reputation: 2287
#7Jun 21, 2022, 03:34 AM
That's a quite different approach, but nevertheless interesting It is already not so much a probability-based prediction, but a prediction by similarity. It's a bit like these Wall Observer users and "TA specialists" pasting an old chart into a new chart It would be more close to a probability based simulation if you took the 100 most similar price performances instead of only 5, and simulated based on them. I'll see if I can play around a bit with that. Another idea would be to try to find Elliott wave-style movements - basically look for similarities in the the more long-term movements of a moving average like SMA or EMA. I've looked at it and it's always the same series, only shift by some days, and it's actually the last days of the price data (this is why the price row ends, as you probably already found out if I interpret your last sentence correctly). So it seems that despite of the days that are "missing", these are still the most similar price series. This means that other series are probably not similar at all. (no, this seems not to be the case, see below) I have found out that the last part of the algorithm (after the closeness rankings are calculated) seems not to work correctly, because if I list the most close price patterns (for 300 days) manually, I get dates from 2023, 2016 and 2022 (in this order by frequency), and these are not "cut off" by the limit date of the CSV file (in my case in October 2024). For those wanting to copy the script it may also important to add that the original CSV pastebin has the column names "Price" (col 1) and "Date" (column 2), instead of "Column 1 Name" and "Column 2 Name", so you must replace these items. The "paperclip" module can also imo be left out as this is not part of the standard Python library and not needed for the simulations. Just comment out the last line (or the last 3 if you don't need the "comment" part).
3 Reply Quote Share
wizard777Member
Posts: 6 · Reputation: 95
#8Jun 21, 2022, 06:17 AM
Thanks.  Thank you for looking at it.    Here's a lot cleaner version with the correct headers, and using home directory filenames.  It only attempts 1 graph.  Still haven't found why it goes haywire with more than around 250 days.   Here's that pastebin link again with the historical volume weighted average prices.  I've fixed the linked paste, but while looking for anything that could be going wrong, I found duplicate entries for 63554.119868161404,2024-09-23.  So that should be fixed with any local copies.   https://pastebin.com/3C67XqKW I used a while loop to run multiple runs for every range of dates that have a close score average of less than 2.  That means that for each pair of dates in the present and past ranges, the percent change from day to day differs by an average of less than 2% points.  Like if the 2nd day in the past range was a -1% change, and the present range was a +1% change, that is a close score of 2 for that day. I figured out we could test this model so I set the range to be from 2012-01-01 to 2024-10-11 and asked it for 30 days of matching(or close to) % change day to day going back from October 11th, to predict prices up to today. .. .. I coulda called the spike to 80k!   Edit: So what about the next 30 days? $100k here we come!
3 Reply Quote Share
chris.altHero Member
Posts: 458 · Reputation: 2287
#9Jun 21, 2022, 03:43 PM
I think I found the problem, but still am looking how to solve it. The problem is this line: If I chose 300 days and the second_best_index is too close to the present date, then second_best_index + 300 + 300 will return a number outside of the DataFrame, so the returned series will be shortened. For example, I get the following dates for first three rankings: - 2023-04-12 - 2023-04-25 - 2023-02-07 The limit of my original CSV file is 2024-10-26. 2023-04-12 + 600 days is: 2024-12-02 2023-04-25 + 600 days is: 2024-12-15 2023-02-07 + 600 days is: 2024-09-29 So only for the third rank the complete 300 days series will be taken, and I can confirm it from the graph. The problem is thus, that the script searches for this timeframe in the current DataFrame, instead of appending more days to the DataFrame. I think I found the fix. Simply delete the line I mentioned above (or comment it out) and replace all instances of the variable next_percent_changes with past_changes. I get the following image in this case (expanded it to 7, because the first six are quite close but the seventh is from 2016):
2 Reply Quote Share
chris.altHero Member
Posts: 458 · Reputation: 2287
#10Jun 22, 2022, 03:56 PM
I made actually a mistake in my last post. The script behaved correctly, however if you project data 300 days in the future for example, and the start date is less than 300 days before the last date in the CSV file, then of course it will project less than 300 days into the future I've made some more improvements to the "similarity" script, but still one part of your last version is missing. The improvements include: first, you can select how many days you want to project into the future. This number in the previous script was always equal to the length of the timeframe you compared to the past changes. Second, you can choose the script to ignore values which are too close together, which was a problem in the last version where a lot of 2023 values were very close. A third improvement: the startdate of each similar timeframe is shown in the chart. - takes arguments -d, --diverse and -n - -d are the days to calculate (if you want the input method, just uncomment the commented line) - --diverse ensures that the dates aren't too close together. The div_days variable (default: 60 days) defines the minimum distance between two of the predictions. - -n is the length of the prediction. In the original script, the prediction is The commented pyperclip part is for the "post" feature and can of course also be uncommented if needed. Some images: Best similarity matches for 300 days, projected 90 days into the future: 300 days, but with the --diversity argument (no dates closer than 60 days together): Interesting that most are uber bullish, but there's always a bearish option. Edited: There were different images and a slightly different script in an earlier version of this post. The script contained a bug but now it should work fine.
2 Reply Quote Share
chris.altHero Member
Posts: 458 · Reputation: 2287
#11Jun 22, 2022, 04:14 PM
Now that we've seen the first serious dip after last year's pump, I have again made some simulations. The scripts are unchanged (compared to last year). I want to thank @DirtyKeyboard seems to still update the CSV data regularly! 1. Probability by similarity: Here we see the most similar price movements recorded to the past, and how the price evolved after that -- projected to the current price. Interestingly, all similar dates are from 2016. We see that in the past when similar movements were recorded, the price always seems to have recovered, and despite of the dip all variants close above 100.000$ in 90 days 2. Original approach: Probability to close above 100.000 in the next 90 days (based on data from the last full cycle, i.e. 2018-22), taking 83000$ as base (yesterday near the average price): 60,5% The individual simulations can be seen in these graphs: The most bearish variant still predicts more than 33.000$, and the most bullish over 265.000$, with most simulations closing near or above 100.000$. [1] Doesn't look that bad [1] Interestingly, the maximum of the histogram is actually close to the current price (80-90k area). It seems though that the accumulated frequency of closing prices over 100.000 is much higher. While there are some slightly bearish to sideways scenarios, the probability of a real crash down to 50k or lower is seen as very low.
6 Reply Quote Share
wizard777Member
Posts: 6 · Reputation: 95
#12Jun 22, 2022, 04:48 PM
Looking good!  So hard to account for all the variables.    But, I was wondering on the #2 approach graphs, what the histogram would look like, if the title was "Histogram of Sims by Max Price per Run" instead of on the last day?  I ask because I was considering trying a script that wouldn't trade automatically, but might help one to set their buy/sell ladders.
2 Reply Quote Share
chris.altHero Member
Posts: 458 · Reputation: 2287
#13Jun 22, 2022, 07:43 PM
The original script actually does this, only the histogram variant used the last price. I changed the script now to include a --max option for the histogram, and fed it with the following data: - Start price: 85000 - End price (to reach): 100000 - Days: 30 - Time interval: 2018 to 2021 (last full 4-year cycle) The probability to be surpassed was 35.95 % for 10000 simulations. The histograms obviously look very different: for the --max option, of course no price went to less than the start price (85000), as the first day is of course part of the row Using the last price: Using the max price: Title of the histogram graph has still not been changed so it's currently misleading (in the second graph it should be "based on Max Price" instead of "by price at Last Day"). (Edit: This was fixed.) I'll make some more modifications to the script soon as I got some new ideas, for example the probability for the last price to reach the end price would also be interesting. Code:
2 Reply Quote Share
t0m2020Senior Member
Posts: 171 · Reputation: 1044
#14Jun 23, 2022, 12:06 AM
A little over my head, as things tend to do more often these days but nevertheless, cool beans. Methinks someone should run the numbers through a bot to try and see actual results. Maybe even on a weaker currency (ringgit, baht maybe?) to rack up them zeroes. A few years ago with more time on my hand I would just feed the numbers into the Bitcoin Up or Down games casinos now have (oh except the edge is so high so boo). That would be the simplest test of this no?
6 Reply Quote Share
chris.altHero Member
Posts: 458 · Reputation: 2287
#15Jun 23, 2022, 12:32 AM
I have fed the scripts with new data. First the question: Will there be a new ATH in the next 14 days, starting from 106,000$? The script returns a 66% probability that yes, i.e. that it will reach 110,000 (and we have already seen 107k). Second question: Will the price reach $130,000 in 90 days? This looks like a reasonable next step. Script says: 56,73% probability with 10,000 simulations. Histogram for the last price: Looks very slightly bearish at a first glance because the maximum of the last price is about 100k. But this would mean that it's possible that a new ATH is achieved before. Histogram for the max price: As I think I already mentioned, the lowest bar is the highest because the max price can't be below the start price, so this bar shows all completely bearish simulations (those never reaching more than the starting price), which are only ~600 from 10000. Graphs for 100 simulations: I also am currently experimenting with additional parameters to adjust volatility. As we're experiencing a declining volatility over the last years, it's possible that the data of the simulation exaggerates the possible volatility, so a knob to adjust it imo makes sense. Oh, I totally oversaw this answer: I guess that would be an interesting experiment. Simply betting to "up or down" however would lose information, I think. You could however of course allocate long and short positions and closing them according to the simulations' outcome. For example, if there are 60% bullish outcomes, buy 60 units of BTC (long) and at the same price short-sell 40 units (short), setting the sell / re-buy price at the maximum or minimum price the simulation gave. Example with 2 simulations (1 bullish and 1 bearish one): 106000, 107000, 108000, 105000, 106000, 112000, 114000, 107000 => buy at 106000 and sell at 114000 if this price is reached 106000, 107000, 103000, 99000, 95000, 99000, 102000 => short-sell at 106000, re-buy at 95000
0 Reply Quote Share
chris.altHero Member
Posts: 458 · Reputation: 2287
#16Jun 24, 2022, 01:53 PM
I have made some new simulations. I assumed that we are either in a big dip in the late bull market or in the early bear market. This means that the data row which matched best is 2021 to mid-2022, which includes both the big mid-2021 dip, the late bull in October/November 2021, and the trend change into the bear market. I've first asked it how high is the probility to reach 100,000$ in 90 days, with a start price of $68,000. The result was a devastating 17%. But at least it is not zero. (And 90 days is a quite short timeframe to "move on" from the 60k shock so strongly.) This is the result for 100 simulations (here it gave 11%): Then I made some simulations for 180 days, taking into account the whole years 2021 and 2022 (i.e. the whole late bull and the whole bear). First the bearish predictions. Probability to reach .... - 50,000: 57% - 40,000: 31% - 30,000: 10% - 20,000: 1.24% - 10,000: 0.03% ... which is quite consistent with some crystal ball owners predicting something between 38000 and 50000 as the "final bottom" (in reality, these data would point to 45-48k as the most likely bottom, but only if the bear market is exactly like in 2022, see below!). And now some bullish ones: - 80,000: 58% - 90,000: 40% - 100,000: 26% - 126,000: 9% => this means the likelihood of a new ATH before roughly August 2026. However, these numbers probably are more bearish than what's to be expected. Simply because volatility is reducing, and these simulations assume it is as high as 2021/22. This is not the case, we can expect a volatility reduction of ~30% at least. I want to thank @DirtyKeboard to update the data feed until September 2025. Great work
1 Reply Quote Share
wizard777Member
Posts: 6 · Reputation: 95
#17Jun 25, 2022, 01:54 AM
Hi, just peeking in you big bear, you better tweak that simulation a bit.     Just playin' and you're welcome for the data!  I can give you what I've got if you'd like, but I found this new source from nonakip and NastyMining that goes back even further. https://bitcointalk.org/index.php?topic=86854.0 https://nastyfans.org/exchangerate.csv
1 Reply Quote Share

Related topics