0% found this document useful (0 votes)
21 views

Python Assignment

Uploaded by

lifeishellin2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Python Assignment

Uploaded by

lifeishellin2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment: Stock Portfolio Tracker and Trade Analyzer

You are tasked with building a Stock Portfolio Tracker and Trade Analyzer. The program should simulate
portfolio management, analyze stock trading opportunities, and provide insights based on real-world data.

Part 1: Data Collection

1. Fetch Real-Time Data:


o Use a publicly available stock API (e.g., Alpha Vantage, Yahoo Finance, or Finnhub) to fetch
real-time stock prices for at least 10 stock symbols (e.g., AAPL, TSLA, AMZN, MSFT, etc.).
o Store the data locally in a file (e.g., CSV or SQLite database).
2. Historical Data:
o Download historical stock data for the past 3 months for the same symbols and store it
separately.

Part 2: Portfolio Tracker

1. Simulate a Portfolio:
o Create a sample portfolio where the user owns specific quantities of stocks (e.g., AAPL: 10
shares, TSLA: 5 shares).
o Calculate and display the current value of the portfolio using real-time data.
2. Performance Tracking:
o Compare the current portfolio value with its value at the start of the historical data period.
o Calculate the percentage gain/loss for each stock and the portfolio as a whole.

Part 3: Trade Analyzer

1. Trade Signal Generation:


o Implement a Moving Average Crossover Strategy:
 Calculate 5-day and 20-day moving averages for each stock.
 Generate a BUY signal if the 5-day moving average crosses above the 20-day moving
average.
 Generate a SELL signal if the 5-day moving average crosses below the 20-day moving
average.
o Output these signals along with the stock name and date.
2. Trade History Simulation:
o Simulate trades based on the generated signals:
 Assume an initial capital of $10,000.
 Buy or sell stocks according to the signals, using the closing price of the respective
days.
o Display the final capital and portfolio value at the end of the 3 months.

Part 4: Error Handling and Logging

1. Error Handling:
o Handle potential errors, such as:
 API rate limits.
 Missing data for certain dates.
 Negative portfolio balance (ensure simulation doesn’t allow overspending).
2. Logging:
o Log each trade, including the date, stock symbol, action (BUY/SELL), quantity, price, and
portfolio balance.

Bonus Tasks (Optional)

1. Data Visualization:
o Plot the stock prices over time for all symbols.
o Highlight buy and sell signals on the graph.
2. Custom Strategy:
o Allow the user to define custom thresholds for the moving average periods and test the
performance.

Deliverables

1. Python scripts implementing the above functionalities.


2. A README file with instructions on:
o How to run the program?
o Assumptions made.
o Libraries used.
3. Output files/logs (CSV or text files) showing:
o Portfolio performance.
o Trade history.
o Any errors logged.
Submission Instructions

 Please email the completed assignment (as a zip file) to [Your Email Address].
 Use the subject line: [Your Name] – Python Developer Assignment.
 Deadline: [Insert Date and Time].

Evaluation Criteria

1. Correctness: Does the program fetch and process data accurately?

_______________

You might also like