<jupyter_start><jupyter_text>Loading Portfolio dataThe `ppt/portfolio_analysis.py` file contains functions for predefined analyses, however, you can still using the `StockPriceLoader` and `CalculateStockValue` classes directly to load the raw data to do your own independant analysis.However, everyone's portfolio is unique and everyone has slightly different requirements for their analysis (one of the reasons for making this library!). This notebook explains how you can directly use the data loading classes which are wrapped within the main `Portfolio` object for low level access to the raw data.<jupyter_code>%load_ext autoreload
%autoreload 2

# !pip install nb_black
%load_ext nb_black
import sys

sys.path.append("..")
import pandas as pd

%matplotlib inline
import matplotlib.pyplot as plt
from utils import print_properties

from ppt.data_loader import (
    BenchMarkLoader,
    CurrencyLoader,
    PositionLoader,
    StockPriceLoader,
)<jupyter_output><empty_output><jupyter_text>Input data formatSee the `README` for explainations on the required data input format.<jupyter_code># example input
pd.read_csv("../data/raw/purchase_info.csv")<jupyter_output><empty_output><jupyter_text>Load PositionsThe base case for all classes is `PositionLoader` this loads the raw input data and extracts some key information which is used by other classes to help with data processing<jupyter_code># automatically loads from default data location (../data/raw/purchase_info.csv)
positions = PositionLoader()
# properties
print_properties(positions)
# dataframe with input csv data
positions.positions
# tickers
positions.tickers
# metadata
positions.stock_metadata<jupyter_output><empty_output><jupyter_text>Load Stock PricesYou are able to load a dataframe of daily closing stock prices for all stock tickers present in the `purchase_info.csv`, starting from the earliest date of your first position, using the `StockPriceLoader` class.Note the default location for the input data file is: `../data/raw/purchase_info.csv`, however, you can specify your own location using the `input_data_source` argument.The `StockPriceLoader` class uses the `ffn` library to load the stock prices for free from Yahoo ([see ffn library for more details](https://pmorissette.github.io/ffn/)).<jupyter_code># load stock prices of tickers in your purchase_info csv file
stock_prices = StockPriceLoader()
# __repr__ gives a list of tickers and the starting date
stock_prices
print_properties(stock_prices)<jupyter_output><empty_output><jupyter_text>The `StockPriceLoader` inherits the same properties from the `PositionLoader` seen above. There are two new properties: `daily_stock_prices_local_currency` and `daily_stock_prices_usd`. These are dataframes containing the daily stock prices for each ticker and the daily stock prices converted from the local currency to usd, starting from the earliest registered date in the input csv.<jupyter_code># local currencies
stock_prices.daily_stock_prices_local_currency.head(10)
# converted to USD
stock_prices.daily_stock_prices_usd.head(10)<jupyter_output><empty_output><jupyter_text>This is the 'raw' data from which all further calculations are made. You can use these dataframe of stock prices for your own individual stock analysis.<jupyter_code>stock_prices.daily_stock_prices_local_currency["NVDA"].plot()
plt.title("Nvidia stock price")
plt.ylabel("USD")
plt.show()<jupyter_output><empty_output><jupyter_text>BenchmarksSometimes you will want to benchmark your portfolio against indices or other instruments.The `BenchMarkLoader` inherits from `PositionLoader`A single benchmark passed as a string or a list of benchmarks can be passed to the function.<jupyter_code># load SNP 500
benchmark = "^GSPC"
bm = BenchMarkLoader(benchmark_tickers=benchmark)
bm.benchmark_stock_prices
# list benchmarks
bm.benchmarks<jupyter_output><empty_output><jupyter_text>Currency LoaderHistorical daily exchange rates are collected from yahoo finance.<jupyter_code>cur = CurrencyLoader()

print_properties(cur)
cur.currencies
# daily exchange rates (including USD/USD)
cur.xrates<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0656651320571844, 'fraction_numerical': 0.001938454082868912, 'mean_word_length': 6.7593984962406015, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '577318', 'license': 'MIT', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1141, 'n_words': 430, 'path': 'tutorials/loading_raw_data.ipynb', 'repo_name': 'julian-west/python_portfolio_tracker', 'size': '4127'}