investpy
investpy copied to clipboard
Random availability of funds via different looping processes
Hi,
I experimented with the following looping processes and I get all the time different results between the different looping processes. I also get different results if I repeat the process again. There is some randomness in the background that I cannot understand.
Here is a minimum working example
# dates to search
from_date = '01/01/1980'
to_date = date.today() - timedelta(days=1)
to_date = to_date.strftime("%d/%m/%Y")
# by fund name
# collect funds
df_temp = []
start = time.time()
for fund_name in funds["name"]:
country = pd.Series.to_string(funds.country[funds.name == fund_name],
index=False).lstrip(' ').rstrip(' ')
try:
temp_prices = investpy.get_fund_historical_data(fund= fund_name,
country = country,
from_date = from_date,
to_date = to_date)
temp_prices["fund"] = fund_name
df_temp.append(temp_prices)
except:
pass
elapsed_time_lc =(time.time()-start)
# collect results and clean
df_funds = pd.concat(df_temp)
# by zipped
df_temp2 = []
start = time.time()
for fund_name, country_name in zip(funds.name,funds.country):
try:
temp_prices = investpy.get_fund_historical_data(fund= fund_name,
country = country_name,
from_date = from_date,
to_date = to_date)
temp_prices["fund"] = fund_name
df_temp2.append(temp_prices)
except:
pass
elapsed_time_lc_second_lopp =(time.time()-start)
# collect results and clean
df_funds2 = pd.concat(df_temp2)
Here is the dataframe funds
one would need to work the MWE above
country | name |
---|---|
ireland | Vanguard Global Bond Index Fund GBP Hedged Accumulation |
united kingdom | Fidelity Active Strategy - Fast - Global Fund Y-acc-gbp |
united kingdom | Fundsmith Equity I Acc |
united kingdom | Vanguard Ftse Dev World Ex Uk Equity Index Acc |
united kingdom | Dodge & Cox Worldwide Us Stock Fund A Gbp |
united kingdom | Baillie Gifford American Fund B Accumulation |
united kingdom | M&g North American Value Fund Sterling I Acc |
united kingdom | Baillie Gifford Global Alpha Growth Fund B Accumulation |
united kingdom | Baillie Gifford Positive Change Fund B Accumulation |
united kingdom | Fidelity Uk Opportunities Fund W Accumulation |
united kingdom | Artemis Uk Select Fund I Acc |
united kingdom | Fidelity Special Situations Fund W-accumulation |
united kingdom | Baillie Gifford Managed Fund B Acc |
united kingdom | Axa Framlington Managed Income Fund Z Gross Gbp Acc |
united kingdom | Bny Mellon Investment Funds - Newton Multi-asset Diversified Return Fund Institutional W Acc |
united kingdom | Baillie Gifford Global Discovery Fund B Accumulation |
united kingdom | Baillie Gifford Global Income Growth Fund B Accumulation |
united kingdom | Baillie Gifford Pacific B Acc |
united kingdom | Stewart Investors Asia Pacific Leaders Fund Class B (accumulation) Gbp |
united kingdom | Fidelity Funds - Global Financial Services Fund W-acc-gbp |
united kingdom | Blackrock Natural Resources Growth & Income Fund D Acc |
united kingdom | Pictet - Global Environmental Opportunities I Dy Gbp |
united kingdom | Fidelity Funds - Global Technology Fund W-acc-gbp |
united kingdom | Vanguard Ftse Developed Europe Ex Uk Equity Index Acc |
united kingdom | Baillie Gifford European Fund B Accumulation |