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', 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')
[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-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 |
2020-06-09 00:00:00+00:00 | 320.79 | -0.007485 | 0.215876 | 121.03 | -0.019312 | 0.402040 | 2.650500 |
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 |