Created
October 20, 2020 16:27
-
-
Save HoverHell/847bf40106a69afe7193d1d5ecb68436 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import pandas as pd | |
import pandas_datareader | |
url = 'https://fintarget.ru/api/strategies/valyutnaya-strategiya' | |
d1 = requests.get(url).json() | |
def proc(val): | |
res = pd.DataFrame(val) | |
res['ts'] = pd.to_datetime(res['t'], unit='ms') | |
res = res.set_index('ts') | |
res = res[['v', 'vc']] | |
return res | |
ph = proc(d1['response']['history']) | |
iph = proc(d1['response']['indexHistory']) | |
ph = ph.join(iph[['v']], how='outer', rsuffix='_idx', sort=True) | |
rub = pandas_datareader.data.DataReader('USDRUB=X', 'yahoo', ph.index.min(), ph.index.max())['Close'] | |
rub = rub[rub > 30] | |
voo = pandas_datareader.data.DataReader('VOO', 'yahoo', ph.index.min(), ph.index.max())['Close'] | |
rub_reidx = pd.DataFrame(dict(rub=rub)).reindex(index=voo.index, method='ffill')['rub'] | |
voo_rub = voo * rub_reidx | |
voo_rub_rel = (voo_rub / voo_rub[0] - 1) * 100 | |
ph = ph.join(pd.DataFrame(dict(voo_rub=voo_rub_rel)), how='outer') | |
ph = ph.fillna(method='ffill') | |
ph.plot(figsize=(16, 8)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment