additional graphs
This commit is contained in:
parent
c5643b1516
commit
a2dc8a3c5e
1 changed files with 10 additions and 5 deletions
15
crypto.py
15
crypto.py
|
@ -2,18 +2,21 @@ import random
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
# Game parameters
|
# Game parameters
|
||||||
# Start price of coin
|
|
||||||
coin_price = 100.0
|
coin_price = 100.0
|
||||||
price_sensitivity = 0.5
|
price_sensitivity = 0.5
|
||||||
volatility = 0.3
|
volatility = 0.3
|
||||||
price_history = [coin_price]
|
price_history = [coin_price]
|
||||||
|
trade_history = [0] # User's buy/sell behavior per turn
|
||||||
|
cumulative_trades = [0] # Net amount of coins user holds over time
|
||||||
|
|
||||||
def save_graph():
|
def save_graph():
|
||||||
plt.clf()
|
plt.clf()
|
||||||
plt.plot(price_history, label="Coin Price")
|
plt.plot(price_history, label="Coin Price", color='blue')
|
||||||
plt.title("Coin Price Over Time")
|
plt.plot(trade_history, label="Trade Behavior", color='orange')
|
||||||
|
plt.plot(cumulative_trades, label="Net Coins Held", color='green')
|
||||||
|
plt.title("Coin Price, Trade Behavior & Net Holdings Over Time")
|
||||||
plt.xlabel("Turn")
|
plt.xlabel("Turn")
|
||||||
plt.ylabel("Price")
|
plt.ylabel("Value")
|
||||||
plt.legend()
|
plt.legend()
|
||||||
plt.grid(True)
|
plt.grid(True)
|
||||||
plt.savefig("coin_price.png")
|
plt.savefig("coin_price.png")
|
||||||
|
@ -36,7 +39,9 @@ while True:
|
||||||
print("⚠️ Please enter a valid number like +10 or -5.")
|
print("⚠️ Please enter a valid number like +10 or -5.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
user_intput = 10
|
trade_history.append(trade_amount)
|
||||||
|
new_total = cumulative_trades[-1] + trade_amount
|
||||||
|
cumulative_trades.append(new_total)
|
||||||
|
|
||||||
buys = trade_amount if trade_amount > 0 else 0
|
buys = trade_amount if trade_amount > 0 else 0
|
||||||
sells = -trade_amount if trade_amount < 0 else 0
|
sells = -trade_amount if trade_amount < 0 else 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue