Skip to content
The Chat Archive
gpt-4-0613· OpenAI Arena Human Preference 55K

Write me python code that gets the price of msft using yfinance

  1. User

    Write me python code that gets the price of msft using yfinance

  2. Assistant

    Sure, first you need to install yfinance module. You can install it via pip:

    pip install yfinance
    

    Then here is the Python code that fetches the current price of MSFT (Microsoft Corporation) using yfinance:

    import yfinance as yf
    
    # Get the data of the stock MSFT
    msft = yf.Ticker("MSFT")
    
    # get stock info
    msft_info = msft.info
    
    # get 'currentPrice' from the dictionary
    price = msft_info['currentPrice']
    
    print("The current price of MSFT is:", price)
    

    Please note that this code will return the price of MSFT at the time the code is executed. If you need the price at a different time, you will need to adjust the code accordingly.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.