简体   繁体   English

我怎样才能做一个投资组合?

[英]How can I do a portfolio?

I want to import the stocks from de APY in the URL and creat a table only with this stocks.我想从 URL 中的 de APY 导入股票,并仅使用这些股票创建一个表。 I think that the information in the APY not is a JSON recognite我认为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)

I get this error:我收到此错误:

JSONDecodeError: Expecting value: line 1 column 1 (char 0) JSONDecodeError:期望值:第 1 行第 1 列(字符 0)

The following will get you the prices dataframe.以下将为您提供prices数据框。 How to manipulate it from here is up to you.如何从这里操纵它取决于你。 I strongly suggest reading the Pandas documentation .我强烈建议阅读Pandas 文档

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM