DataFrame Input Guide
Using Polars DataFrames
finalytics
allows you to bypass online data fetching by passing your own Polars DataFrames for use with the Ticker
, Tickers
, and Portfolio
modules.
This is especially useful when: - You already have historical data from another source. - You want to use cleaned or adjusted data. - You need offline or reproducible analysis.
1. Single Ticker
import polars as pl
from finalytics import Ticker
= pl.read_csv("aapl.csv")
aapl = pl.read_csv("gspc.csv")
gspc
= Ticker(
ticker ="AAPL",
symbol=aapl,
ticker_data=gspc,
benchmark_data=0.95,
confidence_level=0.02
risk_free_rate
)
"performance") ticker.report(
2. Multiple Tickers
= pl.read_csv("nvda.csv")
nvda = pl.read_csv("goog.csv")
goog = pl.read_csv("aapl.csv")
aapl = pl.read_csv("msft.csv")
msft = pl.read_csv("btcusd.csv")
btcusd = pl.read_csv("gspc.csv")
gspc
= [nvda, goog, aapl, msft, btcusd]
tickers_data
from finalytics import Tickers
= Tickers(
tickers =["NVDA", "GOOG", "AAPL", "MSFT", "BTC-USD"],
symbols=tickers_data,
tickers_data=gspc,
benchmark_data="^GSPC",
benchmark_symbol=0.95,
confidence_level=0.02
risk_free_rate
)
"performance") tickers.report(
3. Portfolio Optimization
from finalytics import Portfolio
= Portfolio(
portfolio =["NVDA", "GOOG", "AAPL", "MSFT", "BTC-USD"],
ticker_symbols=tickers_data,
tickers_data=gspc,
benchmark_data="^GSPC",
benchmark_symbol=0.95,
confidence_level=0.02,
risk_free_rate="max_sharpe"
objective_function
)
"performance") portfolio.report(
📘 DataFrame Format
import polars as pl
= pl.DataFrame({
df "timestamp": [1672704000, 1672790400],
"open": [130.28, 126.89],
"high": [130.90, 128.66],
"low": [124.17, 125.08],
"close": [125.07, 126.36],
"volume": [112117500.0, 89113600.0],
"adjclose": [124.82, 126.11],
})
📘 Important Notes
- The DataFrame must include at least the
timestamp
andclose
columns- Column names are case-sensitive and must match exactly
timestamp
must be in UNIX time format (seconds since epoch)- Any missing columns will be automatically filled with
None
- You can find the example CSV files at this link