【Claude Investor】使い方を徹底解説!AIが株式銘柄を自動でピックアップ
みなさんは株で勝ちたいと思ったことはありますか。
2024年3月には日経平均が最高値を突破したり、アメリカのS&P500やNASDAQなども高値圏を維持しています。
そんな株価が上昇している今日ですが、つい私欲がでてしまい買うべき時に買えなかったり、売るべき時に売れなかったりすることがありますよね。
人間であれば誰もが持つ悩みです。
しかし、そんな悩みを消し去ってくれるようなAI(人工知能)のツールが誕生しました。
その名も「Claude Investor」です。(読み方は「クロード・インベスター」です。)
Claude Investorとは、GPT-4を超えた性能を持つAI「Claude」を活用した投資サポートツールです。
ユーザーが特定の業界を1つ入力すると、その業界から有名な銘柄を5つ選んでくれます。そして、最新のヤフーファイナンスの情報をもとに、各々の銘柄のターゲットプライスや投資リスクを教えてくれます。
Claude Investorは、数々のAIスタートアップを立ち上げたCEO マット・シュマー氏によって開発されました。
下の画像は、シュマー氏がツールを公開した時のXの投稿です。公開からわずか3日で50万インプレッションと2790いいねを集めており、X民からの期待が大きいことがわかります。
(引用元:Matt Shumer氏Xアカウント)
それでは、Claude Investorの使い方と実際のどんなアメリカの株式銘柄をおすすめしてくれるのか見ていきましょう!
<Claude Investorの使い方の手順>
Claude Investorはプログラミングをしたことがない人でも使うことができるツールです。
今回は誰でも使い方・やり方がわかるように解説していきます!
大まかな手順としては以下の通りです。
Claude Investor 使い方手順
① Claude APIキーを公式サイトで取得する。
② Google コラボを開く。
③ Google コラボで「必要な文章」と「APIキー」をコピー&ペーストする。
④ Claude Investorが株式銘柄を選別する。
それでは、順番に見ていきましょう!
① Claude APIキーを公式サイトで取得する。
まず、Claude Investorを使うのに絶対に必要になるのがClaudeの「APIキー」です。
APIキーをまだ取得されていない方は下のURLからAPI取得方法をわかりやすく解説しているのでご覧ください。
→3分でできる!「Claude APIキー」取得のやり方をわかりやすく解説
APIキーを取得したあとは、とても簡単です!
② Googleコラボを開く。
下のURLからGoogleコラボにアクセスします。
Googleコラボとは誰でもオンラインでPythonが使えるサイトです。もしGoogleでログインされていない方はログインしてください。無料で使えます!
すると下のような画面が表れるので、左下の青いボタン「ノートブックを新規作成」をクリックします。
(画像:Google Colabの使用画面より引用)
ノートブックの新規作成後は、下のような画面が出ます。(右側にたくさん文字があって、威圧的ですが関係ないので無視して構いません!)

(画像:Google Colabの使用画面より引用)
③ Google コラボで「必要な文章」と「APIキー」をコピー&ペーストする。
あとは、「コーディングを開始するか、AIで生成します。」というところに下の文章をコピー&ペーストするだけです。
\!pip install yfinance requests beautifulsoup4
文章がコピペできたら、左側にある▶ボタンをクリックします。すると必要なパッケージをダウンロードしてくれます。
下のような画面になってたらオッケーです🙆♀

