Week 5: Lists and Arrays in Python

Learn how to work with lists and arrays to handle financial time series data, stock prices, and portfolio holdings.

Learning Objectives:

Exercises:

  1. Create a basic portfolio tracker:
    • Store stock symbols and quantities in lists
    • Create a list of prices and calculate total value
    • Use list comprehension to calculate position values
  2. Implement a simple moving average calculator:
    • Create a list of historical prices
    • Calculate 5-day and 20-day moving averages
    • Generate signals when short MA crosses long MA
  3. Create a bond calculator:
    • Store bond details (face value, coupon, maturity) in nested lists
    • Calculate yield to maturity
    • Compare multiple bonds using list operations
  4. Build a price analyzer:
    • Create a NumPy array of daily prices
    • Calculate daily, weekly, and monthly returns
    • Find highest/lowest prices and their positions
  5. Implement a simple asset allocation tool:
    • Store current and target allocations in arrays
    • Calculate allocation differences
    • Determine rebalancing needs
  6. Create a basic risk calculator:
    • Store historical returns in NumPy arrays
    • Calculate correlation between assets
    • Compute portfolio volatility

💡 ChatGPT Learning Tips

Use these prompts to enhance your learning:

  1. "Show me how to use list comprehension for financial calculations"
  2. "Explain the difference between lists and NumPy arrays for financial data"
  3. "Help me understand how to structure portfolio data using lists"
  4. "What are efficient ways to calculate returns using NumPy arrays?"
← Previous Week | Next Week →
← Back to Home