- 1st Aug 2024
- 17:59 pm
You will write a program to model a series of stock market transactions over time. Your program will allow a user to examine stock prices and find trends using real historical price data. Your program will be a function called StockMarket which takes no arguments and returns no values. Your function StockMarket will allow the user to enter commands related to stock market transactions and queries. Your function should print out a prompt to indicate that the user can enter a command. Your prompt should be a $ character. At the prompt the user will type a command followed by a set of arguments for the command. Your function will perform whatever action is indicated by the command, and then your program will print a $ character on a new line in order to let the user know that he/she can type a new command. The program will continuously ask for commands, and execute them unless the user enters the quit command, which will then terminate your program.
The program will be used for buying and selling only the following two stocks of Covid-19 Vaccines: Moderna Inc (MRNA) and Pfizer Inc (PFE). An attempt to buy or sell any stock other than these is not valid and should result in your program printing an error message before displaying the next prompt.
Free Assignment Solution - Interactive Transaction And Trend Analysis For Moderna And Pfizer
import pandas as pd
from datetime import datetime
def StockMarket():
data1 = []
data2 = []
while(True):
inp = input("Please enter command: ")
try:
if inp.startswith('ReadFiles'):
p2 = inp.split(' ')[1]
p1 = inp.split(' ')[2]
data1 = pd.read_csv(p1)[['Date','Close']]
data2 = pd.read_csv(p2)[['Date','Close']]
data1['Date'] = pd.to_datetime(data1['Date'])
data2['Date'] = pd.to_datetime(data2['Date'])
data1 = data1.set_index('Date')
data2 = data2.set_index('Date')
elif inp.startswith('PricesOnDate'):
v = inp.split(' ')[1]
v1 = data1.loc[v][0]
v2 = data2.loc[v][0]
print('PFE:' ,v2,'|','MRNA:',v1)
elif inp=='quit':
break
elif inp.startswith('MaxPossible'):
f = inp.split(' ')[1]
d1 = inp.split(' ')[3]
d2 = inp.split(' ')[4]
s = inp.split(' ')[2]
if s=='MRNA':
df2 = data1.reset_index()
else:
df2 = data2.reset_index()
if f=='profit':
df2 = df2[(df2['Date']<d2) & (df2['Date']>d1)]
df2
d = df2[df2['Close']==df2['Close'].min()]
s = d['Close']
e = df2[(df2['Date']>d['Date'].values[0])]['Close'].max()
profit = e-s
print(profit.values[0])
else:
df2 = df2[(df2['Date']<d1) & (df2['Date']>d2)]
df2
d = df2[df2['Close']==df2['Close'].max()]
s = d['Close']
e = df2[(df2['Date']>d['Date'].values[0])]['Close'].min()
loss = s-e
print(loss.values[0])
elif inp.startswith('FindTrend'):
d1 = inp.split(' ')[2]
d2 = inp.split(' ')[3]
s = inp.split(' ')[1]
if s=='MRNA':
df2 = data1.reset_index()
elif s=='PFE':
df2 = data2.reset_index()
else:
continue
df2 = df2[(df2['Date']<=d2) & (df2['Date']>=d1)]
cp=0
cn=0
first = True
for i in df2.index:
#print('hhh')
if (first):
first=False
p=df2['Close'][i]
print(df2['Date'][i],'|',df2['Close'][i])
continue
if df2['Close'][i]-p>=0:
print(df2['Date'][i],'|',df2['Close'][i])
cp+=1
cn=0
else:
print(df2['Date'][i],'|',df2['Close'][i])
cp=0
cn-=1
if(cp==3):
print(df2['Date'][i],'|',df2['Close'][i],'|','sell')
cp=0
cn=0
elif(cn==-3):
cp=0
cn=0
print(df2['Date'][i],'|',df2['Close'][i],'|','buy')
p=df2['Close'][i]
except:
print("Please enter valid command!")
Get the best Interactive Transaction and Trend Analysis for Moderna and Pfizer assignment help and tutoring services from our experts now!
Our team of Python experts has successfully finished this sample Python assignment. The provided solutions are intended solely for research and reference. If you find the reports and code useful, our Python tutors would be happy to help.
- For a complete solution package that includes code, reports, and screenshots, please check out our Python Assignment Sample Solution page.
- For personalized online tutoring sessions to address any questions you have about this assignment, reach out to our Python experts.
- For additional insights, explore the partial solution available in the blog above.
About The Author - Jane Doe
Jane Doe is a skilled software developer specializing in financial applications. With expertise in modeling stock market transactions, she crafts programs that facilitate real-time analysis and transaction management. Her latest project, StockMarket, offers an intuitive command-based interface for managing Moderna and Pfizer stocks, making financial tracking straightforward and efficient.