View on GitHub

Home

Algorithmic Trading Strategy

Introduction

In this assignment, you will develop an algorithmic trading strategy by incorporating financial metrics to evaluate its profitability. This exercise simulates a real-world scenario where you, as part of a financial technology team, need to present an improved version of a trading algorithm that not only executes trades but also calculates and reports on the financial performance of those trades.

Background

Following a successful presentation to the Board of Directors, you have been tasked by the Trading Strategies Team to modify your trading algorithm. This modification should include tracking the costs and proceeds of trades to facilitate a deeper evaluation of the algorithm’s profitability, including calculating the Return on Investment (ROI).

After meeting with the Trading Strategies Team, you were asked to include costs, proceeds, and return on investments metrics to assess the profitability of your trading algorithm.

Objectives

  1. Load and Prepare Data: Open and run the starter code to create a DataFrame with stock closing data.

  2. Implement Trading Algorithm: Create a simple trading algorithm based on daily price changes.

  3. Customize Trading Period: Choose your entry and exit dates.

  4. Report Financial Performance: Analyze and report the total profit or loss (P/L) and the ROI of the trading strategy.

  5. Implement a Trading Strategy: Implement a trading strategy and analyze the total updated P/L and ROI.

  6. Discussion: Summarise your finding.

Instructions

Step 1: Data Loading

Start by running the provided code cells in the “Data Loading” section to generate a DataFrame containing AMD stock closing data. This will serve as the basis for your trading decisions. First, create a data frame named amd_df with the given closing prices and corresponding dates.

# Load data from CSV file
amd_df <- read.csv("AMD.csv")
# Convert the date column to Date type and Adjusted Close as numeric
amd_df$date <- as.Date(amd_df$Date)
amd_df$close <- as.numeric(amd_df$Adj.Close)
amd_df <- amd_df[, c("date", "close")]

Plotting the Data

Plot the closing prices over time to visualize the price movement.

plot(amd_df$date, amd_df$close,'l')

Step 2: Trading Algorithm

Implement the trading algorithm as per the instructions. You should initialize necessary variables, and loop through the dataframe to execute trades based on the set conditions.

# Initialize columns for trade type, cost/proceeds, and accumulated shares in amd_df
amd_df$trade_type <- NA
amd_df$costs_proceeds <- NA  # Corrected column name
amd_df$accumulated_shares <- 0  # Initialize if needed for tracking

# Initialize variables for trading logic
previous_price <- 0
share_size <- 100
accumulated_shares <- 0

for (i in 1:nrow(amd_df)) {
# Fill your code here
}

Step 3: Customize Trading Period

Step 4: Run Your Algorithm and Analyze Results

After running your algorithm, check if the trades were executed as expected. Calculate the total profit or loss and ROI from the trades.

# Fill your code here

Step 5: Profit-Taking Strategy or Stop-Loss Mechanisum (Choose 1)

# Fill your code here

Step 6: Summarize Your Findings

# Fill your code here and Disucss

Sample Discussion: On Wednesday, December 6, 2023, AMD CEO Lisa Su discussed a new graphics processor designed for AI servers, with Microsoft and Meta as committed users. The rise in AMD shares on the following Thursday suggests that investors believe in the chipmaker’s upward potential and market expectations; My first strategy earned X dollars more than second strategy on this day, therefore providing a better ROI.