我怎样做投资组合?

2024-04-19 09:55:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在URL中从de APY导入股票,并创建一个仅包含该股票的表。我认为APY中的信息不是JSON识别

import requests
import pandas as pd
import numpy as np

#Variables
stocks = ["Delta Acciones - Clase A","SBS Acciones Argentina - Clase A","MAF Acciones Argentinas - Clase B","IAM Renta Variable - Clase B"]
initial_weight = np.array([0.20,0.30,0.30,0.20])
empresas = {}

prices = requests.get(f'https://api.cafci.org.ar/estadisticas/informacion/diaria/2/2021-07-12/{"fondo"}?serietype=vcp').json ()

prices = pd.DataFrame(prices) 

empresas[fondo] = prices.set_index('fecha')
empresas[fondo] = empresas[fondo]['vcp']

#Concatenate each of the dataframes into a single dataframe
portfolio = pd.concat(empresas, axis=1)

我得到这个错误:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)


1条回答
网友
1楼 · 发布于 2024-04-19 09:55:10

下面将获得prices数据帧。如何从这里操纵它取决于你。我强烈建议阅读Pandas documentation

import requests
import pandas as pd

# remove '{"fondo"}' from the URL entirely
url = "https://api.cafci.org.ar/estadisticas/informacion/diaria/2/2021-07-12/?serietype=vcp"
response = requests.get(url)

# the info you want is in the "data" key in the response
data = response.json()["data"]
prices = pd.DataFrame(data)

相关问题 更多 >