Skip to content
Draft
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,216 changes: 138 additions & 6,078 deletions cookbook/2-Mean-Variance-Optimisation.ipynb

Large diffs are not rendered by default.

781 changes: 73 additions & 708 deletions cookbook/3-Advanced-Mean-Variance-Optimisation.ipynb

Large diffs are not rendered by default.

798 changes: 83 additions & 715 deletions cookbook/4-Black-Litterman-Allocation.ipynb

Large diffs are not rendered by default.

561 changes: 30 additions & 531 deletions cookbook/5-Hierarchical-Risk-Parity.ipynb

Large diffs are not rendered by default.

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

import pandas as pd

__all__ = [
"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_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 @@
{
"AAPL": 3000000000000,
"AMZN": 2000000000000,
"BAC": 300000000000,
"GOOG": 2200000000000,
"JPM": 700000000000,
"MA": 500000000000,
"META": 1500000000000,
"PFE": 150000000000,
"SBUX": 110000000000,
"WMT": 750000000000
}
Loading