[1]:
# margot.data example notebook.
[2]:
from margot.data import MargotDataFrame, Symbol, Ratio
from margot.data.column import alphavantage as av
from margot.data.features import finance

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

[3]:
class ExampleDF(MargotDataFrame):
    spy = Index(symbol='SPY')
    vtwo = Index(symbol='VTWO')
    spy_russ_ratio = Ratio(numerator=spy.adj_close,
                           denominator=vtwo.adj_close,
                           label='spy_russ')
[4]:
mdf = ExampleDF()
[5]:
mdf.to_pandas().tail()
[5]:
SPY VTWO margot
adj_close log_returns realised_vol adj_close log_returns realised_vol spy_russ_ratio
date
2020-06-02 00:00:00+00:00 308.08 0.008246 0.234196 113.91 0.008463 0.400729 2.704591
2020-06-03 00:00:00+00:00 312.18 0.013220 0.212717 116.44 0.021967 0.393954 2.681037
2020-06-04 00:00:00+00:00 311.36 -0.002630 0.207012 116.54 0.000858 0.394140 2.671701
2020-06-05 00:00:00+00:00 319.34 0.025307 0.215927 120.86 0.036398 0.403436 2.642231
2020-06-08 00:00:00+00:00 323.20 0.012015 0.215303 123.39 0.020717 0.404300 2.619337