Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions Choose 4 different stocks from any publicly listed companies Find the closing prices for these stocks on September 2 0 , 2 0 2

Instructions
Choose 4 different stocks from any publicly listed companies
Find the closing prices for these stocks on September 20,2024 as the purchase price, and September 26,2024 as the current price
Use these stock prices to complete the following tasks
Task 1: Collect Stock Prices Data and Create Vectors
Choose 4 different stocks and note their ticker symbols (e.g., AAPL for Apple, MSFT for Microsoft, etc.).
Use an online source (such as Yahoo Finance or Google Finance) to find the closing prices of these stocks on the following dates:
Purchase price: Closing price on September 20,2024.
Current price: Closing price on September 26,2024.
Create three vectors:
stock_tickers: Stock ticker symbols (e.g.,AAPL,MSFT,GOOG,AMZN).
purchase_prices: The closing prices on September 20,2024.
current_prices: The closing prices on September 26,2024.
# write your code
Task 2: Write a Function to Calculate Returns and Use a Loop
Define a function CalculateReturn(current_price, purchase_price) that
Takes the current price and purchase price as inputs
Calculate the percentage return using the formula:
Percentage Return=Current PricePurchase PricePurchase Price\times 100
Use a for loop to apply this function to each stock and create a new vector returns that stores the percentage return for each stock.
Task 3: DataFrame
Create a DataFrame portfolio_df with the following columns:
Stock: Stock ticker symbols.
Purchase_Price: Purchase prices from Task 1.
Current_Price: Current prices from Task 1.
Return: The percentage return from Task 2.
Use the ifelse() function to create a new column Trade_Decision based on the following conditions:
Sell if the return is greater than 3%.
Sell if the return is less than -1%.
Hold otherwise.
Task 4:Calculate Realized Profit/Loss Based on Trade Decisions
Bouns Points: Vectorize the calculation for Task4
Loop through the portfolio and check the trade decision. If the decision is Sell, calculate the realized profit for that stock:
Realized Profit/Loss=Current PricePurchase Price
Sum the realized profits/losses for all stocks.
Print the total realized profit/loss for the portfolio.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Public Finance

Authors: Harvey Rosen, Ted Gayer

10th edition

9781259716874, 78021685, 1259716872, 978-0078021688

More Books

Students also viewed these Finance questions