(画像:Google Colabの使用画面より引用)
次に左上に「+コード」というボタンがあるのでそちらを押します。すると、コピペができる欄がまた表れます。
そしたら、先ほど取得したご自身のAPIキーを↓の”カッコ”の中に代入して、▶ボタンを押してください。
ANTHROPIC\_API\_KEY = "あなたのAPIキー"
この時点ではまだ何も起きません。「+コード」ボタンを押したら、最後に長い文章をコピペしましょう!本当に長いのでびっくりするかもしれませんが、このステップで最後です。
import yfinance as yf
from datetime import datetime, timedelta
import requests
from bs4 import BeautifulSoup
import ast
import json
def get_article_text(url):
try:
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
article_text = ' '.join([p.get_text() for p in soup.find_all('p')])
return article_text
except:
return "Error retrieving article text."
def get_stock_data(ticker, years):
end_date = datetime.now().date()
start_date = end_date - timedelta(days=years*365)
stock = yf.Ticker(ticker)
# Retrieve historical price data
hist_data = stock.history(start=start_date, end=end_date)
# Retrieve balance sheet
balance_sheet = stock.balance_sheet
# Retrieve financial statements
financials = stock.financials
# Retrieve news articles
news = stock.news
return hist_data, balance_sheet, financials, news
def get_claude_comps_analysis(ticker, hist_data, balance_sheet, financials, news):
system_prompt = f"You are a financial analyst assistant. Analyze the given data for {ticker} and suggest a few comparable companies to consider. Do so in a Python-parseable list."
news = ""
for article in news:
article_text = get_article_text(article['link'])
news = news + f"\n\n---\n\nTitle: {article['title']}\nText: {article_text}"
messages = [
{"role": "user", "content": f"Historical price data:\n{hist_data.tail().to_string()}\n\nBalance Sheet:\n{balance_sheet.to_string()}\n\nFinancial Statements:\n{financials.to_string()}\n\nNews articles:\n{news.strip()}\n\n----\n\nNow, suggest a few comparable companies to consider, in a Python-parseable list. Return nothing but the list. Make sure the companies are in the form of their tickers."},
]
headers = {
"x-api-key": ANTHROPIC_API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json"
}
data = {
"model": 'claude-3-haiku-20240307',
"max_tokens": 2000,
"temperature": 0.5,
"system": system_prompt,
"messages": messages,
}
response = requests.post("[https://api.anthropic.com/v1/messages](https://api.anthropic.com/v1/messages)", headers=headers, json=data)
response_text = response.json()['content'][0]['text']
return ast.literal_eval(response_text)
def compare_companies(main_ticker, main_data, comp_ticker, comp_data):
system_prompt = f"You are a financial analyst assistant. Compare the data of {main_ticker} against {comp_ticker} and provide a detailed comparison, like a world-class analyst would. Be measured and discerning. Truly think about the positives and negatives of each company. Be sure of your analysis. You are a skeptical investor."
messages = [
{"role": "user", "content": f"Data for {main_ticker}:\n\nHistorical price data:\n{main_data['hist_data'].tail().to_string()}\n\nBalance Sheet:\n{main_data['balance_sheet'].to_string()}\n\nFinancial Statements:\n{main_data['financials'].to_string()}\n\n----\n\nData for {comp_ticker}:\n\nHistorical price data:\n{comp_data['hist_data'].tail().to_string()}\n\nBalance Sheet:\n{comp_data['balance_sheet'].to_string()}\n\nFinancial Statements:\n{comp_data['financials'].to_string()}\n\n----\n\nNow, provide a detailed comparison of {main_ticker} against {comp_ticker}. Explain your thinking very clearly."},
]
headers = {
"x-api-key": ANTHROPIC_API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json"
}
data = {
"model": 'claude-3-haiku-20240307',
"max_tokens": 3000,
"temperature": 0.5,
"system": system_prompt,
"messages": messages,
}
response = requests.post("[https://api.anthropic.com/v1/messages](https://api.anthropic.com/v1/messages)", headers=headers, json=data)
response_text = response.json()['content'][0]['text']
# return json.loads(response_text)
return response_text
def get_sentiment_analysis(ticker, news):
system_prompt = f"You are a sentiment analysis assistant. Analyze the sentiment of the given news articles for {ticker} and provide a summary of the overall sentiment and any notable changes over time. Be measured and discerning. You are a skeptical investor."
news_text = ""
for article in news:
article_text = get_article_text(article['link'])
timestamp = datetime.fromtimestamp(article['providerPublishTime']).strftime("%Y-%m-%d")
news_text += f"\n\n---\n\nDate: {timestamp}\nTitle: {article['title']}\nText: {article_text}"
messages = [
{"role": "user", "content": f"News articles for {ticker}:\n{news_text}\n\n----\n\nProvide a summary of the overall sentiment and any notable changes over time."},
]
headers = {
"x-api-key": ANTHROPIC_API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json"
}
data = {
"model": 'claude-3-haiku-20240307',
"max_tokens": 2000,
"temperature": 0.5,
"system": system_prompt,
"messages": messages,
}
response = requests.post("[https://api.anthropic.com/v1/messages](https://api.anthropic.com/v1/messages)", headers=headers, json=data)
response_text = response.json()['content'][0]['text']
return response_text
def get_analyst_ratings(ticker):
stock = yf.Ticker(ticker)
recommendations = stock.recommendations
if recommendations is None or recommendations.empty:
return "No analyst ratings available."
latest_rating = recommendations.iloc[-1]
firm = latest_rating.get('Firm', 'N/A')
to_grade = latest_rating.get('To Grade', 'N/A')
action = latest_rating.get('Action', 'N/A')
rating_summary = f"Latest analyst rating for {ticker}:\nFirm: {firm}\nTo Grade: {to_grade}\nAction: {action}"
return rating_summary
def get_industry_analysis(ticker):
### update to use search to find recent data!!
stock = yf.Ticker(ticker)
industry = stock.info['industry']
sector = stock.info['sector']
system_prompt = f"You are an industry analysis assistant. Provide an analysis of the {industry} industry and {sector} sector, including trends, growth prospects, regulatory changes, and competitive landscape. Be measured and discerning. Truly think about the positives and negatives of the stock. Be sure of your analysis. You are a skeptical investor."
messages = [
{"role": "user", "content": f"Provide an analysis of the {industry} industry and {sector} sector."},
]
headers = {
"x-api-key": ANTHROPIC_API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json"
}
data = {
"model": 'claude-3-haiku-20240307',
"max_tokens": 2000,
"temperature": 0.5,
"system": system_prompt,
"messages": messages,
}
response = requests.post("[https://api.anthropic.com/v1/messages](https://api.anthropic.com/v1/messages)", headers=headers, json=data)
response_text = response.json()['content'][0]['text']
return response_text
def get_final_analysis(ticker, comparisons, sentiment_analysis, analyst_ratings, industry_analysis):
system_prompt = f"You are a financial analyst providing a final investment recommendation for {ticker} based on the given data and analyses. Be measured and discerning. Truly think about the positives and negatives of the stock. Be sure of your analysis. You are a skeptical investor."
messages = [
{"role": "user", "content": f"Ticker: {ticker}\n\nComparative Analysis:\n{json.dumps(comparisons, indent=2)}\n\nSentiment Analysis:\n{sentiment_analysis}\n\nAnalyst Ratings:\n{analyst_ratings}\n\nIndustry Analysis:\n{industry_analysis}\n\nBased on the provided data and analyses, please provide a comprehensive investment analysis and recommendation for {ticker}. Consider the company's financial strength, growth prospects, competitive position, and potential risks. Provide a clear and concise recommendation on whether to buy, hold, or sell the stock, along with supporting rationale."},
]
headers = {
"x-api-key": ANTHROPIC_API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json"
}
data = {
"model": 'claude-3-opus-20240229',
"max_tokens": 3000,
"temperature": 0.5,
"system": system_prompt,
"messages": messages,
}
response = requests.post("[https://api.anthropic.com/v1/messages](https://api.anthropic.com/v1/messages)", headers=headers, json=data)
response_text = response.json()['content'][0]['text']
return response_text
def generate_ticker_ideas(industry):
system_prompt = f"You are a financial analyst assistant. Generate a list of 5 ticker symbols for major companies in the {industry} industry, as a Python-parseable list."
messages = [
{"role": "user", "content": f"Please provide a list of 5 ticker symbols for major companies in the {industry} industry as a Python-parseable list. Only respond with the list, no other text."},
]
headers = {
"x-api-key": ANTHROPIC_API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json"
}
data = {
"model": 'claude-3-haiku-20240307',
"max_tokens": 200,
"temperature": 0.5,
"system": system_prompt,
"messages": messages,
}
response = requests.post("[https://api.anthropic.com/v1/messages](https://api.anthropic.com/v1/messages)", headers=headers, json=data)
response_text = response.json()['content'][0]['text']
ticker_list = ast.literal_eval(response_text)
return [ticker.strip() for ticker in ticker_list]
def get_current_price(ticker):
stock = yf.Ticker(ticker)
data = stock.history(period='1d', interval='1m')
return data['Close'][-1]
def rank_companies(industry, analyses, prices):
system_prompt = f"You are a financial analyst providing a ranking of companies in the {industry} industry based on their investment potential. Be discerning and sharp. Truly think about whether a stock is valuable or not. You are a skeptical investor."
analysis_text = "\n\n".join(
f"Ticker: {ticker}\nCurrent Price: {prices.get(ticker, 'N/A')}\nAnalysis:\n{analysis}"
for ticker, analysis in analyses.items()
)
messages = [
{"role": "user", "content": f"Industry: {industry}\n\nCompany Analyses:\n{analysis_text}\n\nBased on the provided analyses, please rank the companies from most attractive to least attractive for investment. Provide a brief rationale for your ranking. In each rationale, include the current price (if available) and a price target."},
]
headers = {
"x-api-key": ANTHROPIC_API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json"
}
data = {
"model": 'claude-3-opus-20240229',
"max_tokens": 3000,
"temperature": 0.5,
"system": system_prompt,
"messages": messages,
}
response = requests.post("[https://api.anthropic.com/v1/messages](https://api.anthropic.com/v1/messages)", headers=headers, json=data)
response_text = response.json()['content'][0]['text']
return response_text
# User input
industry = input("Enter the industry to analyze: ")
years = 1 # int(input("Enter the number of years for analysis: "))
# Generate ticker ideas for the industry
tickers = generate_ticker_ideas(industry)
print(f"\nTicker Ideas for {industry} Industry:")
print(", ".join(tickers))
# Perform analysis for each company
analyses = {}
prices = {}
for ticker in tickers:
try:
print(f"\nAnalyzing {ticker}...")
hist_data, balance_sheet, financials, news = get_stock_data(ticker, years)
main_data = {
'hist_data': hist_data,
'balance_sheet': balance_sheet,
'financials': financials,
'news': news
}
sentiment_analysis = get_sentiment_analysis(ticker, news)
analyst_ratings = get_analyst_ratings(ticker)
industry_analysis = get_industry_analysis(ticker)
final_analysis = get_final_analysis(ticker, {}, sentiment_analysis, analyst_ratings, industry_analysis)
analyses[ticker] = final_analysis
prices[ticker] = get_current_price(ticker)
except:
pass
# Rank the companies based on their analyses
ranking = rank_companies(industry, analyses, prices)
print(f"\nRanking of Companies in the {industry} Industry:")
print(ranking)↑めっちゃ長いです笑
④ Claude Investorが株式銘柄を選別する。
上記の長い文章をコピペすると、「Enter the industry to analyze(分析したい業界を入力してください)」という文字が表れます。
ご自身で好きな業界を選びましょう!私の場合は「Tech(テック)」業界を選びました。
「Tech」の他にも、「Energy(エネルギー業界)」、「Bank(銀行業界)」、「Entertainment(エンタメ業界)」、「Semiconductor(半導体業界)」などいろいろあるので試してみましょう。
するとその業界を代表する5つの米国銘柄をClaude AIが選出します。
具体的な銘柄はおすすめできないのですが、雰囲気だけお伝えするために偽物のティッカーでお伝えします。
AIのおすすめ順に並べた表を作るとこのようになりました。※銘柄は実在しません!
| ティッカー | 現在の株価 | 目標株価 | 説明 |
|---|---|---|---|
| 1. OCR(オークロ) | $423.23 | $450 | 強力な財務実績、クラウド コンピューティングのリーダーシップ、戦略的パートナーシップにより、オークロは最も魅力的な投資オプションとなっています。 |
| 2. MATG(マットジー) | $178.13 | $200 | マットジーは電子商取引における圧倒的な地位、クラウド コンピューティングや広告などの高成長分野への多角化、業界の好調な傾向により、魅力的な投資となっています。 |
| 3. GODL(グードル) | $149.23 | $160 | グードルは長期的な投資として魅力的です。 しかし、特に EU からの規制監視が強化されており、短期的には明確な前向きの触媒が欠如しているため、慎重なアプローチが必要です。 |
| 4. Pear(ペアー) | $169.83 | $175 | ペアーの強力なブランドは強みです。 しかし、EUの規制リスク、明確な前向きの触媒の欠如、サプライチェーンの問題や競争に関連した業界の逆風により、魅力が落ちてきています。 |
| 5. PESL(ペースル) | $173.80 | $150 | ペースルの EV 市場における強力なブランド認知は、注目に値する利点です。 しかし、競争の激化、需要への懸念により、検討対象企業の中で最も魅力の低い投資オプションとなっている。 |
シュマー氏はClaude Investorを使って投資をすることについておすすめしていないそうなので、投資をする際は自己責任でお願いします!
*掲載している情報は、投資の勧誘や売買推奨を目的としたものではありません。投資のご判断はご自身の責任でお願いします。
参考文献 ・Matt Shumer X Account ・Google Colab ・mshumer / gpt-investor