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-15 00:00:00+00:00 305.6968 0.009292 0.260969 113.92 0.022998 0.433523 2.683434
2020-06-16 00:00:00+00:00 311.5808 0.019065 0.265222 116.76 0.024624 0.437526 2.668558
2020-06-17 00:00:00+00:00 310.2865 -0.004163 0.265461 114.60 -0.018673 0.442664 2.707561
2020-06-18 00:00:00+00:00 310.4060 0.000385 0.264006 114.65 0.000436 0.441551 2.707423
2020-06-19 00:00:00+00:00 308.6400 -0.005706 0.263797 113.85 -0.007002 0.441814 2.710935