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 buysell
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 eg "Apple", "Google"
Ensure that pricei should match the stock named namei
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 buyssells
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 tryexcept 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 :
Buying Stocks Option :
Selling Stocks Option :
Viewing Portfolio Option :
Saving Portfolio Option :
Exiting Option :Available Stocks:
Apple $
Google $
Buying Stocks Option :
Enter stock number to buy:
Enter quantity:
Successfully purchased shares of Apple.
Selling Stocks Option :
Enter stock number to sell:
Enter quantity:
Successfully sold shares of Apple.
Viewing Portfolio Option :
Your Portfolio:
Apple shares
Total Value: $
Saving Portfolio Option :
Portfolio saved successfully!
Exiting Option :
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 buysell
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 eg "Apple", "Google"
Ensure that pricei should match the stock named namei
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 buyssells
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,pricechargecurrentprice: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 Volatality can be adjustedrandomchangs random,gaussdrift volatilitynewprice currentprice random,changeif new,price :return new,price
Exanple usage:
currentprice mathrm Replace with tha actual current price
new,price simulate,pricechangecurrent price
printtNew price; $nowsgrtce;tSave User Portfolio:
Integrate functionality to preserve the user's portfolio and transaction logs in a
file for subsequent sessions.
Error Handling with Python:
Use tryexcept 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 :
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
