Question: Stock Market Simulator Objective: Develop a basic stock market simulator using Python. The simulator should facilitate users to buy / sell stocks, monitor their portfolio,

Stock Market Simulator
Objective: Develop a basic stock market simulator using
Python. The simulator should facilitate users to buy/sell
stocks, monitor their portfolio, and trace historical prices of a
set of stocks.
Specifications:
Stock Data Representation:
Use lists to store stock prices for multiple companies.
Utilize strings to represent stock names (e.g., "Apple", "Google").
Ensure that price[i] should match the stock named name[i].
File Processing with Python:
Use the open() function to read initial stock data from a file.
Each file line should include a stock name followed by its initial price.
Retain historical prices for the purpose of displaying trends.
User Portfolio:
Design lists to log the quantity of shares of each stock owned by the user and the
user's transaction history (buys/sells).
Menu System:
Implement a menu using Python's print function and input() for user prompts.
Options should cover:
Display stocks
Purchase stocks
Sell stocks
Observe portfolio
Save portfolio
Exit
Buying and Selling Stocks:
Formulate functions for stock transactions, incorporating checks for sufficient
user funds, updating user stock count, and recording transactions.
Mathematical Functions:
Develop functions to compute the net worth of the user's portfolio.
Create a simple random walk method to adjust stock prices after each user
transaction to emulate market variations. You may use the following:
Save User Portfolio:
Integrate functionality to preserve the user's portfolio and transaction logs in a
file for subsequent sessions.
Error Handling with Python:
Use try-except blocks to tackle potential user mistakes, such as inputting invalid
data or attempting to sell stocks not in their possession.
Sample Output -
Viewing Stocks (Option 1):
Buying Stocks (Option 2):
Selling Stocks (Option 3):
Viewing Portfolio (Option 4):
Saving Portfolio (Option 5):
Exiting (Option 6):Available Stocks:
Apple - $150
Google - $2500
Buying Stocks (Option 2):
Enter stock number to buy: 1
Enter quantity: 5
Successfully purchased 5 shares of Apple.
Selling Stocks (Option 3):
Enter stock number to sell: 1
Enter quantity: 2
Successfully sold 2 shares of Apple.
Viewing Portfolio (Option 4):
Your Portfolio:
Apple -3 shares
Total Value: $450
Saving Portfolio (Option 5):
Portfolio saved successfully!
Exiting (Option 6):
Thank you for using the Stock Market Simulator. Goodbye! Stock Market Simulator
Objective: Develop a basic stock market simulator using
Python. The simulator should facilitate users to buy/sell
stocks, monitor their portfolio, and trace historical prices of a
set of stocks.
Specifications:
Stock Data Representation:
Use lists to store stock prices for multiple companies.
Utilize strings to represent stock names (e.g., "Apple", "Google").
Ensure that price[i] should match the stock named name[i].
File Processing with Python:
Use the open() function to read initial stock data from a file.
Each file line should include a stock name followed by its initial price.
Retain historical prices for the purpose of displaying trends.
User Portfolio:
Design lists to log the quantity of shares of each stock owned by the user and the
user's transaction history (buys/sells).
Menu System:
Implement a menu using Python's print function and input() for user prompts.
Options should cover:
Display stocks
Purchase stocks
Sell stocks
Observe portfolio
Save portfolio Exit
Buying and Selling Stocks:
Formulate functions for stock transactions, incorporating checks for sufficient
user funds, updating user stock count, and recording transactions.
Mathematical Functions:
Develop functions to compute the net worth of the user's portfolio.
Create a simple random walk method to adjust stock prices after each user
transaction to emulate market variations. You may use the following:det stmolato,price_charge(current_price):stmplate a randoa pztce change for a stock.current,orice (float); The current price of the stoek.float: The new stice aftor the randes malk.\ Define parameters for the randon malkvolatility =0.3* Volatality (can be adjusted)random_changs = random,gauss(drift, volatility)new_price = current_price *(1+ random,change)if new,price 0.04:return new,price
Exanple usage:
current_price =}=100.0=|\mathrm{ Replace with tha actual current price
new,price = simulate,price_change(current, price)
print(t*New price; ${nowsgrtce;.2t)=)Save User Portfolio:
Integrate functionality to preserve the user's portfolio and transaction logs in a
file for subsequent sessions.
Error Handling with Python:
Use try-except blocks to tackle potential user mistakes, such as inputting invalid
data or attempting to sell stocks not in their possession.
Sample Output -
Viewing Stocks (Option 1):
Stock Market Simulator Objective: Develop a basic

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!