Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save quantra-go-algo/6d8c9f7e5c4db2b991100144fc796012 to your computer and use it in GitHub Desktop.

Select an option

Save quantra-go-algo/6d8c9f7e5c4db2b991100144fc796012 to your computer and use it in GitHub Desktop.
guardrailed-llm-agent — Step 2: Getting the Data Right (snippet 1)
import yfinance as yf
import pandas as pd, numpy as np
# auto_adjust=True ensures prices are split- and dividend-adjusted.
# AAPL split 7-for-1 in 2014 and 4-for-1 in 2020. Without adjustment,
# those days show fake -86% and -75% returns that corrupt every feature.
df = yf.download(SYMBOL, start=START, auto_adjust=True, progress=False)
if isinstance(df.columns, pd.MultiIndex):
df = df.droplevel(-1, axis=1) # flatten multi-level columns
df.index = pd.to_datetime(df.index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment