How to use historical data from YahooFinance, calculate mean vector and covariance matrices, so I can optimize them with QAOA?
Quantum Computing SEArchived Apr 14, 2026✓ Full text saved
I want to use historical data for 5 stocks from YahooFinance and then calculate mean vector and covariance matrices, so I can optimize them with QAOA. Anyone know what is wrong with this code: num_assets = 5 data = YahooDataProvider(["IBM", "AMZN", "VOW3.DE", "GOOGL", "MA"], start=datetime.datetime(2015,1,1), end=datetime.datetime(2018,12,31)) data.run() mu = data.get_period_return_mean_vector() print(mu) sigma = data.get_period_return_covariance_matrix() # plot sigma plt.imshow(sigma, interpola
Full text archived locally
✦ AI Summary· Claude Sonnet
How to use historical data from YahooFinance, calculate mean vector and covariance matrices, so I can optimize them with QAOA?
Ask Question
Asked 4 years, 8 months ago
Modified today
Viewed 343 times
-1
I want to use historical data for 5 stocks from YahooFinance and then calculate mean vector and covariance matrices, so I can optimize them with QAOA. Anyone know what is wrong with this code:
num_assets = 5
data = YahooDataProvider(["IBM", "AMZN", "VOW3.DE", "GOOGL", "MA"],
start=datetime.datetime(2015,1,1),
end=datetime.datetime(2018,12,31))
data.run()
mu = data.get_period_return_mean_vector()
print(mu)
sigma = data.get_period_return_covariance_matrix()
# plot sigma
plt.imshow(sigma, interpolation='nearest')
plt.show()
The current output is [nan nan nan nan nan]
qiskitprogrammingqaoa
Share
Improve this question
Follow
edited Mar 20, 2025 at 10:39
Frederik vom Ende
4,3413
3 gold badges
15
15 silver badges
51
51 bronze badges
asked Aug 9, 2021 at 12:06
Milica G.
332
2 bronze badges
Which language/SDK are you using? –
Mauricio
Commented
Aug 9, 2021 at 12:44
@Mauricio Python/Qiskit –
Milica G.
Commented
Aug 9, 2021 at 12:59
Add a comment
1 Answer
Sorted by:
Highest score (default)
Date modified (newest first)
Date created (oldest first)
0
I overcame the problem with this code:
num_assets = 5
yf.pdr_override()
df = pdr.get_data_yahoo("IBM AMZN VOW3.DE GOOGL MA", start="2015-01-01", end="2018-12-31")#, group_by='ticker')
# print(df)
mu = df['Adj Close'].mean()
print(mu)
sigma = df['Adj Close'].cov()
print(sigma)
This was the output:
Share
Improve this answer
Follow
edited Mar 20, 2025 at 10:37
Frederik vom Ende
4,3413
3 gold badges
15
15 silver badges
51
51 bronze badges
answered Aug 10, 2021 at 8:49
Milica G.
332
2 bronze badges
Add a comment
Your Answer
Sign up or log in
Sign up using Google
Sign up using Email and Password
Post as a guest
Name
Email
Required, but never shown
Post Your Answer
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Ask question
Explore related questions
qiskitprogrammingqaoa
See similar questions with these tags.
The Overflow Blog
Who needs VCs when you have friends like these?
The messy truth of your AI strategies
Related
7
Cascade/Feedforward quantum circuits
2
How can I use surface code measurement data produced with Qiskit to run matching algorithms (e.g. PyMatching)?
Hot Network Questions
Is diamond the best shape for stealth?
Generating integers using EML
What should I verify on my W4 if I'm claiming 0 but still underwitholding?
Archaic usage of "whomst"
Should this cement crack along the inside wall of my garage be filled?
Locating content of retired Microsoft Answers questions
How to fix different spacing within `expex` in `beamerposter` depending on the compiler?
Symmetry is Morita Invariant
Broken code - numerical order failure...
Output a Sturmian sequence
Term to differentiate language as performed vs recorded?
Finding a PCB connector for this OLED display FPC interface
Analyzing a "Foreign endorsement makes you inelectable" law
Prove that at least one of the cars can drive around the track by taking gas from other cars on its way.
What role does vibrato have in the orchestra?
Is there a way to get alerts when my daughter receives calls from numbers not saved in her contacts?
Can there be multiple simple extensions of the field
Can UK/EU dual nationals enter the UK legally with an EU passport via Ireland?
Morleyization versus double negation
Calculating the expected value of a transformation
What is wrong with this "counterexample" to the Extreme Value Theorem?
Would a future closed-loop steady-state economy (with no net resource depletion) mine outer space, and if so, for what?
Logic Puzzle [#2] Where No Variable Can Be Determined Without All Six Clues
How to export Gemini Chat history to Word or PDF?
Question feed
By continuing to use this website, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. By exiting this window, default cookies will be accepted. To reject cookies, select an option from below.
Customize settings
Cookie Consent Preference Center
When you visit any of our websites, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences, or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and manage your preferences. Please note, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
Cookie Policy
Accept all cookies
Manage Consent Preferences
Strictly Necessary Cookies
Always Active
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.
Targeting Cookies
Targeting Cookies
These cookies are used to make advertising messages more relevant to you and may be set through our site by us or by our advertising partners. They may be used to build a profile of your interests and show you relevant advertising on our site or on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device.
Performance Cookies
Performance Cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
Functional Cookies
Functional Cookies
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
Cookie List
Clear
checkbox label label
Apply Cancel
Consent Leg.Interest
checkbox label label
checkbox label label
checkbox label label
Necessary cookies only Confirm My Choices