Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using local market data source config #840

Merged
merged 1 commit into from
Oct 13, 2024
Merged
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ I have provided a few data sources built-in. Download this data using `python -m

Configuration is done by appending `pypmanager/configuration/market_data.yaml` with the securities you want to download data for.

Currently, there is support for loading data from the following sites:

- Morningstar
- The Financial Times
- Svenska Handelsbanken

## Unimplemented ideas

- Calculate IRR per security and on a total.
- Split the overview by account or maybe tag.
- Investments made in other currencies
- Support other online brokers by extending the `DataLoader` class.
1 change: 1 addition & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Never commit user data
market_data
transactions
configuration
48 changes: 0 additions & 48 deletions pypmanager/configuration/market_data.yaml
Original file line number Diff line number Diff line change
@@ -1,60 +1,12 @@
---
sources:
- isin_code: LU0051755006
loader_class: MorningstarLoader
lookup_key: F0GBR04SN7
name: JPM China A (dist) USD
- isin_code: SE0009268584
loader_class: MorningstarLoader
lookup_key: F00000YG5V
name: Lysa Aktier C
- isin_code: SE0013720000
loader_class: MorningstarLoader
lookup_key: F000014U6O
name: Aktiespararna Direktavkastning B
- isin_code: SE0017231947
loader_class: MorningstarLoader
lookup_key: F00001DFD6
name: Lysa Sweden Equity Broad B
- isin_code: SE0009268394
loader_class: MorningstarLoader
lookup_key: F00000YG5U
name: Lysa R�ntor C
- isin_code: SE0000671919
loader_class: MorningstarLoader
lookup_key: F0GBR04M88
name: Storebrand Global All Countries A SEK
- isin_code: SE0004297927
loader_class: MorningstarLoader
lookup_key: F00000NBM7
name: Spiltan Aktiefond Investmentbolag
- isin_code: SE0003788587
loader_class: MorningstarLoaderSHB
lookup_key: shb0000025
- isin_code: SE0014453221
loader_class: FTLoader
lookup_key: "601933686"
- isin_code: SE0005965662
loader_class: FTLoader
lookup_key: "535679922"
- isin_code: SE0014956850
loader_class: FTLoader
lookup_key: "679312906"
- isin_code: SE0005188836
loader_class: FTLoader
lookup_key: "535619835"
- isin_code: SE0005796331
loader_class: FTLoader
lookup_key: "535627197"
- isin_code: SE0016798805
loader_class: FTLoader
lookup_key: "681984998"
- isin_code: SE0003455658
loader_class: FTLoader
lookup_key: "535686415"
- isin_code: SE0008129985
loader_class: FTLoader
lookup_key: "535691067"
- isin_code: SE0000529992
loader_class: FTLoader
lookup_key: "535673247"
23 changes: 18 additions & 5 deletions pypmanager/ingest/market_data/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

from datetime import UTC, datetime
from pathlib import Path
from typing import TYPE_CHECKING, Any

import pandas as pd
Expand All @@ -22,14 +21,28 @@

def _load_sources() -> list[Source]:
"""Load settings."""
path = Path(Settings.file_market_data_config)
with path.open(encoding="UTF-8") as file:
output_data: list[Source] = []
with Settings.file_market_data_config.open(encoding="UTF-8") as file:
# Load the YAML content from the file
yaml_data = yaml.safe_load(file)

data = Sources(**yaml_data)
global_sources = Sources(**yaml_data).sources
LOGGER.info(f"Found {len(global_sources)} source(s) in global file")
output_data.extend(global_sources)

return data.sources
if (
Settings.file_market_data_config_local
and Settings.file_market_data_config_local.exists()
):
with Settings.file_market_data_config_local.open(encoding="UTF-8") as file:
# Load the YAML content from the file
yaml_data = yaml.safe_load(file)

local_sources = Sources(**yaml_data).sources
LOGGER.info(f"Found {len(local_sources)} source(s) in local file")
output_data.extend(local_sources)

return output_data

Check warning on line 45 in pypmanager/ingest/market_data/helpers.py

View workflow job for this annotation

GitHub Actions / Run test suite (3.12)

Missing coverage

Missing coverage on lines 24-45


def _class_importer(name: str) -> Any: # noqa: ANN401
Expand Down
10 changes: 10 additions & 0 deletions pypmanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@
folder_path = Path(self.dir_config)
return (folder_path / "market_data.yaml").resolve()

@property
def file_market_data_config_local(self: TypedSettings) -> Path | None:
"""Return local market data file."""
folder_path = Path(self.dir_data)
local_market_data = (folder_path / "configuration/market_data.yaml").resolve()
if local_market_data.exists():
return local_market_data

return None

Check warning on line 65 in pypmanager/settings.py

View workflow job for this annotation

GitHub Actions / Run test suite (3.12)

Missing coverage

Missing coverage on lines 60-65

is_demo: bool = False


Expand Down
Loading