Why is my price consistently decreasing in my code?

0
9
Asked By CuriousCoder92 On

I'm working on a Python program that generates a price based on random movements, but I'm noticing that the price often ends up smaller than expected. In my code, I use a random factor to determine whether the price should go up or down, but it seems like it's stuck on decreasing. Can anyone help me understand why this happens and how to fix it? I'm particularly confused about how I'm manipulating the variable 'x' and how that affects the price calculation. Any tips would be appreciated!

3 Answers

Answered By CodeNinja45 On

I think the issue might be the section where you do `x *= -1`. When 'x' is negative and you multiply by -1, it becomes positive, but in some cases, it may lead to values greater than expected, leading to unexpected price changes. You might want to add a check to keep 'x' within a certain range.

Answered By RandomDev123 On

If you're looking for more stable behavior, consider adjusting how much 'x' can influence the price change. Right now, that random factor can swing pretty wildly, leading to large decreases. Maybe limit it to a function that keeps changes more gradual.

Answered By TechGuru77 On

It looks like the variable 'x' has some tricky calculations. When you have `x = -1 + (-math.log(1 - random.random())) * 0.1`, if 'x' falls below zero, you end up with negative values after multiplying with 'Price'. This could be why your new price is decreasing. Try ensuring 'x' is always positive before doing the price calculation.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.