Relative tickersΒΆ

[1]:
# If you would like to refresh your data, please execute the bellow codes.

import pandas as pd
import numpy as np
from datetime import datetime
from tqdm import tqdm

from mypo import Loader

DOWNLOAD = False

if DOWNLOAD:
    tickers = pd.read_csv("/app/docs/tutorial/tickers.csv")
    loader = Loader()
    for row in tqdm(tickers.to_dict('record')):
        loader.get(row['Ticker'], expense_ratio=row['ExpenseRatio'] * 0.01)
    loader.save('/app/docs/tutorial/all.bin')
[2]:
loader = Loader.load('/app/docs/tutorial/all.bin')
loader = loader.since(datetime(2005, 1, 1))
market = loader.get_market()
[3]:
relatives = market.get_relative('SPY')
subset = market.filter(relatives.index)
subset.get_normalized_prices().plot()
summary = subset.get_summary()
pd.concat([relatives, summary], axis=1)
/app/mypo/market.py:344: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df[c] = df[c] / df[c][0]
[3]:
correlation daily return variance sharpe ratio expense ratio
SPY 1.000000 0.000378 0.000151 2.504204 0.0009
IVV 0.991220 0.000378 0.000149 2.534072 0.0004
VTI 0.989775 0.000396 0.000153 2.582378 0.0003
VV 0.984560 0.000394 0.000150 2.622159 0.0004
OEF 0.981520 0.000362 0.000144 2.506807 0.0020
DIA 0.971903 0.000354 0.000142 2.485636 0.0016
VUG 0.964886 0.000481 0.000153 3.148496 0.0004
VTV 0.964339 0.000309 0.000161 1.926668 0.0004
VO 0.959315 0.000439 0.000184 2.378992 0.0004
SPYG 0.959191 0.000461 0.000147 3.135345 0.0004
../_images/tutorial_relative_3_2.png
[4]:
relatives = market.get_relative('QQQ')
subset = market.filter(relatives.index)
subset.get_normalized_prices().plot()
summary = subset.get_summary()
pd.concat([relatives, summary], axis=1)
/app/mypo/market.py:344: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df[c] = df[c] / df[c][0]
[4]:
correlation daily return variance sharpe ratio expense ratio
QQQ 1.000000 0.000604 0.000180 3.357576 0.0020
VGT 0.972177 0.000592 0.000192 3.093324 0.0010
VUG 0.959840 0.000481 0.000153 3.148496 0.0004
XLK 0.959785 0.000542 0.000186 2.916631 0.0013
IXN 0.950463 0.000533 0.000190 2.805024 0.0046
SPYG 0.948154 0.000461 0.000147 3.135345 0.0004
IVV 0.917970 0.000378 0.000149 2.534072 0.0004
VV 0.917716 0.000394 0.000150 2.622159 0.0004
OEF 0.917152 0.000362 0.000144 2.506807 0.0020
VTI 0.917042 0.000396 0.000153 2.582378 0.0003
../_images/tutorial_relative_4_2.png
[5]:
relatives = market.get_relative('TLT')
subset = market.filter(relatives.index)
subset.get_normalized_prices().plot()
summary = subset.get_summary()
pd.concat([relatives, summary], axis=1)
/app/mypo/market.py:344: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df[c] = df[c] / df[c][0]
[5]:
correlation daily return variance sharpe ratio expense ratio
TLT 1.000000 0.000149 8.023317e-05 1.852575 0.0015
IEF 0.910671 0.000078 1.682326e-05 4.616812 0.0015
TIP 0.687777 0.000052 1.542495e-05 3.399998 0.0019
AGG 0.628454 0.000031 1.006247e-05 3.110153 0.0005
SHY 0.532498 0.000013 8.115460e-07 16.588645 0.0015
LQD 0.444578 0.000052 2.888835e-05 1.791466 0.0014
GLD 0.137658 0.000385 1.311764e-04 2.936049 0.0040
XLU -0.188980 0.000286 1.442391e-04 1.982567 0.0013
VPU -0.204574 0.000292 1.424607e-04 2.047491 0.0010
BBH -0.231169 0.000469 2.608901e-04 1.799338 0.0035
../_images/tutorial_relative_5_2.png
[6]:
relatives = market.get_relative('SHY')
subset = market.filter(relatives.index)
subset.get_normalized_prices().plot()
summary = subset.get_summary()
pd.concat([relatives, summary], axis=1)
/app/mypo/market.py:344: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df[c] = df[c] / df[c][0]
[6]:
correlation daily return variance sharpe ratio expense ratio
SHY 1.000000 0.000013 8.115460e-07 16.588645 0.0015
IEF 0.710661 0.000078 1.682326e-05 4.616812 0.0015
TIP 0.554166 0.000052 1.542495e-05 3.399998 0.0019
TLT 0.532498 0.000149 8.023317e-05 1.852575 0.0015
AGG 0.506509 0.000031 1.006247e-05 3.110153 0.0005
LQD 0.287736 0.000052 2.888835e-05 1.791466 0.0014
GLD 0.145957 0.000385 1.311764e-04 2.936049 0.0040
BBH -0.145924 0.000469 2.608901e-04 1.799338 0.0035
XLU -0.158207 0.000286 1.442391e-04 1.982567 0.0013
VPU -0.173564 0.000292 1.424607e-04 2.047491 0.0010
../_images/tutorial_relative_6_2.png
[7]:
relatives = market.get_relative('OIH')
subset = market.filter(relatives.index)
subset.get_normalized_prices().plot()
summary = subset.get_summary()
pd.concat([relatives, summary], axis=1)

/app/mypo/market.py:344: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df[c] = df[c] / df[c][0]
[7]:
correlation daily return variance sharpe ratio expense ratio
OIH 1.000000 0.000070 0.000640 0.109930 0.0035
VDE 0.930946 0.000264 0.000376 0.700395 0.0010
XLE 0.918825 0.000274 0.000379 0.723470 0.0013
IXC 0.895601 0.000171 0.000320 0.533886 0.0046
VAW 0.741992 0.000408 0.000248 1.644935 0.0010
IJH 0.726242 0.000450 0.000195 2.302109 0.0007
VO 0.718080 0.000439 0.000184 2.378992 0.0004
XLB 0.717752 0.000377 0.000236 1.599943 0.0013
VXF 0.706386 0.000471 0.000205 2.302768 0.0006
VBR 0.704551 0.000387 0.000229 1.687121 0.0007
../_images/tutorial_relative_7_2.png
[8]:
relatives = market.get_relative('GLD')
subset = market.filter(relatives.index)
subset.get_normalized_prices().plot()
summary = subset.get_summary()
pd.concat([relatives, summary], axis=1)

/app/mypo/market.py:344: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df[c] = df[c] / df[c][0]
[8]:
correlation daily return variance sharpe ratio expense ratio
GLD 1.000000 0.000385 0.000131 2.936049 0.0040
EZA 0.244017 0.000327 0.000509 0.641726 0.0059
TIP 0.234096 0.000052 0.000015 3.399998 0.0019
IXC 0.184852 0.000171 0.000320 0.533886 0.0046
VAW 0.182821 0.000408 0.000248 1.644935 0.0010
XLB 0.181047 0.000377 0.000236 1.599943 0.0013
EWZ 0.180725 0.000450 0.000616 0.729426 0.0059
ILF 0.171530 0.000397 0.000468 0.847993 0.0048
IEF 0.169814 0.000078 0.000017 4.616812 0.0015
EPP 0.165893 0.000269 0.000264 1.019724 0.0048
../_images/tutorial_relative_8_2.png