|
3 | 3 | from margot import finance, cboe, alphavantage as av
|
4 | 4 |
|
5 | 5 |
|
6 |
| -# def test_symbol(): |
| 6 | +def test_symbol(): |
| 7 | + class Equity(Symbol): |
| 8 | + adjusted_close = av.DailyAdjusted(time_series="adjusted_close") |
| 9 | + volume = av.DailyAdjusted(time_series="volume") |
7 | 10 |
|
8 |
| -# class Equity(Symbol): |
9 |
| -# adjusted_close = av.DailyAdjusted( |
10 |
| -# time_series='adjusted_close') |
11 |
| -# volume = av.DailyAdjusted( |
12 |
| -# time_series='volume') |
| 11 | + simple_returns = finance.SimpleReturns(column="adjusted_close") |
| 12 | + log_returns = finance.LogReturns(column="adjusted_close") |
| 13 | + realised_vol = finance.RealisedVolatility( |
| 14 | + column="log_returns", window=30 |
| 15 | + ) |
13 | 16 |
|
14 |
| -# simple_returns = finance.SimpleReturns(column='adjusted_close') |
15 |
| -# log_returns = finance.LogReturns(column='adjusted_close') |
16 |
| -# realised_vol = finance.RealisedVolatility( |
17 |
| -# column='log_returns', window=30) |
| 17 | + upper_band = finance.UpperBollingerBand( |
| 18 | + column="adjusted_close", window=20, width=2.0 |
| 19 | + ) |
| 20 | + sma20 = finance.SimpleMovingAverage(column="adjusted_close", window=20) |
| 21 | + lower_band = finance.LowerBollingerBand( |
| 22 | + column="adjusted_close", window=20, width=2.0 |
| 23 | + ) |
18 | 24 |
|
19 |
| -# upper_band = finance.UpperBollingerBand( |
20 |
| -# column='adjusted_close', window=20, width=2.0) |
21 |
| -# sma20 = finance.SimpleMovingAverage(column='adjusted_close', window=20) |
22 |
| -# lower_band = finance.LowerBollingerBand( |
23 |
| -# column='adjusted_close', window=20, width=2.0) |
24 |
| - |
25 |
| -# env = {'DATA_CACHE': os.path.join(os.getcwd(), 'data')} |
26 |
| -# spy = Equity(symbol='SPY', trading_calendar='NYSE') |
| 25 | + env = {"DATA_CACHE": os.path.join(os.getcwd(), "data")} |
| 26 | + spy = Equity(symbol="SPY", trading_calendar="NYSE") |
27 | 27 |
|
28 | 28 |
|
29 | 29 | # def test_frame():
|
30 |
| - |
31 | 30 | # class Index(Symbol):
|
32 |
| -# close = cboe.Column(time_series='close') |
| 31 | +# close = cboe.Column(time_series="close") |
33 | 32 |
|
34 | 33 | # class VXBasis(MargotDataFrame):
|
35 |
| -# vixm = Index(symbol='VIX3M', trading_calendar='NYSE') |
36 |
| -# vix3m = Index(symbol='VIX', trading_calendar='NYSE') |
| 34 | +# vixm = Index(symbol="VIX3M", trading_calendar="NYSE") |
| 35 | +# vix3m = Index(symbol="VIX", trading_calendar="NYSE") |
37 | 36 | # vx_basis = Ratio(
|
38 | 37 | # numerator=vixm.close,
|
39 | 38 | # denominator=vix3m.close,
|
40 |
| -# label='vx_basis_ratio') |
| 39 | +# label="vx_basis_ratio", |
| 40 | +# ) |
41 | 41 |
|
42 | 42 | # vxbasis = VXBasis()
|
43 | 43 | # vxbasis.to_pandas()
|
44 | 44 | # vxbasis.vx_basis.latest
|
45 | 45 | # vxbasis.vx_basis.to_pandas()
|
46 | 46 |
|
47 | 47 |
|
48 |
| -# def test_constructors(): |
49 |
| - |
50 |
| -# class Index(Symbol): |
51 |
| -# adjusted_close = av.DailyAdjusted( |
52 |
| -# time_series='adjusted_close') |
53 |
| - |
54 |
| -# spy = Index(symbol='SPY', trading_calendar='NYSE') |
55 |
| -# vtwo = Index(symbol='VTWO', trading_calendar='NYSE') |
| 48 | +def test_constructors(): |
| 49 | + class Index(Symbol): |
| 50 | + adjusted_close = av.DailyAdjusted(time_series="adjusted_close") |
56 | 51 |
|
57 |
| -# assert( |
58 |
| -# spy.to_pandas().tail()[ |
59 |
| -# 'SPY', 'adjusted_close'].sum() != vtwo.to_pandas().tail()[ |
60 |
| -# 'VTWO', 'adjusted_close'].sum() |
61 |
| -# ) |
| 52 | + spy = Index(symbol="SPY", trading_calendar="NYSE") |
| 53 | + vtwo = Index(symbol="VTWO", trading_calendar="NYSE") |
62 | 54 |
|
| 55 | + assert ( |
| 56 | + spy.to_pandas().tail()["SPY", "adjusted_close"].sum() |
| 57 | + != vtwo.to_pandas().tail()["VTWO", "adjusted_close"].sum() |
| 58 | + ) |
63 | 59 |
|
64 |
| -# def test_finance_features(): |
65 | 60 |
|
66 |
| -# class Index(Symbol): |
67 |
| -# adjusted_close = av.DailyAdjusted( |
68 |
| -# time_series='adjusted_close') |
| 61 | +def test_finance_features(): |
| 62 | + class Index(Symbol): |
| 63 | + adjusted_close = av.DailyAdjusted(time_series="adjusted_close") |
69 | 64 |
|
70 |
| -# simple_returns = finance.SimpleReturns(column='adjusted_close') |
71 |
| -# log_returns = finance.LogReturns(column='adjusted_close') |
72 |
| -# real_vol = finance.RealisedVolatility(column='log_returns', window=20) |
73 |
| -# sma = finance.SimpleMovingAverage(column='adjusted_close', window=10) |
74 |
| -# upper = finance.UpperBollingerBand( |
75 |
| -# column='adjusted_close', window=20, width=2.0) |
76 |
| -# lower = finance.LowerBollingerBand( |
77 |
| -# column='adjusted_close', window=20, width=2.0) |
| 65 | + simple_returns = finance.SimpleReturns(column="adjusted_close") |
| 66 | + log_returns = finance.LogReturns(column="adjusted_close") |
| 67 | + real_vol = finance.RealisedVolatility(column="log_returns", window=20) |
| 68 | + sma = finance.SimpleMovingAverage(column="adjusted_close", window=10) |
| 69 | + upper = finance.UpperBollingerBand( |
| 70 | + column="adjusted_close", window=20, width=2.0 |
| 71 | + ) |
| 72 | + lower = finance.LowerBollingerBand( |
| 73 | + column="adjusted_close", window=20, width=2.0 |
| 74 | + ) |
78 | 75 |
|
79 |
| -# spy = Index(symbol='SPY', trading_calendar='NYSE') |
| 76 | + spy = Index(symbol="SPY", trading_calendar="NYSE") |
80 | 77 |
|
81 |
| -# spy.to_pandas() |
| 78 | + spy.to_pandas() |
0 commit comments