margot.data example notebook.ΒΆ
[1]:
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)
[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-10 00:00:00+00:00 | 319.00 | -0.005596 | 0.216225 | 117.67 | -0.028154 | 0.411975 | 2.710971 |
2020-06-11 00:00:00+00:00 | 300.61 | -0.059377 | 0.273717 | 108.94 | -0.077087 | 0.456570 | 2.759409 |
2020-06-12 00:00:00+00:00 | 304.21 | 0.011905 | 0.273778 | 111.33 | 0.021701 | 0.446860 | 2.732507 |
2020-06-15 00:00:00+00:00 | 307.05 | 0.009292 | 0.260969 | 113.92 | 0.022998 | 0.433523 | 2.695312 |
2020-06-16 00:00:00+00:00 | 312.96 | 0.019065 | 0.265222 | 116.76 | 0.024624 | 0.437526 | 2.680370 |