margot.data example notebook.ΒΆ

[1]:
from margot import Symbol, MargotDataFrame, Ratio
from margot import finance, alphavantage as av

class Index(Symbol):
    adj_close = av.DailyAdjusted(function='historical_daily_adjusted',
                          time_series='adjusted_close')
    log_returns = finance.LogReturns(column='adj_close')
    realised_vol = finance.RealisedVolatility(column='log_returns',
                                              window=30)

[2]:
class ExampleDF(MargotDataFrame):
    spy = Index(symbol='SPY', trading_calendar='NYSE')
    vtwo = Index(symbol='VTWO', trading_calendar='NYSE')
    spy_russ_ratio = Ratio(numerator=spy.adj_close,
                           denominator=vtwo.adj_close,
                           label='spy_russ')
[3]:
mdf = ExampleDF()
[4]:
mdf.to_pandas().tail()
[4]:
SPY VTWO margot
adj_close log_returns realised_vol adj_close log_returns realised_vol spy_russ_ratio
date
2020-06-23 00:00:00+00:00 312.05 0.004593 0.260809 115.2159 0.004250 0.429186 2.708394
2020-06-24 00:00:00+00:00 304.09 -0.025840 0.265557 111.4867 -0.032902 0.426147 2.727590
2020-06-25 00:00:00+00:00 307.35 0.010663 0.259729 113.0700 0.014102 0.411958 2.718228
2020-06-26 00:00:00+00:00 300.05 -0.024038 0.269796 110.4600 -0.023354 0.419855 2.716368
2020-06-29 00:00:00+00:00 304.46 0.014591 0.272220 113.9400 0.031019 0.425613 2.672108