Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 20 additions & 113 deletions cookbook/1-RiskReturnModels.ipynb

Large diffs are not rendered by default.

6,172 changes: 118 additions & 6,054 deletions cookbook/2-Mean-Variance-Optimisation.ipynb

Large diffs are not rendered by default.

769 changes: 67 additions & 702 deletions cookbook/3-Advanced-Mean-Variance-Optimisation.ipynb

Large diffs are not rendered by default.

767 changes: 67 additions & 700 deletions cookbook/4-Black-Litterman-Allocation.ipynb

Large diffs are not rendered by default.

557 changes: 28 additions & 529 deletions cookbook/5-Hierarchical-Risk-Parity.ipynb

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions pypfopt/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from importlib.resources import files
import json

import pandas as pd

__all__ = [
"load_cookbook_prices",
"load_example_market_caps",
"load_example_prices",
"load_spy_prices",
]


def _load_csv(filename: str) -> pd.DataFrame:
resource = files(__package__).joinpath(filename)
with resource.open("rb") as handle:
return pd.read_csv(handle, parse_dates=["date"], index_col="date")


def load_example_prices() -> pd.DataFrame:
return _load_csv("stock_prices.csv")


def load_cookbook_prices() -> pd.DataFrame:
return _load_csv("yfinance_stock_prices.csv")


def load_spy_prices() -> pd.DataFrame:
return _load_csv("spy_prices.csv")


def load_example_market_caps() -> dict[str, int]:
resource = files(__package__).joinpath("example_market_caps.json")
with resource.open("r", encoding="utf-8") as handle:
market_caps = json.load(handle)
return {ticker: int(value) for ticker, value in market_caps.items()}
12 changes: 12 additions & 0 deletions pypfopt/data/example_market_caps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"AMZN": 2662932938752,
"BAC": 391632846848,
"COST": 405003698176,
"DIS": 206492696576,
"DPZ": 13826333696,
"KO": 308038205440,
"MCD": 218510311424,
"MSFT": 3780701847552,
"NAT": 768654912,
"SBUX": 98250891264
}
Loading